Logging and Debugging

Good logging helps people understand a running system under pressure. It should provide enough context to explain what happened, where it happened and what the last successful step was, without turning every request into a wall of noisy text.

Structured logs

Logs become far easier to search and correlate when they use predictable fields instead of only free text. A common pattern is to include level, event, route and request_id.

funksjon logg_info(hendelse: tekst, steg: tekst, id: tekst) -> tekst {
    returner "{\"level\":\"info\",\"event\":\"" + hendelse + "\",\"trace_id\":\"" + id + "\"}"
}

Debugging workflow

When something fails, start with correlation: identify the request or trace ID, find the last successful step, check the boundaries to integrations or storage, and only then move into detailed hypotheses. This keeps debugging calm and repeatable.

For broader operational context, read this chapter together with observability and reliability.