0
0
Expressframework~10 mins

Winston for application logging in Express - 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 Winston in an Express app.

Express
const winston = require('[1]');
Drag options to blanks, or click blank then click option'
Awinston
Bexpress
Cmorgan
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'winston' in require.
Confusing with 'morgan' which is another logger.
2fill in blank
medium

Complete the code to create a Winston logger with console transport.

Express
const logger = winston.createLogger({ transports: [new winston.transports.[1]()] });
Drag options to blanks, or click blank then click option'
AFile
BHttp
CStream
DConsole
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'File' transport without specifying filename.
Using 'Http' transport which sends logs over HTTP.
3fill in blank
hard

Fix the error in the code to log an info message using Winston.

Express
logger.[1]('Server started successfully');
Drag options to blanks, or click blank then click option'
Ainfo
Bprint
Cwrite
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which is not a Winston method.
Using 'write' which is not a method on logger.
4fill in blank
hard

Fill both blanks to configure Winston to log errors to a file named 'error.log'.

Express
const logger = winston.createLogger({ transports: [new winston.transports.[1]({ filename: '[2]' })] });
Drag options to blanks, or click blank then click option'
AFile
BConsole
Cerror.log
Dcombined.log
Attempts:
3 left
💡 Hint
Common Mistakes
Using Console transport with filename option (ignored).
Using wrong filename like 'combined.log' for error logs.
5fill in blank
hard

Fill all three blanks to create a logger that logs info level to console and errors to 'error.log' file.

Express
const logger = winston.createLogger({ level: '[1]', transports: [new winston.transports.[2](), new winston.transports.[3]({ filename: 'error.log', level: 'error' })] });
Drag options to blanks, or click blank then click option'
Ainfo
BConsole
CFile
Ddebug
Attempts:
3 left
💡 Hint
Common Mistakes
Setting level to 'debug' which logs too much.
Using Console transport for file logging.