0
0
Expressframework~20 mins

Log levels and when to use them in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding log levels in Express apps
Which log level is best suited for recording detailed information useful only during development and debugging in an Express app?
Aerror
Bwarn
Cdebug
Dinfo
Attempts:
2 left
💡 Hint
Think about which level gives the most detailed messages for developers.
component_behavior
intermediate
2:00remaining
Log output behavior with different levels
Given an Express app configured to log only 'warn' and above, which log messages will appear in the console?
Express
logger.error('Error happened');
logger.warn('Warning issued');
logger.info('Informational message');
logger.debug('Debug details');
AOnly 'Error happened' appears
BAll four messages appear
COnly 'Informational message' and 'Debug details' appear
DOnly 'Error happened' and 'Warning issued' messages appear
Attempts:
2 left
💡 Hint
Remember that logging levels filter out messages below the set level.
📝 Syntax
advanced
2:00remaining
Correct usage of log levels in Express middleware
Which code snippet correctly logs an error message inside an Express error-handling middleware?
Express
app.use((err, req, res, next) => {
  // log error here
  next(err);
});
Alogger.error(`Error: ${err.message}`);
Blogger.warn('Error: ' + err.message);
Clogger.info(`Error: ${err.message}`);
Dlogger.debug('Error: ' + err.message);
Attempts:
2 left
💡 Hint
Errors should be logged with the highest severity level.
🔧 Debug
advanced
2:00remaining
Identifying incorrect log level usage
What is wrong with this Express logging code snippet? logger.info('User login failed due to invalid password');
AIt should use 'warn' level because login failure is a warning, not an error
BIt should use 'debug' level because it's only useful during development
CIt should use 'error' level because login failure is a serious issue
DThere is no problem; 'info' is the correct level
Attempts:
2 left
💡 Hint
Consider how serious a login failure is for the app's security.
state_output
expert
3:00remaining
Log output filtering with dynamic log level changes
An Express app starts with log level 'info'. During runtime, the log level changes to 'error'. Which log messages will be output before and after the change? Code snippet: logger.info('Server started'); logger.error('Database connection failed'); // log level changes to 'error' logger.warn('Cache miss'); logger.error('Unhandled exception');
ABefore change: 'Server started', 'Database connection failed'; After change: 'Cache miss', 'Unhandled exception'
BBefore change: 'Server started', 'Database connection failed'; After change: 'Unhandled exception' only
CBefore change: 'Server started'; After change: 'Cache miss', 'Unhandled exception'
DBefore change: 'Database connection failed'; After change: 'Cache miss' only
Attempts:
2 left
💡 Hint
Remember which levels are shown at 'info' and 'error' settings.