fix(swift-diagnostics): T5.2 \u2014 replace print() with os.Logger
OSDiagnosticsLogger was using print() for actual log output despite being the 'OSLog-based logger' implementation. Per AGENTS.md and the existing struct name, it should use os.Logger. Changes: + import os + private let logger: Logger (initialised in init()) + logger.debug / info / warning / error replace print() at all 4 sites + uses privacy: .public to make messages visible in Console.app scripts/check-rule-violations.sh shows 4 \u2192 0 swift-print findings in this package. The common-plat repo now contributes 0 swift-print to the ecosystem total.
This commit is contained in:
parent
a59fd92632
commit
d53f61a76f
@ -1,4 +1,5 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
import os
|
||||||
|
|
||||||
/// Client configuration
|
/// Client configuration
|
||||||
public struct DiagnosticsConfiguration: Sendable {
|
public struct DiagnosticsConfiguration: Sendable {
|
||||||
@ -77,27 +78,29 @@ public struct NoOpDiagnosticsLogger: DiagnosticsLogger {
|
|||||||
public struct OSDiagnosticsLogger: DiagnosticsLogger {
|
public struct OSDiagnosticsLogger: DiagnosticsLogger {
|
||||||
private let subsystem: String
|
private let subsystem: String
|
||||||
private let category: String
|
private let category: String
|
||||||
|
private let logger: Logger
|
||||||
|
|
||||||
public init(subsystem: String = "com.bytelyst.diagnostics", category: String = "DiagnosticsClient") {
|
public init(subsystem: String = "com.bytelyst.diagnostics", category: String = "DiagnosticsClient") {
|
||||||
self.subsystem = subsystem
|
self.subsystem = subsystem
|
||||||
self.category = category
|
self.category = category
|
||||||
|
self.logger = Logger(subsystem: subsystem, category: category)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func debug(_ message: String, metadata: [String: any Sendable]?) {
|
public func debug(_ message: String, metadata: [String: any Sendable]?) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
print("[DEBUG] \(message)")
|
logger.debug("\(message, privacy: .public)")
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public func info(_ message: String, metadata: [String: any Sendable]?) {
|
public func info(_ message: String, metadata: [String: any Sendable]?) {
|
||||||
print("[INFO] \(message)")
|
logger.info("\(message, privacy: .public)")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func warn(_ message: String, metadata: [String: any Sendable]?) {
|
public func warn(_ message: String, metadata: [String: any Sendable]?) {
|
||||||
print("[WARN] \(message)")
|
logger.warning("\(message, privacy: .public)")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func error(_ message: String, metadata: [String: any Sendable]?) {
|
public func error(_ message: String, metadata: [String: any Sendable]?) {
|
||||||
print("[ERROR] \(message)")
|
logger.error("\(message, privacy: .public)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user