agentleFS
raulrieraraulriera/skills/logging-best-practices/SKILL.md

logging-best-practices

Skill2 starsChanged 4 months agoMITView on GitHub

Use when adding or reviewing logging in Swift code that uses the Logbook package — log calls, levels, metadata, redaction, bootstrap/flush wiring, or logging in tests. Symptoms: values interpolated into log messages, personal data (email, phone, token) reaching logs, metadata keys that hide what a value is, print() in app code.

16 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use show-me, improve-codebase-architecture and 5 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • AnasX7Skill

    show-me

    Help the user understand the current topic visually with concise diagrams, code-shape sketches, and focused HTML artifacts.

    Also in 3 projects that use this

  • GoogleSkill

    improve-codebase-architecture

    Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

    Also in 4 projects that use this

  • CloudflareSkill

    receiving-code-review

    Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation

    Also in 3 projects that use this

  • OpenAISkill

    executing-plans

    Use when you have a written implementation plan to execute in a separate session with review checkpoints

    Also in 3 projects that use this

  • OpenAISkill

    requesting-code-review

    Use when completing tasks, implementing major features, or before merging to verify work meets requirements

    Also in 3 projects that use this

  • SentrySkill

    security-review

    Finds exploitable application security vulnerabilities in code changes. Use for Warden security scans, appsec review, OWASP-style checks, authentication or authorization bugs, injection, XSS, SSRF, path traversal, secrets, unsafe crypto, webhook verification, open redirects, or sensitive data exposure.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 16 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    The message is a constant: Every variable goes in metadata.

    line 21

“Common” is measured: kept by at least 6 in 10 of the 16 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Logging Best Practices

Overview

Logbook fans every entry out to the unified log, an in-memory ring buffer, and rotating files — after a middleware chain scrubs it. Middleware only sees metadata, so everything below exists to keep sensitive values where middleware can catch them.

The contract at every call site

  1. The message is a constant. Every variable goes in metadata. A value interpolated into the message reaches Console and the exported file exactly as written — middleware never sees it.
  2. Keys name the value truthfully. SensitiveKeyRedactor matches keys (token, key, secret, password, credential, seed, mnemonic, phone, email). "email": user.email is scrubbed; "account": user.email leaks to every sink. If the value is an email, the key says email — this is also what makes logs greppable.
  3. Log personal data only on the line that needs it. A failure being investigated earns an identifier; a happy-path "sync succeeded" does not.
  4. One private static let log = Log("CategoryName") per type or feature area. The name is the Console category filter. Never print(), never a bare os.Logger — neither reaches the ring buffer, the file, or middleware.
// ❌ message carries values; key hides that the value is an email; PII on the happy path
Self.log.info("Sync started for \(account.email)")
Self.log.error("Sync failed", metadata: ["account": account.email])

// ✅
Self.log.info("Sync started")
Self.log.error("Sync failed", metadata: [
    "email": account.email,          // key-matched, so the redactor scrubs it
    "endpoint": endpoint.absoluteString,
    "error": "\(error)",
])

Levels

LevelRecords
tracefinest-grained control flow; off in release builds
debugworth seeing while working on this code, and not after
infoworth knowing when reading a normal session back
noticeout of the ordinary, not yet wrong
warningsomething wrong the app absorbed and carried on from
errora failure the user can feel
criticala failure the app cannot carry on past

App wiring

  • Logbook.bootstrap(subsystem:configuration:) runs first thing in the app's init, before anything logs, with SensitiveKeyRedactor() in middleware — add PatternRedactor() where emails or phone numbers can appear under innocent keys. Before bootstrap, metadata is dropped rather than risked.
  • await Logbook.flush() as the app leaves the foreground — lines batch before reaching disk, and a part-filled batch dies with the process.
  • From an app extension, pass the host app's subsystem explicitly; the default would name the extension.

Tests

Configuration sets files: nil, or points directory at a temporary one. A test never writes the real Caches/Logs.

Common mistakes

MistakeFix
log.error("Failed: \(error)")constant message; "error": "\(error)" in metadata
"account": user.emailthe key is email — redaction matches keys
email or user id on success linesidentifiers only where an investigation needs them
print() or bare os.Loggera Log — nothing else reaches every sink or middleware
tests writing real log filesfiles: nil, or a temporary directory

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.