79 lines
2.3 KiB
Swift
79 lines
2.3 KiB
Swift
//
|
|
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Logging
|
|
|
|
// NOTE: There are two separate classes with the name Logger
|
|
// being used in this file.
|
|
@objc
|
|
public extension DebugLogger {
|
|
static func configureSwiftLogging() {
|
|
LoggingSystem.bootstrap { _ in
|
|
CLForwardingLogHandler()
|
|
}
|
|
}
|
|
|
|
// A LogHandler that forwards to CocoaLumberjack.
|
|
private struct CLForwardingLogHandler: LogHandler {
|
|
public init() {}
|
|
|
|
@inlinable
|
|
public func log(level: Logging.Logger.Level,
|
|
message: Logging.Logger.Message,
|
|
metadata: Logging.Logger.Metadata?,
|
|
file: String,
|
|
function: String,
|
|
line: UInt) {
|
|
let message = message.description
|
|
let line = Int(line)
|
|
|
|
switch level {
|
|
case .trace:
|
|
SignalCoreKit.Logger.verbose(message, file: file, function: function, line: line)
|
|
case .debug:
|
|
SignalCoreKit.Logger.debug(message, file: file, function: function, line: line)
|
|
case .info,
|
|
.notice:
|
|
SignalCoreKit.Logger.info(message, file: file, function: function, line: line)
|
|
case .warning:
|
|
SignalCoreKit.Logger.warn(message, file: file, function: function, line: line)
|
|
case .error,
|
|
.critical:
|
|
SignalCoreKit.Logger.error(message, file: file, function: function, line: line)
|
|
}
|
|
}
|
|
|
|
@inlinable
|
|
public subscript(metadataKey metadataKey: String) -> Logging.Logger.Metadata.Value? {
|
|
get {
|
|
return self.metadata[metadataKey]
|
|
}
|
|
set {
|
|
self.metadata[metadataKey] = newValue
|
|
}
|
|
}
|
|
|
|
@inlinable
|
|
public var metadata: Logging.Logger.Metadata {
|
|
get {
|
|
return [:]
|
|
}
|
|
set {}
|
|
}
|
|
|
|
@inlinable
|
|
public var logLevel: Logging.Logger.Level {
|
|
get {
|
|
#if DEBUG
|
|
return .trace
|
|
#else
|
|
return .info
|
|
#endif
|
|
}
|
|
set {}
|
|
}
|
|
}
|
|
}
|