diff --git a/Sources/TelemetryClient/LogHandler.swift b/Sources/TelemetryClient/LogHandler.swift index 43f4857..d6a855a 100644 --- a/Sources/TelemetryClient/LogHandler.swift +++ b/Sources/TelemetryClient/LogHandler.swift @@ -1,4 +1,5 @@ import Foundation +import OSLog public struct LogHandler { public enum LogLevel: Int, CustomStringConvertible { @@ -16,6 +17,17 @@ public struct LogHandler { return "ERROR" } } + + public var osLogLevel: OSLogType { + switch self { + case .debug: + return OSLogType.debug + case .info: + return OSLogType.info + case .error: + return OSLogType.error + } + } } let logLevel: LogLevel @@ -27,6 +39,16 @@ public struct LogHandler { } } + @available(iOS 14.0, macOS 11.0, watchOS 7.0, tvOS 14.0, *) + public static var oslog = { logLevel in + LogHandler(logLevel: logLevel) { level, message in + Logger( + subsystem: "TelemetryDeck", + category: "LogHandler" + ).log(level: logLevel.osLogLevel, "\(message, privacy: .public)") + } + } + public static var stdout = { logLevel in LogHandler(logLevel: logLevel) { level, message in print("[TelemetryDeck: \(level.description)] \(message)")