Logging with structured formats helps you save information in a clear, organized way. This makes it easier to find and understand what happened in your app.
When you want to track errors and events in your Node.js app clearly.
When you need to send logs to tools that analyze data automatically.
When you want to keep logs readable by both humans and machines.
When you want to include extra details like time, user ID, or request info in logs.
When debugging problems in production or development environments.
A. The order of arguments is incorrect; the object should come first.
B. Missing semicolon after require statement.
C. pino() must be called with configuration object.
D. logger.info cannot accept two arguments.
Solution
Step 1: Check pino.info argument order
pino expects the first argument as an object with extra data, second as message string.
Step 2: Analyze given code
The code passes message string first, then object, which is reversed and causes wrong output.
Final Answer:
The order of arguments is incorrect; the object should come first. -> Option A
Quick Check:
pino.info(object, message) argument order [OK]
Hint: Pass object first, then message string to logger.info [OK]
Common Mistakes:
Swapping message and object arguments
Thinking semicolon is mandatory for correctness
Assuming pino() needs config always
5. You want to log user events with structured logs including user ID, event type, and timestamp using pino. Which code snippet correctly logs this data ensuring timestamp is included in the JSON output?
hard
A. logger.info({ userId: 123, event: 'click' }, 'User event at ' + new Date());
C. logger.info({ userId: 123, event: 'click', time: new Date().toISOString() }, 'User event');
D. logger.info({ userId: 123, event: 'click', timestamp: Date.now() });
Solution
Step 1: Ensure correct argument order and timestamp format
pino expects object first, then message string. Timestamp should be ISO string for readability.
Step 2: Check each option
logger.info({ userId: 123, event: 'click', time: new Date().toISOString() }, 'User event'); passes object with userId, event, and ISO timestamp, then message string. This is correct.
Final Answer:
logger.info({ userId: 123, event: 'click', time: new Date().toISOString() }, 'User event'); -> Option C
Quick Check:
Object first with ISO timestamp, then message [OK]
Hint: Pass object with ISO timestamp first, then message string [OK]
Common Mistakes:
Swapping message and object arguments
Using Date.now() without formatting
Concatenating message and timestamp in string
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.