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() })
```
This commit is contained in:
George Barnett authored and GitHub committed 2021-05-05 19:02:50 +09:00
1 parent 3577a992d3
commit 08ec50d7b1
1 file changed
+2
+2
View File
@@ -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? {