mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Refactor class to use protocol
This commit is contained in:
parent
9b2572ba41
commit
b93e0c3547
@ -7,16 +7,26 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import os
|
import os
|
||||||
|
import OSLog
|
||||||
|
|
||||||
|
protocol LogWriter {
|
||||||
|
func log(_ message: String, withSensitiveInfo privateInfo: String?, level: OSLogType)
|
||||||
|
func logCrashAndSetFlag(error: Error)
|
||||||
|
}
|
||||||
|
|
||||||
final class Logging {
|
final class Logging {
|
||||||
|
|
||||||
private let logger: Logger
|
private let logger: Logger
|
||||||
private let subsystem = Bundle.main.bundleIdentifier!
|
private let subsystem = Bundle.main.bundleIdentifier!
|
||||||
|
|
||||||
init(for category: String) {
|
init(for category: String = "") {
|
||||||
self.logger = Logger(subsystem: subsystem, category: category)
|
self.logger = Logger(subsystem: subsystem, category: category)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Logging: LogWriter {
|
||||||
|
|
||||||
func log(
|
func log(
|
||||||
_ message: String,
|
_ message: String,
|
||||||
withSensitiveInfo privateInfo: String? = nil,
|
withSensitiveInfo privateInfo: String? = nil,
|
||||||
@ -33,7 +43,7 @@ final class Logging {
|
|||||||
let errorDescription = error.localizedDescription
|
let errorDescription = error.localizedDescription
|
||||||
UserDefaults.shared.set(true, forKey: WFDefaults.didHaveFatalError)
|
UserDefaults.shared.set(true, forKey: WFDefaults.didHaveFatalError)
|
||||||
UserDefaults.shared.set(errorDescription, forKey: WFDefaults.fatalErrorDescription)
|
UserDefaults.shared.set(errorDescription, forKey: WFDefaults.fatalErrorDescription)
|
||||||
logger.critical("\(errorDescription)")
|
logger.log(level: .error, "\(errorDescription)")
|
||||||
fatalError(errorDescription)
|
fatalError(errorDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user