Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 min

Structured logging

Understand the idea

A sentence in the console is not a record you can search when the request has already finished.

The idea

The first run is the habit to retire: one sentence, no ids. The second run is one JSON object. is being able to connect that object to a failed . When you debug a slow query, a model body that crashed a route, or a route with no limit, the log should name the route and the status so it matches the Debug Library entry you open. Those entries live at /debug/unindexed-query-slow/, /debug/malformed-ai-response/, and /debug/missing-rate-limit/. A sentence does not point at them. A request id does.

What changes

Sentence and record
LogCan you filter it?What is missing
something failedNoLevel, id, status
JSON with level, msg, noteId, requestId, statusYesNothing this lesson needs
The whole request including headersYes, and dangerousA boundary. Do not log secrets

The command

A sentence

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

One JSON record

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

The first run prints something failed. The second prints one JSON object with level error, msg note missing, noteId 9, requestId req-1, and status 404.

Guided challenge

Log the error status 404

The structured log says status 200. Change the status field to 404 so the record matches a missing note.

Log the error status 404

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

"status":404

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What is wrong with logging something failed?
    02Which fields belong on the error line?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson