0
0
Expressframework~20 mins

Winston for application logging in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Winston Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this Winston logger configuration?
Given the following Winston logger setup in an Express app, what will be the output when logger.info('Server started') is called?
Express
const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.simple(),
  transports: [
    new winston.transports.Console()
  ]
});

logger.info('Server started');
AError: No output
BServer started
C[INFO] Server started
Dinfo: Server started
Attempts:
2 left
💡 Hint
Look at the format used in the logger configuration.
🧠 Conceptual
intermediate
1:00remaining
Which transport writes logs to a file in Winston?
In Winston, which transport class is used to save logs into a file?
Awinston.transports.File
Bwinston.transports.Console
Cwinston.transports.Http
Dwinston.transports.Stream
Attempts:
2 left
💡 Hint
Think about the transport that deals with files.
Troubleshoot
advanced
1:30remaining
Why does this Winston logger not output any logs?
Consider this Winston logger setup. Why does calling logger.debug('Debug message') produce no output?
Express
const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  transports: [new winston.transports.Console()]
});

logger.debug('Debug message');
ABecause 'debug' is not a valid log level in Winston
BBecause the Console transport is missing a format option
CBecause the logger level is set to 'info', which ignores 'debug' level logs
DBecause the logger is missing a file transport
Attempts:
2 left
💡 Hint
Check the logger's level setting and how it filters messages.
🔀 Workflow
advanced
2:00remaining
Order the steps to add a timestamp to Winston logs
Put these steps in the correct order to configure Winston to include timestamps in log messages.
A2,1,3,4
B1,2,3,4
C1,3,2,4
D1,2,4,3
Attempts:
2 left
💡 Hint
Think about how you build the format step by step.
Best Practice
expert
2:00remaining
What is the best practice for handling uncaught exceptions with Winston?
Which option correctly shows how to configure Winston to handle uncaught exceptions and log them to a file?
AAdd an exceptions handler with a File transport in the logger configuration.
BUse process.on('uncaughtException') to manually log errors without Winston.
CSet the logger level to 'error' and rely on default behavior.
DWrap all code in try-catch blocks and log errors with console.error.
Attempts:
2 left
💡 Hint
Winston has a built-in way to catch uncaught exceptions.