# How to structure a log

[Sentry](https://yomu.fyi/company/sentry) · Kyle Tryon · Jul 21, 2026

**Type:** Tutorial

## Summary

Logging arbitrary JSON objects often produces unstable messages and deeply nested data that complicate searching, aggregating, and debugging production incidents. Structured logging treats log output as real application data by establishing predictable, consistent schemas across services. Engineers should define stable event names using a domain.action pattern and capture dynamic dimensions with flattened, snake\_case attributes formatted in dot notation. Attribute payloads must contain only primitive values or primitive arrays rather than arbitrary objects, utilizing low-cardinality result identifiers and explicit units for numeric measurements. Teams can enforce these structural conventions automatically with linting tools such as ESLint, while routing execution durations and timing measurements to tracing spans.

## Context

Unstructured log messages with dynamic text and arbitrary nested JSON objects make logs difficult to query, filter, group, aggregate, and analyze during production incident debugging.

## Approach / What changed

Adopt a standardized logging schema that utilizes stable domain.action event names, flattened dot-notation attribute keys, primitive values, explicit numeric units, and linting rules for automated enforcement.

## Takeaways

- Event names should follow a stable domain.action pattern without dynamic strings in the message, placing dynamic variables into scoped attributes instead.
- Attributes must use flattened dot-notation keys with snake\_case segments and restrict values to primitive types or arrays of primitives rather than raw nested objects.
- Numeric attributes should explicitly specify units within their key names, and execution duration measurements should be recorded in tracing spans rather than log attributes.

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

[Read original post](https://blog.sentry.io/structure-a-log)
