|
|
@@ -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) |
|
|
|
} |
|
|
|
|
|
|
|