What Are Logs? Log Levels and Formats Explained
At 9:05 a.m. a customer writes in: "I was charged at 2:14 last night, but my order never arrived." Your dashboard shows a small bump in errors at 2:14 and nothing more. It cannot tell you which order failed or why. To find out, you open the application's logs and search that minute. This lesson answers the question behind that move: what are logs, how serious is each line, and what shapes do they come in?
A log line is a timestamped event
A log is a record of events that a program writes while it runs. Each log line (also called a log entry or event) describes one thing that happened, such as a request arriving or a payment failing. Almost every line has three parts. A timestamp says when, a level says how serious, and a message says what happened.
Logs keep the detail that metrics throw away. A metric is a number over time, such as "3 errors in the last minute", and it is cheap because it keeps only the count. The log line behind one of those errors keeps the order ID, the error text and the exact millisecond. That is why logs answer "what exactly happened?", as the four signals lesson put it. It is also why they cost more: you store every event, not a summary.
Log levels: how serious is this line?
A log level is a label on each line that says how important it is. Most logging libraries use the same ladder, from least to most serious:
DEBUG: fine detail for developers, such as the contents of a shopping cart.INFO: normal milestones, such as "order placed" or "server started on port 8080".WARN(Python spells itWARNING): something unusual that the program handled, such as a retry.ERROR: one operation failed, such as a payment, but the program keeps running.FATAL(Python calls itCRITICAL): the program cannot continue and is about to stop.
Every logger has a threshold: it writes lines at that level and above, and silently drops the rest. Production systems usually run at INFO, because DEBUG output is often larger than everything else combined. You switch DEBUG on briefly while chasing a bug, then off again. Some libraries add a TRACE level below it.
Here is the threshold at work in Python's standard logging module. The logger is set to INFO, so the first call writes nothing:
import logging
logging.basicConfig(level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s %(message)s")
log = logging.getLogger("checkout")
log.debug("cart items=%s", ["sku-1", "sku-7"]) # below INFO: dropped
log.info("order placed order_id=%s", 8812)
log.warning("payment slow, retrying attempt=%d", 2)
log.error("payment failed order_id=%s reason=%s", 8812, "card_declined")
Running it prints three lines to stderr, which is where basicConfig sends output by default. The DEBUG line never appears:
2026-11-24 02:14:07,412 INFO checkout order placed order_id=8812
2026-11-24 02:14:07,950 WARNING checkout payment slow, retrying attempt=2
2026-11-24 02:14:08,301 ERROR checkout payment failed order_id=8812 reason=card_declined
To choose a level, ask who needs to act. If nobody does, use INFO or DEBUG. If the program recovered by itself, use WARN. If a user's request failed, use ERROR. Keep ERROR honest: when routine events are logged as errors, people learn to ignore the word.
Common log formats
A log format is the layout of each line. You will meet four. Free text is a sentence for a human, such as Payment failed for order 8812. Key=value (often called logfmt) labels each value: level=error msg="payment failed" order_id=8812. JSON writes each line as an object with named fields, which the next lesson covers in depth. The fourth is the web server access log.
An access log has one line per HTTP request, with fields in a fixed order. Web servers such as nginx and Apache share the "combined" format, and the official nginx Docker image adds one field at the end. This is the kind of line you will produce in the experiment at the end of this lesson:
172.17.0.1 - - [24/Nov/2026:10:15:41 +0000] "GET /nope HTTP/1.1" 404 153 "-" "curl/8.7.1" "-"
Read it left to right: who asked, when, what they asked for, what the server answered and how many bytes of body it sent. A dash means "no value". The diagram takes the same line apart field by field. The nginx log module documentation lists every variable a format can use.
Where logs go: stdout, files and journald
Every process starts with two output streams: stdout (standard output, for normal output) and stderr (standard error, for errors and diagnostics). A program can write its logs to either stream, to a file such as /var/log/nginx/access.log, or to the system's log service. On most Linux servers that service is journald, part of systemd, which keeps logs in a binary journal that you read with journalctl.
Containers follow a simpler convention: write logs to stdout and stderr, and let the platform handle them. The container runtime captures both streams and stores them on the host. Docker's default json-file driver keeps one file per container under /var/lib/docker/containers/, and Kubernetes nodes keep them under /var/log/pods/. The official nginx image even links its log files to the streams: access.log points to /dev/stdout and error.log to /dev/stderr.
These commands read logs from each of those places, limited to a recent time range:
docker logs --since 10m --tail 50 web # a container: last 50 lines of the past 10 minutes
kubectl logs deploy/checkout --since=10m # one pod of a Kubernetes deployment
journalctl -u nginx --since "10 min ago" -p warning # a systemd service: warning and worse
tail -f /var/log/nginx/access.log # a plain file: follow new lines live
The -p warning option keeps only lines at priority warning or more serious. journald uses the eight syslog priorities, from debug up to emerg, which map closely onto the levels above. During an incident, tail -f or docker logs -f shows new lines as they arrive.
What not to log
Logs travel further than you expect. They are copied to central servers, kept for months and read by many people, so anything secret in a log line is exposed in all of those places at once.
So never log passwords, tokens (API keys, session cookies, the HTTP Authorization header) or personal data such as email addresses, phone numbers, home addresses and card numbers. Privacy laws such as the EU's GDPR cover personal data in logs just like personal data anywhere else. Log a stable internal ID instead, such as user_id=42 rather than the customer's email. The OWASP Logging Cheat Sheet lists what to leave out.
Check yourself
Your logger's threshold is WARN. Which of these appear: INFO "server started", WARN "retrying", ERROR "payment failed"?
Only the WARN and the ERROR lines, because a logger writes its threshold level and everything more serious.
In the access-log line "GET /nope HTTP/1.1" 404 153, what do 404 and 153 mean?
404 is the HTTP status (Not Found) and 153 is the size in bytes of the response body the server sent.
Why do containerised apps log to stdout instead of to a file inside the container?
The runtime captures stdout and stderr and keeps them outside the container, where docker logs, kubectl logs and log collectors can read them; a file inside the container is hard to reach and disappears with it.