Bird
Raised Fist0
Expressframework~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. Which log level in Express is best used to record normal operation messages that confirm things are working as expected?
easy
A. info
B. error
C. debug
D. warn

Solution

  1. Step 1: Understand the purpose of log levels

    Log levels help separate messages by importance. 'info' is for normal operations.
  2. Step 2: Match log level to message type

    'info' is used to confirm the app is running fine, unlike 'error' or 'warn' which indicate problems.
  3. Final Answer:

    info -> Option A
  4. Quick Check:

    Normal operation messages = info [OK]
Hint: Info logs show normal app activity clearly [OK]
Common Mistakes:
  • Confusing 'info' with 'error'
  • Using 'debug' for normal messages
  • Thinking 'warn' is for normal info
2. Which of the following is the correct way to log a warning message using Express's console object?
easy
A. console.info('This is a warning')
B. console.error('This is a warning')
C. console.debug('This is a warning')
D. console.warn('This is a warning')

Solution

  1. Step 1: Identify the correct console method for warnings

    Express uses standard console methods; 'warn' is for warnings.
  2. Step 2: Match method to message type

    console.warn() logs warning messages, unlike console.error() which logs errors.
  3. Final Answer:

    console.warn('This is a warning') -> Option D
  4. Quick Check:

    Warning messages use console.warn() [OK]
Hint: Use console.warn() for warnings, not error or info [OK]
Common Mistakes:
  • Using console.error for warnings
  • Using console.info for warnings
  • Using console.debug for warnings
3. What will be the output of this Express logging code snippet?
console.info('Server started');
console.warn('Memory usage high');
console.error('Failed to connect to DB');
console.debug('User ID: 1234');
medium
A. Only 'Failed to connect to DB' will appear
B. Only 'Server started' and 'Memory usage high' will appear
C. All four messages will appear in the console
D. Only 'User ID: 1234' will appear

Solution

  1. Step 1: Understand default console behavior in Express

    By default, all console methods (info, warn, error, debug) print messages to the console.
  2. Step 2: Analyze the code snippet output

    All four console calls will output their messages unless filtered by a logging library, which is not shown here.
  3. Final Answer:

    All four messages will appear in the console -> Option C
  4. Quick Check:

    Default console logs all levels [OK]
Hint: Default console logs all messages unless filtered [OK]
Common Mistakes:
  • Thinking debug logs are hidden by default
  • Assuming error logs suppress others
  • Confusing info and warn visibility
4. You want to log an error in Express but accidentally write console.warn('Error occurred'). What is the main issue with this?
medium
A. The code will cause a syntax error
B. The message will be logged as a warning, not an error
C. The message will not appear in the console
D. The app will crash

Solution

  1. Step 1: Identify the difference between warn and error logs

    console.warn logs warnings; console.error logs errors. They differ in severity.
  2. Step 2: Understand the impact of using warn instead of error

    Using console.warn will log the message but mark it as a warning, not an error, which may mislead debugging.
  3. Final Answer:

    The message will be logged as a warning, not an error -> Option B
  4. Quick Check:

    Wrong log level changes message severity [OK]
Hint: Use console.error for errors, not console.warn [OK]
Common Mistakes:
  • Thinking warn causes errors
  • Expecting syntax error
  • Assuming message won't show
5. In an Express app, you want to log detailed information only when debugging is enabled, but always log warnings and errors. Which approach correctly uses log levels to achieve this?
hard
A. Use console.debug for detailed info, console.warn for warnings, and console.error for errors; enable debug logs conditionally.
B. Use console.info for all logs and filter messages manually.
C. Use console.error for all messages to ensure visibility.
D. Use console.warn for detailed info and console.debug for errors.

Solution

  1. Step 1: Assign log levels by message importance

    Detailed info fits debug, warnings fit warn, and errors fit error.
  2. Step 2: Enable debug logs conditionally

    Debug logs can be turned on or off based on environment or settings, while warnings and errors always log.
  3. Final Answer:

    Use console.debug for detailed info, console.warn for warnings, and console.error for errors; enable debug logs conditionally. -> Option A
  4. Quick Check:

    Conditional debug, always warn/error = correct logging [OK]
Hint: Debug logs conditional; warn and error always on [OK]
Common Mistakes:
  • Logging all as info
  • Using error for all messages
  • Mixing warn and debug levels incorrectly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard