https://github.com/apple/swift-log
A Logging API for Swift
https://github.com/apple/swift-log
logging swift-server
Last synced: 7 days ago
JSON representation
A Logging API for Swift
- Host: GitHub
- URL: https://github.com/apple/swift-log
- Owner: apple
- License: apache-2.0
- Created: 2019-02-11T18:13:17.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T10:15:58.000Z (9 months ago)
- Last Synced: 2025-05-07T15:53:48.071Z (9 months ago)
- Topics: logging, swift-server
- Language: Swift
- Homepage: https://apple.github.io/swift-log/
- Size: 814 KB
- Stars: 3,687
- Watchers: 61
- Forks: 314
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-starts - apple/swift-log - A Logging API for Swift (Swift)
- awesome-ios - swift-log
README
# 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](https://swiftpackageindex.com/apple/swift-log)
- 🚀 **Contributions** are welcome, please see [CONTRIBUTING.md](CONTRIBUTING.md)
- 🪪 **License** is Apache 2.0, repeated in [LICENSE.txt](LICENSE.txt)
- 🔒 **Security** issues should be reported via the process in [SECURITY.md](SECURITY.md)
- 🔀 **Available Logging Backends**: SwiftLog is an API package - you'll want to
choose from the many
[community-maintained logging backends](#available-log-handler-backends) for production use
## Quick Start
The following snippet shows how to add SwiftLog to your Swift Package:
```swift
// 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:
```swift
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](https://swiftpackageindex.com/search?query=swift-log)
for the `swift-log` keyword.