Logging
Логирование
Software records events in a log so people can see what happened, when it happened, and what was going on at the time.
What logging is for
Logging gives you a record of what a system did while it was running. A web server might record the status of each HTTP response, while a background worker might record why it abandoned a job. When a customer reports a failure you can't reproduce, those records give you a place to start.
From an event to a searchable record
When code calls a logger, the logging library can attach a timestamp and severity, format the entry, and send it to a configured destination. Common levels include DEBUG for diagnostic detail, INFO for routine events, WARN for unexpected conditions that don't necessarily stop the work, and ERROR for failures. With a minimum level of INFO, a logger typically suppresses DEBUG entries. Agree on what the levels mean within your team rather than assuming every application uses them the same way.
Containerized apps commonly write to standard output and standard error. A collector reads those streams through the platform's logging mechanism, adds context such as the container name, and forwards entries to a central store. This lets you search across replicas without knowing which one handled the request. It also preserves records that reached the store before a container was removed.
Example: a job stops retrying
A worker that has used up its retry budget could emit one structured record:
{"timestamp":"2026-06-10T09:14:32Z","level":"ERROR","service":"email-worker","event":"delivery_retries_exhausted","job_id":"job-731","attempts":5}
event names the outcome, and job_id lets you look up earlier attempts if they were logged with the same ID. Because attempts is a numeric field rather than part of the message, you can filter or aggregate on it without parsing prose. The record tells you that the worker stopped retrying; by itself, it doesn't tell you why delivery failed.
What to log and what to leave out
Use logs to explain individual events. A metric can tell you that the job failure rate doubled; logs can show the error returned on a particular attempt. A distributed trace answers a different question: where did a request go, and how much time did it spend at each step?
Log enough context to investigate the issue without dumping request bodies, passwords, or access tokens. Prefer an explicit set of approved fields. In production, set a retention period and check the volume before enabling verbose output: more logs cost more to ship and store, and noise makes useful events harder to find. Avoid recording the same exception as an error at every layer that catches and rethrows it.
In interviews
Expect a scenario such as “One customer got a 500, but the dashboard looks normal. What do you do?” Start with a time window and a request or trace ID, then follow that ID across service logs. Explain which record points to the underlying failure and which records merely report its effects.