🎓 A1Learner
🔍
0 of 50 lessons completed

Logging

Logging is the habit of printing what a program does as it runs. Each log line names one event.

Log a plain event

This line logs that the server started.

console.log("[INFO] Server started");

Log a problem

This line logs a note that was not found.

console.error("[ERROR] Note not found");

Example

console.log("[INFO] Server started");
console.log("[INFO] GET /notes");
console.error("[ERROR] Note not found");
console.log("[INFO] Server stopped");

Key points

  • Logging is the habit of printing what a program does as it runs.
  • Each log line names one event.
  • Use console.log for plain events.
  • Use console.error for problems.
  • A level word names how serious the event is.
  • Start each line with a level word like INFO or ERROR.

In this example, each line logs one event. The INFO lines name plain events. The ERROR line names a problem. The ERROR line goes to the error stream, and the other lines go to the plain output. A terminal shows both streams together.

Note

Logs stay in the terminal, so they suit a running server.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which line logs a problem?