# Logging

> Writing down what a program does, one timed line per event.

**Field:** Infrastructure  
**Category:** Monitoring & Observability  
**Also known as:** Log, Logs, Log File, Application Log, Structured Logging

## Think of it like

It is like a ship's diary. Each line says what happened and when.

## Definition

Logging is writing down events, one line at a time, as a program runs. Each line, called a log entry, has a time, a level and a message. It might say a user logged in, or a payment failed. The lines go to a file or to a tool that gathers logs from many servers. Logs are the place to look for the details of one event.

## Example

A payment fails for one buyer. Jack searches the logs for the order number and finds the line saying the card was refused.

## Example code

```json
{"time": "2026-11-16T09:14:02Z", "level": "error", "msg": "payment failed", "order": 4182}
```

One structured log line. Each part has a name, so a tool can search by order or level.

## Why it matters

When something breaks, the log is often the only record of what took place.

## Common mistake

Writing passwords or card numbers into logs. Many people can read logs, and they are kept for a long time.

## Three principles

- **Time on every line.** So events can be put in order.
- **Structured.** Named fields are easy to search.
- **Gathered in one place.** Logs from all servers, searched together.

## Related terms

- [Log Level](https://learn.benibix.com/term/infrastructure/log-level)
- [Observability](https://learn.benibix.com/term/infrastructure/observability)
- [Metric (Monitoring)](https://learn.benibix.com/term/infrastructure/metric)
- [Distributed Tracing](https://learn.benibix.com/term/infrastructure/distributed-tracing)
- [Stack Trace](https://learn.benibix.com/term/development/stack-trace)
- [Log Aggregation](https://learn.benibix.com/term/infrastructure/log-aggregation)
- [Print Debugging](https://learn.benibix.com/term/development/print-debugging)

## Told apart from

- [Print Debugging vs Logging](https://learn.benibix.com/compare/print-debugging-vs-logging): People think print debugging is the same as logging, and it is not. Print lines are short-lived. You add them to chase one bug, then delete them. Logging stays in the code for good. It writes events with a time and a level, so people can read them long after the code ran.

![Three panels side by side about the same slow request. Logs: three lines of text, each with a time and a message, the last one an error. Metrics: a line chart of response time over an hour, with a spike. Traces: a set of stacked bars, one per step of the request, where the database bar is the longest.](https://learn.benibix.com/diagrams/inf-telemetry-signals.svg)

---

Source: https://learn.benibix.com/term/infrastructure/logging
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
