Challenge - 5 Problems
Express Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2: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?
Attempts:
2 left
💡 Hint
Think about which level gives the most detailed messages for developers.
✗ Incorrect
The debug level is used for detailed diagnostic information useful during development. Other levels like error or warn are for more serious issues or warnings.
❓ component_behavior
intermediate2: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');
Attempts:
2 left
💡 Hint
Remember that logging levels filter out messages below the set level.
✗ Incorrect
When the log level is set to warn, only warn and error messages are shown. info and debug are ignored.
📝 Syntax
advanced2: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);
});Attempts:
2 left
💡 Hint
Errors should be logged with the highest severity level.
✗ Incorrect
Errors should be logged with error level to highlight serious problems. Using warn, info, or debug is less appropriate for errors.
🔧 Debug
advanced2:00remaining
Identifying incorrect log level usage
What is wrong with this Express logging code snippet?
logger.info('User login failed due to invalid password');
Attempts:
2 left
💡 Hint
Consider how serious a login failure is for the app's security.
✗ Incorrect
A login failure due to invalid password is a warning about user input, not a system error. So warn is more appropriate than info or error.
❓ state_output
expert3: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');
Attempts:
2 left
💡 Hint
Remember which levels are shown at 'info' and 'error' settings.
✗ Incorrect
At 'info' level, info and error messages appear. After changing to 'error', only error messages appear, so warn is filtered out.