# When and what should I be logging?

[Sentry](https://yomu.fyi/company/sentry) · Ben Coe · Jul 9, 2026

**Type:** Explainer

## Summary

Targeted structured logging provides a fast way to capture operational behavior in production without requiring new deployments for debugging. Developers benefit most from logging key runtime decisions, multi-step algorithm outcomes, mutating audit operations, and context around non-critical or retried errors. Rather than outputting plain text, applications should record structured key-value pairs that capture who performed an action, what occurred, and associated trace identifiers. Sensitive information such as secrets and personally identifiable data must be excluded or scrubbed, and large unparsed payloads should be avoided to prevent excessive costs. Managing log levels appropriately and treating logs as potentially temporary instrumentation helps maintain actionable telemetry without generating unnecessary noise.

## Context

Choosing among telemetry options like traces, profiles, metrics, and logs can be difficult when building and debugging applications. Developers need fast, reliable ways to capture production runtime behavior without over-instrumenting code or leaking sensitive data.

## Approach / What changed

The author recommends starting with targeted, structured key-value log lines to capture runtime decisions, multi-step algorithm outcomes, audit events, and non-critical error context. Structured logs should accumulate request context, include trace identifiers, use appropriate log levels, and avoid full payload blobs, passwords, or personal data.

## Takeaways

- Structured logs using consistent key-value pairs enable searching, visualizations, and alerts, while answering who performed an action, what happened, and when it occurred.
- Applications should log runtime decision branches, intermediate algorithm progress, mutating audit events, and failure context such as retry counts instead of logging every line of code.
- To manage security, compliance, and volume costs, sensitive data and secrets must be scrubbed or replaced with opaque IDs, and large unstructured payloads should be avoided.

**Tags:** [Developer Experience](https://yomu.fyi/topic/developer-experience), [Monitoring](https://yomu.fyi/topic/monitoring), [Observability](https://yomu.fyi/topic/observability)

[Read original post](https://blog.sentry.io/logging-best-practices)
