diff --git a/Shared/Logging/Logging.swift b/Shared/Logging/Logging.swift index b1e88a0..64d7f9c 100644 --- a/Shared/Logging/Logging.swift +++ b/Shared/Logging/Logging.swift @@ -7,16 +7,26 @@ import Foundation import os +import OSLog + +protocol LogWriter { + func log(_ message: String, withSensitiveInfo privateInfo: String?, level: OSLogType) + func logCrashAndSetFlag(error: Error) +} final class Logging { private let logger: Logger private let subsystem = Bundle.main.bundleIdentifier! - init(for category: String) { + init(for category: String = "") { self.logger = Logger(subsystem: subsystem, category: category) } +} + +extension Logging: LogWriter { + func log( _ message: String, withSensitiveInfo privateInfo: String? = nil, @@ -33,7 +43,7 @@ final class Logging { let errorDescription = error.localizedDescription UserDefaults.shared.set(true, forKey: WFDefaults.didHaveFatalError) UserDefaults.shared.set(errorDescription, forKey: WFDefaults.fatalErrorDescription) - logger.critical("\(errorDescription)") + logger.log(level: .error, "\(errorDescription)") fatalError(errorDescription) }