mirror of
https://github.com/apple/swift-log
synced 2026-11-22 03:40:39 +00:00
1895d78a91cb6c0ae8d633a2a4d91670ed5a2733
StreamLogHandler initializers public (#477)
Make `StreamLogHandler` initializers public. ### Motivation: Closes https://github.com/apple/swift-log/issues/273 ### Modifications: Promote the two stream-accepting initializers from `internal` to `public`. Also as a result, their stream parameter is spelled out as `any TextOutputStream & Sendable` rather than the internal `_SendableTextOutputStream` typealias, which cannot appear in a public signature. ~The private stored property and the internal typealias are otherwise unchanged.~ The internal typealias has been completely removed as it was only used to store the stream, and the private stored property is updated to use the spelled-out type. Also updates the docc documentation accordingly. ### Result: Users would be able to construct a `StreamLogHandler` with their own `TextOutputStream` implementation, reusing the existing logic to format log messages and prettify metadata instead of reimplementing them. --------- Signed-off-by: subhramit <subhramit.bb@live.in> Co-authored-by: Vladimir Kukushkin <kukushechkin@apple.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
- 🔀 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%