mirror of
https://github.com/apple/swift-log
synced 2026-11-27 04:14:20 +00:00
8ba97a9cf5614fbbe0bfd7756f68a0851a8a9403
Update documentation to reflect recent changes ### Motivation: The documentation was not updated in SLG-0003 or SLG-0005. Concretely, the examples given in the documentation used the now deprecated multiparameter methods in `LogHandler`, and the new `LogEvent`-based method were not listed among the others. Likewise, the new logging methods (`Logger.trace` etc.) that take an `Error` as a parameter were not added. Lastly, `LogEvent` had no separate entry. While the default rendered docs for these were acceptable, it decreased the discoverability of the new methods, and the examples using deprecated methods were misleading. ### Modifications: * Update all code examples to use non-deprecated methods. * List all new methods on `Logger` and `LogHandler` along the existing ones. * Add a minimal file for `LogEvent` to give it the same look as all other types. * Update code examples in `.md` files to follow swift format. ### Result: Documentation reflects the current state and best practices of `swift-log`. --------- Co-authored-by: Joseph Heck <j_heck@apple.com> Co-authored-by: Vladimir Kukushkin <kukushechkin@mac.com>
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.md
- 🔀 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.
Description
Mirror of github.com/apple/swift-log
3.3 MiB
0 Stars
1 Watchers
0 Forks
Languages
Swift
97.5%
CMake
2.5%