/swift-skills:swift-structured-loggingfrom swift-skills
Structured logging for Swift/macOS apps using the SBLogger pattern. Use when adding a new log category to a Swift service, writing log messages in Swift code, setting up logging infrastructure in a new Swift project, or reviewing log message format consistency. Triggers on: 'add logging', 'new log category', 'set up logging', 'log messages', 'SBLogger', 'Logger category'. Swift-specific — covers Sendable isolation, nonisolated let, MainActor, os.Logger, and stderr debug output.
Ships in swift-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Enforce consistent logging across Swift/macOS apps using the SBLogger pattern: actor-based stderr sink in DEBUG, os.Logger in release, domain-labeled categories, and a strict message format.
Two files, one line each:
Logger extension (e.g., Logger+AppName.swift):
static nonisolated let calendar = SBLogger(subsystem: subsystem, category: "Calendar")
SBLogger domain labels (e.g., AppLogger.swift):
"Calendar": "📅 AppName.Calendar",
Then at file scope in the service — never inside the class:
private nonisolated let log = Logger.calendar
Bare private let picks up MainActor isolation from project settings and breaks in actors/nonisolated contexts. Always use private nonisolated let.
Every log message follows: "methodName: description" with optional " — detail" suffix.
The method prefix is non-negotiable — without it, log output from multiple services is indistinguishable. The dash separator before error details enables grep filtering.
// Success
log.info("createEvent: \"\(title)\"")
// Failure — method prefix, then dash, then error
log.error("createEvent: failed — \(error)")
// State
log.info("syncStatus: events=\(eventStatus), reminders=\(reminderStatus)")
// Decision
log.info("perform: requesting access for events")
// Rejection
log.info("speakOnly: rejected — phase is \(phase)")
// Warning
log.warning("perform: access denied for reminders")
// Missing method prefix — useless in mixed log output
log.info("Created event: \(title)")
// Generic — which method? Which service?
log.error("Failed to create event")
// Verbose — log lines aren't prose
log.info("The event was successfully created and saved to the calendar")
Adding logging to a new PaymentService:
// 1. Logger+App.swift — add category
static nonisolated let payments = SBLogger(subsystem: subsystem, category: "Payments")
// 2. AppLogger.swift — add domain label
"Payments": "💳 MyApp.Payments",
// 3. PaymentService.swift — file scope logger + usage
private nonisolated let log = Logger.payments
@Observable final class PaymentService {
func processPayment(amount: Decimal, merchantId: String) async throws -> Receipt {
log.info("processPayment: \(amount) to \(merchantId)")
do {
let receipt = try await gateway.charge(amount: amount, merchant: merchantId)
log.info("processPayment: completed — receipt \(receipt.id)")
return receipt
} catch {
log.error("processPayment: failed — \(error)")
throw error
}
}
func refund(receiptId: String) async -> RefundResult {
guard let receipt = store.find(receiptId) else {
log.warning("refund: receipt not found — \(receiptId)")
return .notFound
}
log.info("refund: processing \(receiptId)")
// ...
}
}
Output in DEBUG:
[14:23:01.445] [INFO] [💳 MyApp.Payments] processPayment: 29.99 to merch_abc123
[14:23:02.112] [INFO] [💳 MyApp.Payments] processPayment: completed — receipt rec_xyz789
After adding logging to a file, grep to check format consistency:
grep -n 'log\.\(info\|error\|warning\|debug\)' Services/NewService.swift
Every match should show "methodName: immediately after the opening quote. Flag any that start with a capital letter without a method prefix, or use generic phrasing like "Failed to" or "Successfully".
When setting up logging in a new project (not adding to an existing one), read the existing SBLogger and LogSink implementations in SpokenBite as the reference pattern:
SBLogger — Sendable struct, four levels, @autoclosure messages, #if DEBUG stderr via LogSink actor, release via os.LoggerLogSink — actor with DateFormatter, writes [timestamp] [LEVEL] [label] message to stderrWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
4 skills in this plugin
/axiom-accessibility-diagUse when fixing VoiceOver issues, Dynamic Type violations, color contrast failures, touch target problems, keyboard navigation gaps, or Reduce Motion support - comprehensive accessibility diagnostics with WCAG compliance, Accessibility Inspector workflows, and App Store Review preparation for iOS/macOS/axiom-swiftdataUse when working with SwiftData - @Model definitions, @Query in SwiftUI, @Relationship macros, ModelContext patterns, CloudKit integration, iOS 26+ features, and Swift 6 concurrency with @MainActor — Apple's native persistence framework/foundation-modelsComplete guide for Apple's on-device Foundation Models framework (iOS 26+). Use when implementing, debugging, or architecting with Foundation Models. Triggers on: 'Foundation Models', 'LanguageModelSession', '@Generable', '@Guide', 'on-device LLM', 'FM framework'. Covers API reference, anti-patterns, decision trees, diagnostics, Instruments triage, and production crisis defense.npx claudepluginhub foxtrottwist/swift-skills --plugin swift-skills