Skip to content
Back to skills

Logging

ASecurity

Application logging principles — stack-agnostic. Use when writing or reviewing ANY log statement in any language, choosing a log message or level, adding logging to handlers, services, consumers, jobs or endpoints, carrying context or correlation into logs, deciding what to log and where, or weighing log volume against observability. It encodes: the message as a fixed, low-cardinality grouping key (never interpolated, never carrying the failure), all variable data as structured properties, th...

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentsgoapi

Works with

  • api

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add JorgeCostaMacia/code-harness --skill logging --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Logging?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Logging
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jorgecostamacia-logging-code-harness/badge)](https://www.skillsdirectory.com/skills/jorgecostamacia-logging-code-harness)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: logging
description: >-
  Application logging principles — stack-agnostic. Use when writing or
  reviewing ANY log statement in any language, choosing a log message or
  level, adding logging to handlers, services, consumers, jobs or endpoints,
  carrying context or correlation into logs, deciding what to log and where,
  or weighing log volume against observability. It encodes: the message as a
  fixed, low-cardinality grouping key (never interpolated, never carrying the
  failure), all variable data as structured properties, the level as the
  outcome with the message unchanged, correlation in every scope, a failure
  logged once where it is handled, no secret in any store (secret fields
  marked for masking), the payload only in a private log store, and
  observability over log volume. The library and its idioms live in each
  stack's skill.
---

# Logging (principles)

People and tools consume logs as **structured data**: they query, group and count them, and alert on them (Loki/Grafana or any equivalent). Every rule below serves that: a log line is a record with a fixed name and typed fields, not a sentence. The library, its API and its configuration are each stack skill's.

## The message is a grouping key

The message is a **fixed, low-cardinality constant** — the name of the event or of the unit that logs it:

- **Never interpolate.** `"User 42 loaded in 13ms"` makes every occurrence a distinct message; counts, dashboards and alerts on it stop working.
- **No templates rendered into the message either** — [our convention]. A structured library can keep the template and the values apart, but the log store groups on the **rendered line**. A placeholder rendered into that line brings the cardinality back. The message groups; the data travels beside it as properties.
- **The message never carries the failure** — no exception text, no offending value. Those go in the error and the properties; the message stays stable.
- **[our convention] Name it after the unit that logs it**: the handler's or the job's own name. Then the key is unique and stable, and no one writes it by hand. When you rename the unit, its series gets the new name too.

## All variable data as properties

Every value that varies — ids, counts, inputs, the payload — is a **structured property** of the line. You can query it on its own (`UserId="42"`), and it is never part of the text. Log complex payloads **structured** (as an object), not as their string form. Query by property, never by message text.

## The level is the outcome; the message stays

An operation's outcomes share **one message** and differ by **level**, so the series splits by level under one key:

| Level | Means |
| --- | --- |
| **Information** | the normal path |
| **Warning** | an anomaly that is not a failure — skipped, retried, ignored |
| **Error** | the **operation** failed; the error travels as structured data, not in the message |
| **Critical** | the **application** cannot continue — a startup failure, an unrecoverable state, the host going down |

A test for Critical: *if the process still serves after the line, the line was not Critical.* A failed request or message is Error. An alert then needs no extra work: the rate of `message=X AND level=Error` over the total.

## Correlation in every scope

**Every** line carries the identity of the item in progress and the **correlation id** of its flow. They tie the line to the end-to-end trace across services. You cannot debug from a line that you cannot correlate.

## Who logs what

- **Cross-cutting logging is the pipeline's**: shared packages wire request logging, error logging, and environment and version enrichment once in the host. Never write them by hand in each service.
- **Log a failure once, where the code handles it**: usually the pipeline that turns it into a response, a retry or a parked message. Logging it at every layer on its way up multiplies one failure into many lines; log-and-rethrow is noise.
- **Application code logs its own events**: the line that says a handler, use case or job did its work, with its properties. A pipeline's request line can be that line for a handler: when the pipeline logs each request with its status and the properties that the handler pushed, the handler logs nothing more.
- **Never log a secret, in any store**: passwords, tokens, API keys, connection strings, and the `Authorization`, `Cookie` and `Set-Cookie` headers. This rule wins over every rule that asks for a payload. A secret field of a payload or a request is marked, so that the log masks it. That mark is the rule, not an option. The logging library is expected to mask those headers and the marked fields by default.

## Observability over volume — [our convention]

Asynchronous pipelines log **one Information line for each message they handle**, with its identity, its correlation and its counts, on purpose. **The payload is required on the lines of a failure, a retry and a parking.** From those lines, someone traces a message back to what it carried, and inspects or replays it. **On the success line, the payload is recommended but optional.** It keeps the full trail; without it, the identity and the correlation still trace the message. A slower consumer costs nothing visible. A lost trail costs the ability to trace a message back to what it carried. **Retention and rotation** manage the disk, not higher levels or fewer lines. Change a minimum level per source in configuration — never by deleting log statements.

**The payload goes only to a private log store**: a store with restricted access and a defined retention. A payload can carry personal data, and everyone who can read the store reads it. Log personal data only in such a store, and only where the purpose justifies it. A project without a private log store does not log personal data: its payloads mark their personal fields for masking, as they mark their secrets. If you do not know whether the store is private, ask the person.

## Anti-patterns

- ✘ An interpolated message: it makes one series per value, without limit.
- ✘ A placeholder template that renders values into the message.
- ✘ The exception's text in the message, and the exception itself not logged as structured data.
- ✘ An object serialized into the message instead of logged as a structured property.
- ✘ A one-off phrase per call site ("about to start processing…") — unqueryable; if it deserves a log, it deserves a stable name.
- ✘ Levels as emphasis — the level is the outcome.
- ✘ Critical for a failed operation.
- ✘ The same failure logged by every layer it passes through.
- ✘ A secret in a line, or a secret field that is not marked for masking.
- ✘ A payload with personal data in a log store that is not private.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.