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
- theexperiencecompany/gaiatheir own version, first seen Nov 26, 2026
- gilsmt/skillstheir own version, first seen Nov 25, 2026
- anis-dr/skillstheir own version, first seen Oct 15, 2026
- Mindrally/skillstheir own version, first seen Oct 8, 2026
- neondatabase/mcp-server-neontheir own version, first seen Oct 8, 2026
- deadlock-mod-manager/deadlock-mod-managertheir own version, first seen Oct 8, 2026
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.
AnasX7Skillshow-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
GoogleSkillimprove-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
CloudflareSkillreceiving-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
OpenAISkillexecuting-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
OpenAISkillrequesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
Also in 3 projects that use this
SentrySkillsecurity-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
Other versions16 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 16
- neondatabase/mcp-server-neon★ 663same name
- deadlock-mod-manager/deadlock-mod-manager★ 638same name
- theexperiencecompany/gaia★ 336same name
- Mindrally/skills★ 275same name
- boristane/agent-skills★ 119same name
- ncklrs/startup-os-skills★ 51same name
- nbbaier/agent-skills★ 15same name
- FaisalAlqarni/sp-ecc★ 9same name
- Stormix/transcripts-mcp★ 8same name
- niieani/caara★ 5same name
6 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository3 other files it gives its agents.
- reclaim-dev-disk-spaceSkill
- reflectSkill
- xcuitest-best-practicesSkill
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
- Very specific: line 21
The message is a constant: Every variable goes in metadata.
“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.
Files
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
- 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. - Keys name the value truthfully.
SensitiveKeyRedactormatches keys (token,key,secret,password,credential,seed,mnemonic,phone,email)."email": user.emailis scrubbed;"account": user.emailleaks to every sink. If the value is an email, the key saysemail— this is also what makes logs greppable. - Log personal data only on the line that needs it. A failure being investigated earns an identifier; a happy-path "sync succeeded" does not.
- One
private static let log = Log("CategoryName")per type or feature area. The name is the Console category filter. Neverprint(), never a bareos.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
| Level | Records |
trace | finest-grained control flow; off in release builds |
debug | worth seeing while working on this code, and not after |
info | worth knowing when reading a normal session back |
notice | out of the ordinary, not yet wrong |
warning | something wrong the app absorbed and carried on from |
error | a failure the user can feel |
critical | a failure the app cannot carry on past |
App wiring
Logbook.bootstrap(subsystem:configuration:)runs first thing in the app's init, before anything logs, withSensitiveKeyRedactor()inmiddleware— addPatternRedactor()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
| Mistake | Fix |
log.error("Failed: \(error)") | constant message; "error": "\(error)" in metadata |
"account": user.email | the key is email — redaction matches keys |
| email or user id on success lines | identifiers only where an investigation needs them |
print() or bare os.Logger | a Log — nothing else reaches every sink or middleware |
| tests writing real log files | files: nil, or a temporary directory |
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
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.

