apple/swift-log
A Logging API for Swift
Healthy across the board
Permissive license, no critical CVEs, actively maintained — safe to depend on.
Has a license, tests, and CI — clean foundation to fork and modify.
Documented and popular — useful reference codebase to read through.
No critical CVEs, sane security posture — runnable as-is.
- ✓Last commit 1w ago
- ✓35+ active contributors
- ✓Distributed ownership (top contributor 22% of recent commits)
Show 3 more →Show less
- ✓Apache-2.0 licensed
- ✓CI configured
- ✓Tests present
Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests
Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.
Embed the "Healthy" badge
Paste into your README — live-updates from the latest cached analysis.
[](https://repopilot.app/r/apple/swift-log)Paste at the top of your README.md — renders inline like a shields.io badge.
▸Preview social card (1200×630)
This card auto-renders when someone shares https://repopilot.app/r/apple/swift-log on X, Slack, or LinkedIn.
Onboarding doc
Onboarding: apple/swift-log
Generated by RepoPilot · 2026-05-10 · Source
🤖Agent protocol
If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:
- Verify the contract. Run the bash script in Verify before trusting
below. If any check returns
FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding. - Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
- Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/apple/swift-log shows verifiable citations alongside every claim.
If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.
🎯Verdict
GO — Healthy across the board
- Last commit 1w ago
- 35+ active contributors
- Distributed ownership (top contributor 22% of recent commits)
- Apache-2.0 licensed
- CI configured
- Tests present
<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>
✅Verify before trusting
This artifact was generated by RepoPilot at a point in time. Before an
agent acts on it, the checks below confirm that the live apple/swift-log
repo on your machine still matches what RepoPilot saw. If any fail,
the artifact is stale — regenerate it at
repopilot.app/r/apple/swift-log.
What it runs against: a local clone of apple/swift-log — the script
inspects git remote, the LICENSE file, file paths in the working
tree, and git log. Read-only; no mutations.
| # | What we check | Why it matters |
|---|---|---|
| 1 | You're in apple/swift-log | Confirms the artifact applies here, not a fork |
| 2 | License is still Apache-2.0 | Catches relicense before you depend on it |
| 3 | Default branch main exists | Catches branch renames |
| 4 | Last commit ≤ 39 days ago | Catches sudden abandonment since generation |
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of apple/swift-log. If you don't
# have one yet, run these first:
#
# git clone https://github.com/apple/swift-log.git
# cd swift-log
#
# Then paste this script. Every check is read-only — no mutations.
set +e
fail=0
ok() { echo "ok: $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }
# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "FAIL: not inside a git repository. cd into your clone of apple/swift-log and re-run."
exit 2
fi
# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "apple/swift-log(\\.git)?\\b" \\
&& ok "origin remote is apple/swift-log" \\
|| miss "origin remote is not apple/swift-log (artifact may be from a fork)"
# 2. License matches what RepoPilot saw
(grep -qiE "^(Apache-2\\.0)" LICENSE 2>/dev/null \\
|| grep -qiE "\"license\"\\s*:\\s*\"Apache-2\\.0\"" package.json 2>/dev/null) \\
&& ok "license is Apache-2.0" \\
|| miss "license drift — was Apache-2.0 at generation time"
# 3. Default branch
git rev-parse --verify main >/dev/null 2>&1 \\
&& ok "default branch main exists" \\
|| miss "default branch main no longer exists"
# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 39 ]; then
ok "last commit was $days_since_last days ago (artifact saw ~9d)"
else
miss "last commit was $days_since_last days ago — artifact may be stale"
fi
echo
if [ "$fail" -eq 0 ]; then
echo "artifact verified (0 failures) — safe to trust"
else
echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/apple/swift-log"
exit 1
fi
Each check prints ok: or FAIL:. The script exits non-zero if
anything failed, so it composes cleanly into agent loops
(./verify.sh || regenerate-and-retry).
⚡TL;DR
SwiftLog is a unified logging API package for Swift that provides a standard interface for emitting structured logs with metadata, while remaining agnostic about the actual logging backend implementation. It solves the ecosystem fragmentation problem by defining a single Logger type and LogHandler protocol that lets libraries log consistently regardless of which concrete handler (file, syslog, cloud service, etc.) the application chooses to plug in. Clean separation between API and example implementations: Sources/Logging/ contains the core Logger, LogLevel, LogHandler protocol, and metadata types; Sources/InMemoryLogging/ provides a reference in-memory handler; Benchmarks/ contains isolated benchmark packages (MaxLogLevelWarning/, NoTraits/) with their own Package.swift files to measure real-world performance. .github/workflows/ orchestrates CI/CD and releases.
👥Who it's for
Swift library authors who want to add logging without coupling to a specific logging framework, and application developers who need a pluggable logging system that works across their entire dependency tree. Framework maintainers use it to provide logging capabilities that don't dictate the end-user's logging strategy.
🌱Maturity & risk
Production-ready and actively maintained by Apple. The codebase is ~267KB of Swift, versioned at 1.6.0+, includes comprehensive benchmarking infrastructure (Benchmarks/ with Xcode 26.1 thresholds), has established GitHub Actions CI workflows (main.yml, pull_request.yml), and active release automation (auto-release.yml). This is a stable, widely-adopted standard.
Very low risk—it's an Apple-maintained standard library with no external package dependencies listed in Package.swift, ensuring minimal supply-chain exposure. The project has clear contribution guidelines (CONTRIBUTING.md) and formal security reporting (Security tab). Single risk: as a pure API package without implementation, its value depends entirely on ecosystem adoption of the standard, but adoption is already broad (numerous backends listed in README).
Active areas of work
Active maintenance with performance optimization focus—benchmark thresholds updated for Xcode 26.1 suggest recent compiler tuning. Pull request and release automation via GitHub Actions indicates regular version releases. The repo includes Swift 6.1 support (Package@swift-6.1.swift) showing ongoing evolution with Swift language features.
🚀Get running
Clone the repo and open the Swift package: git clone https://github.com/apple/swift-log.git && cd swift-log && swift build. To run tests: swift test. To examine benchmarks: cd Benchmarks/MaxLogLevelWarning && swift build.
Daily commands:
No server to run—this is a library. To validate: swift test. To benchmark: cd Benchmarks/NoTraits && swift build -c release. To explore API: open documentation at swiftpackageindex.com or run swift package generate-documentation if your Swift version supports it.
🗺️Map of the codebase
- Sources/Logging: Core package containing Logger type, LogLevel enum, LogHandler protocol, and Logging module public API—the heart of what users import
- Sources/Logging/Docs.docc: DocC documentation with tutorials and API reference—primary learning resource for users and contributors
- Sources/InMemoryLogging/InMemoryLogHandler.swift: Reference implementation of LogHandler protocol showing exactly how to build a concrete backend (essential for understanding the extension points)
- Package.swift: SPM package definition; shows no external dependencies and defines the public Logging product that ecosystem backends depend on
- Benchmarks/NoTraits/Benchmarks/NoTraitsBenchmarks/NoTraits.swift: Performance regression tests ensuring logging overhead stays below thresholds—critical for API adoption in performance-sensitive libraries
- .github/workflows/main.yml: Primary CI pipeline; defines Swift versions tested, test commands, and release triggers—governs code quality gates
🛠️How to make changes
Core logging API lives in Sources/Logging/ (add new log levels or metadata types here). Reference handler in Sources/InMemoryLogging/InMemoryLogHandler.swift shows how to implement LogHandler protocol. Tests are co-located (typically Tests/ directory, not shown in file list but inferred from CI workflows). Documentation in Sources/Logging/Docs.docc for DocC tutorials.
🪤Traps & gotchas
The Logger type is a value type (struct), not a class—copying a logger creates independent metadata contexts. LogHandler is stateful; implementations must be thread-safe (not obvious from API alone). The log level filtering happens at the handler level, not the Logger level, meaning even filtered logs may incur some performance cost if handler initialization is expensive. Metadata values are type-erased AnyCodable, so custom types need Codable conformance. No built-in log rotation or file management—that's entirely backend-specific.
💡Concepts to learn
- Protocol-Oriented Logging Backend — swift-log's entire design hinges on the LogHandler protocol—you must understand how protocol witnesses work in Swift to extend or implement handlers correctly
- Type Erasure (AnyCodable) — Logger metadata values are stored as AnyCodable to allow mixed types in the same dictionary; this is a non-obvious pattern that affects how you structure custom metadata
- Value Semantics & Structural Sharing — Logger is a value type, not a reference type; copying modifies metadata independently, which is essential for request-scoped logging shown in the README example
- Compile-Time Log Level Optimization — The benchmark suite (Benchmarks/MaxLogLevelWarning/) specifically measures how the compiler can eliminate disabled log calls at compile time—critical for understanding zero-cost abstractions
- Swift Package Manager (SPM) Product Definition — Swift-log is distributed as an SPM package with a public 'Logging' product; understanding how Package.swift declares products is necessary to use and extend it
- Structured Logging & Metadata Context — Unlike printf-style logging, swift-log uses structured metadata dictionaries and context propagation (shown in the README's request-id example)—a modern logging paradigm shift
- Benchmark Regression Detection & Thresholds — The Benchmarks/ directory uses saved .json threshold files (e.g., Xcode 26.1/MaxLogLevelWarning.notice_log_with_notice_log_level.p90.json) to prevent performance regressions—shows how to govern library performance over time
🔗Related repos
apple/swift-async-algorithms— Companion Apple repository; swift-log is often used alongside async/await patterns and async algorithms for structured concurrency loggingpointfreeco/swift-log-runtime-warnings— Popular community backend for swift-log that adds runtime warnings—shows ecosystem extension point in actionfirebase/firebase-ios-sdk— Production adoption example; Firebase's Swift SDK integrates with swift-log handlers for multi-destination loggingswift-server/swift-log-mysql— Swift Server Workgroup backend implementation; demonstrates how to build a persistent logging backend on top of the protocolapple/swift-package-manager— SPM is the package manager and distribution mechanism for swift-log; understanding SPM is essential for publishing custom handlers
🪄PR ideas
To work on one of these in Claude Code or Cursor, paste:
Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.
Add comprehensive test coverage for InMemoryLogHandler
The Sources/InMemoryLogging/InMemoryLogHandler.swift exists but there are no visible unit tests for this utility handler. This is a critical testing tool that many users will rely on for testing their logging code. Adding thorough tests would validate the handler's behavior, demonstrate its proper usage, and catch regressions.
- [ ] Create Tests/InMemoryLoggingTests/InMemoryLogHandlerTests.swift
- [ ] Add tests for metadata storage and retrieval across multiple log calls
- [ ] Add tests for log level filtering behavior
- [ ] Add tests for thread-safety if applicable
- [ ] Add tests demonstrating common test patterns (e.g., asserting specific messages were logged)
Add LogHandler implementation examples with integration tests
The repo has ImplementingALogHandler.md documentation but no concrete, tested reference implementations beyond the NoOpLogHandler in benchmarks. Adding reference implementations (e.g., FileLogHandler, ConsoleLogHandler with color support) with full integration tests would help contributors understand best practices and reduce barriers to creating custom handlers.
- [ ] Create Sources/Logging/ReferenceImplementations/ConsoleLogHandler.swift with proper formatting
- [ ] Create Sources/Logging/ReferenceImplementations/FileLogHandler.swift with rotation support
- [ ] Add Tests/LoggingTests/ReferenceImplementationsTests.swift with integration tests
- [ ] Document thread-safety guarantees and performance considerations in each implementation
- [ ] Add usage examples to Sources/Logging/Docs.docc/ImplementingALogHandler.md
Add benchmark comparisons between different LogHandler implementations
The Benchmarks directory has threshold files for MaxLogLevelWarning and NoTraits scenarios, but there's no benchmark comparing different handler implementations (e.g., NoOp vs Console vs File). This would help users understand performance trade-offs when choosing a handler and provide regression detection as handlers evolve.
- [ ] Create Benchmarks/HandlerComparison/Package.swift with a new benchmark suite
- [ ] Add Benchmarks/HandlerComparison/Benchmarks/HandlerComparisonBenchmarks/Comparison.swift comparing 3+ handler implementations
- [ ] Generate and commit Benchmarks/HandlerComparison/Thresholds/ baseline measurements
- [ ] Document methodology in Benchmarks/README.md explaining what the benchmarks measure
- [ ] Add GitHub Actions step in .github/workflows/main.yml to run and validate benchmark results
🌿Good first issues
- Add benchmark thresholds for additional Xcode versions (e.g., Xcode 25.x) to Benchmarks/MaxLogLevelWarning/Thresholds/ and Benchmarks/NoTraits/Thresholds/ to track compiler regression across Swift evolution
- Expand Sources/Logging/Docs.docc with a new tutorial section showing how to implement a custom LogHandler for a specific backend (e.g., file-based, network-based) with concrete, runnable code
- Add integration tests in the test suite comparing Logger behavior across different LogLevel filtering scenarios to ensure documented filtering semantics are upheld (validate against README examples)
⭐Top contributors
Click to expand
Top contributors
- @kukushechkin — 22 commits
- @rnro — 12 commits
- @FranzBusch — 8 commits
- @samuelmurray — 6 commits
- @czechboy0 — 5 commits
📝Recent commits
Click to expand
Recent commits
ac3646e— Disable nightly 6.3 WASM builds (#454) (kukushechkin)5c348a6— Cleanup repository structure (#451) (kukushechkin)deae26e— Add tests for SwiftLogNoOpLogHandler (#449) (crleonard)1fe83fb— Make dependabot set label (#448) (kukushechkin)41592e4— Bump swiftlang/github-workflows/.github/workflows/soundness.yml from 0.0.9 to 0.0.11 (#447) (dependabot[bot])83b6d96— Update dependabot to daily schedule (#446) (kukushechkin)25598b6— Improve readability by extracting separate types to their own files (#444) (samuelmurray)8ba97a9— Update documentation to reflect recent changes (#445) (samuelmurray)5073617— SLG-0003: Error parameter implementation (#425) (samuelmurray)6f3fbac— Bump swiftlang/github-workflows/.github/workflows/soundness.yml from 0.0.8 to 0.0.9 (#437) (dependabot[bot])
🔒Security observations
The apple/swift-log repository demonstrates a strong security posture. As a logging library with no external dependencies visible, it avoids supply chain risks. No hardcoded secrets, SQL injection vectors, or XSS vulnerabilities were detected in the file structure. The codebase uses modern CI/CD practices with GitHub Actions and Dependabot. Minor improvements include adding explicit security policies and strengthening dependency update enforcement. The library's focused scope (logging API) and lack of complex infrastructure or data handling further reduces attack surface.
- Low · Benchmark Thresholds Files in Version Control —
Benchmarks/*/Thresholds/. Benchmark threshold JSON files are committed to the repository. While not a direct security risk, this could potentially expose performance characteristics or implementation details that might be useful to attackers performing timing-based analysis. Fix: Consider moving benchmark threshold files to a separate configuration system or .gitignore them if they are auto-generated. - Low · Missing SECURITY.md or Security Policy —
Repository root. No visible SECURITY.md file in the repository root. This makes it unclear how to responsibly report security vulnerabilities to the maintainers. Fix: Add a SECURITY.md file with vulnerability disclosure guidelines and contact information, following GitHub's security advisory best practices. - Low · Dependabot Configuration Present —
.github/dependabot.yml, .github/workflows/. While Dependabot is configured (.github/dependabot.yml), there's no visible evidence of required status checks enforcing dependency security updates in CI/CD workflows. Fix: Ensure branch protection rules enforce passing Dependabot checks and automated dependency update reviews are in place.
LLM-derived; treat as a starting point, not a security audit.
👉Where to read next
- Open issues — current backlog
- Recent PRs — what's actively shipping
- Source on GitHub
Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.