0
0
Node.jsframework~10 mins

Logging with structured formats in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the popular logging library 'winston'.

Node.js
const winston = require('[1]');
Drag options to blanks, or click blank then click option'
Alodash
Bwinston
Cexpress
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated libraries like 'express' or 'lodash' instead of 'winston'.
2fill in blank
medium

Complete the code to create a new logger with JSON format output.

Node.js
const logger = winston.createLogger({ format: winston.format.[1]() });
Drag options to blanks, or click blank then click option'
Ajson
Bsimple
Ccolorize
Dprintf
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'simple' or 'colorize' which are for plain text logs, not structured JSON.
3fill in blank
hard

Fix the error in the code to log an info message with the logger.

Node.js
logger.[1]('Server started successfully');
Drag options to blanks, or click blank then click option'
Ainfo
Bwrite
Clog
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'write' or 'print' which are not winston logger methods.
4fill in blank
hard

Fill both blanks to add a timestamp and format the log as JSON.

Node.js
const logger = winston.createLogger({ format: winston.format.combine(winston.format.[1](), winston.format.[2]()) });
Drag options to blanks, or click blank then click option'
Atimestamp
Bjson
Ccolorize
Dsimple
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'colorize' or 'simple' which do not produce structured JSON logs.
5fill in blank
hard

Fill all three blanks to create a logger that writes JSON logs with timestamps to a file named 'app.log'.

Node.js
const logger = winston.createLogger({ format: winston.format.combine(winston.format.[1](), winston.format.[2]()), transports: [new winston.transports.[3]({ filename: 'app.log' })] });
Drag options to blanks, or click blank then click option'
Atimestamp
Bjson
CFile
DConsole
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Console' transport which logs to the console, not a file.