mirror of
https://github.com/apple/swift-log
synced 2026-11-28 04:14:20 +00:00
nest types & allow nested metadata
This commit is contained in:
1 parent
e658d61717
commit
c7ac24db1f
12 files changed
+284
-128
No files matched your search
@@ -7,7 +7,7 @@ import Logging
|
||||
|
||||
// this is a contrived example of a logging library implementation that writes logs to stdout
|
||||
public final class SimpleLogging {
|
||||
private let defaultLogLevel = LogLevel.info
|
||||
private let defaultLogLevel = Logging.Level.info
|
||||
|
||||
public init() {}
|
||||
|
||||
@@ -17,30 +17,30 @@ public final class SimpleLogging {
|
||||
|
||||
private struct Logger: LogHandler {
|
||||
private var logger: SimpleLogger
|
||||
private let defaultLogLevel: LogLevel
|
||||
private let defaultLogLevel: Logging.Level
|
||||
|
||||
public init(label: String, defaultLogLevel: LogLevel) {
|
||||
public init(label: String, defaultLogLevel: Logging.Level) {
|
||||
self.logger = SimpleLogger(label: label)
|
||||
self.defaultLogLevel = defaultLogLevel
|
||||
}
|
||||
|
||||
public func log(level: LogLevel, message: String, file _: String, function _: String, line _: UInt) {
|
||||
public func log(level: Logging.Level, message: String, file: StaticString, function: StaticString, line _: UInt) {
|
||||
self.logger.log(level: level, message: message) { text in
|
||||
print(text)
|
||||
}
|
||||
}
|
||||
|
||||
public var logLevel: LogLevel {
|
||||
public var logLevel: Logging.Level {
|
||||
get { return self.logger.logLevel ?? self.defaultLogLevel }
|
||||
set { self.logger.logLevel = newValue }
|
||||
}
|
||||
|
||||
public var metadata: LoggingMetadata? {
|
||||
public var metadata: Logging.Metadata? {
|
||||
get { return self.logger.metadata }
|
||||
set { self.logger.metadata = newValue }
|
||||
}
|
||||
|
||||
public subscript(metadataKey metadataKey: String) -> String? {
|
||||
public subscript(metadataKey metadataKey: String) -> Logging.Metadata.Value? {
|
||||
get { return self.logger[metadataKey: metadataKey] }
|
||||
set { self.logger[metadataKey: metadataKey] = newValue }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user