mirror of
https://github.com/apple/swift-log
synced 2026-11-22 03:40:39 +00:00
Unify repos layout across the ecosystem: 1. Remove `CONTRIBUTORS.md` and mentions of it. 2. Remove `CODE_OF_CONDUCT.md` and mentions of it. 3. From `CONTRIBUTING.md` remove "Writing a Patch" and "Commit Message Template" sections. 4. Remove `.mailmap` and mentions of it. 5. Remove `dev/git.commit.template` and mentions of it. 6. Remove `SECURITY.md`, if it is referenced somewhere, change it to reference to the org security file "https://github.com/apple/swift-log?tab=security-ov-file". 7. Remove copyright header from `Package.swift` and version-specific package manifests. 8. Add SPI shields to the `README.md`. 9. Add "How to contribute your work" section in `CONTRIBUTING.md`. 10. Add "Add Automated release process" section in `CONTRIBUTING.md`.
2.6 KiB
2.6 KiB
SwiftLog
This repository contains a logging API implementation for Swift. SwiftLog provides a unified, performant, and ergonomic logging API that can be adopted by libraries and applications across the Swift ecosystem.
- 📚 Documentation and tutorials are available on the Swift Package Index
- 🚀 Contributions are welcome, please see CONTRIBUTING.md
- 🪪 License is Apache 2.0, repeated in LICENSE.txt
- 🔒 Security issues should be reported via the process in Security
- 🔀 Available Logging Backends: SwiftLog is an API package - you'll want to choose from the many community-maintained logging backends for production use
Quick Start
The following snippet shows how to add SwiftLog to your Swift Package:
// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "YourApp",
dependencies: [
.package(url: "https://github.com/apple/swift-log", from: "1.6.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "Logging", package: "swift-log")
]
)
]
)
Then start logging:
import Logging
// Create a logger
let logger = Logger(label: "com.example.YourApp")
// Log at different levels
logger.info("Application started")
logger.warning("This is a warning")
logger.error("Something went wrong", metadata: ["error": "\(error)"])
// Add metadata for context
var requestLogger = logger
requestLogger[metadataKey: "request-id"] = "\(UUID())"
requestLogger.info("Processing request")
Available log handler backends
The community has built numerous specialized logging backends.
A great way to discover available log backend implementations is searching the
Swift Package Index
for the swift-log keyword.