Add DocC documentation

This commit is contained in:
T. R. Bernstein
2026-02-28 01:12:28 +01:00
parent 003600ddff
commit 45ab296e9e
4 changed files with 132 additions and 2 deletions

View File

@@ -8,6 +8,22 @@ public struct LoggingOSLog: LogHandler {
public var metadataProvider: Logging.Logger.MetadataProvider?
private let oslogger: os.Logger
/**
Initializer that may be passed directly to
[LoggingSystem.bootstrap](https://swiftpackageindex.com/apple/swift-log/1.10.1/documentation/logging/loggingsystem/bootstrap(_:)).
- Parameter label: Example: com.example.sometool.MailProcessing
A reverse domain style identifier. The part up until the
last dot is used as the subsystem and the part after the
last dot is used as the category of the unified logging
message.
After the last dot spaces may be used to separate words.
If you want to use the application bundle identifier as the
subsystem, use a value without any dot and the whole value
will be mapped as the category of the unified logging system and
the subsystem is either the bundle identifier - if any - or
the string "SwiftLogToOsLog".
*/
public init(label: String) {
let lastDotPosition = label.lastIndex(of: ".") ?? label.startIndex
let frontPart = label.prefix(upTo: lastDotPosition)
@@ -20,6 +36,16 @@ public struct LoggingOSLog: LogHandler {
self.init(subsystem: String(frontPart), category: String(backPart))
}
/**
This Initializer may not be passed directly to
[LoggingSystem.bootstrap](https://swiftpackageindex.com/apple/swift-log/1.10.1/documentation/logging/loggingsystem/bootstrap(_:)).
It must be wrapped beforehand, but allows for direct assignment of subsystem and
category parameters of [OSLog](https://developer.apple.com/documentation/oslog).
- Parameters:
- subsystem: See the [Apple documentation](https://developer.apple.com/documentation/os/generating-log-messages-from-your-code#:~:text=The%20subsystem%20string,for%20each%20subsystem%20string.) for this parameter.
- category: See the [Apple documentation](https://developer.apple.com/documentation/os/generating-log-messages-from-your-code#:~:text=The%20category%20string,for%20these%20strings.) for this parameter.
*/
public init(
subsystem: String = Bundle.main.bundleIdentifier ?? "SwiftLogToOsLog",
category: String,
@@ -29,11 +55,20 @@ public struct LoggingOSLog: LogHandler {
self.logLevel = logLevel
}
/**
This Initializer may not be passed directly to
[LoggingSystem.bootstrap](https://swiftpackageindex.com/apple/swift-log/1.10.1/documentation/logging/loggingsystem/bootstrap(_:)).
Use it, when you've already a fully configured [os.Logger](https://developer.apple.com/documentation/os/logging)
instance.
*/
public init(oslog: os.Logger, logLevel: Logging.Logger.Level = .debug) {
self.oslogger = oslog
self.logLevel = logLevel
}
/**
This function is called by [SwiftLog](https://github.com/apple/swift-log).
*/
public func log(
level: Logging.Logger.Level,
message: Logging.Logger.Message,
@@ -50,6 +85,9 @@ public struct LoggingOSLog: LogHandler {
self.oslogger.log(level: OSLogType.from(loggerLevel: level), "\(message)")
}
/**
Use subscripts on struct instances, to add metadata for all future log messages.
*/
public subscript(metadataKey metadataKey: String) -> Logging.Logger.Metadata.Value? {
get {
return self.metadata[metadataKey]
@@ -72,4 +110,4 @@ public struct LoggingOSLog: LogHandler {
guard !metadata.isEmpty else { return nil }
return metadata.map { "\($0) = \($1)" }.joined(separator: separator)
}
}
}