From 08ec50d7b14e1de96cd8d4f43db2c44691ccfd49 Mon Sep 17 00:00:00 2001 From: George Barnett Date: Wed, 5 May 2021 11:02:50 +0100 Subject: [PATCH] Add `SwiftLogNoOpLogHandler.init(_: String)` (#194) Motivation: `LogHandler` facotories are given a label as input and return a `LogHandler`. Since the no-op handler doesn't care about the label callers must provide a thunk: `{ _ in SwiftLogNoOpLogHandler() }`. That's fine but slightly more annoying to type than it needs to be. Modifications: - Add `SwiftLogNoOpLogHandler.init(_: String)` Result: Users can create a logger with the no-op handler with: ```swift Logger(label: "foo", factory: SwiftLogNoOpLogHandler.init) ``` instead of: ```swift Logger(label: "foo", factory: { _ in SwiftLogNoOpLogHandler() }) ``` --- Sources/Logging/Logging.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Logging/Logging.swift b/Sources/Logging/Logging.swift index 2bc67bc..9b27a5b 100644 --- a/Sources/Logging/Logging.swift +++ b/Sources/Logging/Logging.swift @@ -1147,6 +1147,8 @@ public struct StreamLogHandler: LogHandler { public struct SwiftLogNoOpLogHandler: LogHandler { public init() {} + public init(_: String) {} + @inlinable public func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, file: String, function: String, line: UInt) {} @inlinable public subscript(metadataKey _: String) -> Logger.Metadata.Value? {