mirror of
https://github.com/apple/swift-log
synced 2026-11-27 04:14:20 +00:00
Extract task-local Baggage within log function
This commit is contained in:
2 files changed
+57
-418
No files matched your search
+34
-400
@@ -56,32 +56,6 @@ public struct Logger {
|
||||
}
|
||||
|
||||
extension Logger {
|
||||
#if compiler(>=5.5)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func log(level: Logger.Level,
|
||||
_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
if self.logLevel <= level {
|
||||
let providerMetadata = self.metadataProvider?(baggage)
|
||||
let metadata: Metadata? = {
|
||||
guard let metadata = metadata(), !metadata.isEmpty else { return providerMetadata }
|
||||
guard let providerMetadata = providerMetadata else { return metadata }
|
||||
return providerMetadata.merging(metadata, uniquingKeysWith: { _, oneOffMetadata in oneOffMetadata })
|
||||
}()
|
||||
|
||||
self.handler.log(level: level,
|
||||
message: message(),
|
||||
metadata: metadata,
|
||||
source: source() ?? Logger.currentModule(fileID: (file)),
|
||||
file: file, function: function, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing the log level as a parameter.
|
||||
///
|
||||
/// If the `logLevel` passed to this method is more severe than the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -101,6 +75,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func log(level: Logger.Level,
|
||||
_ message: @autoclosure () -> Logger.Message,
|
||||
@@ -108,9 +83,26 @@ extension Logger {
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
if self.logLevel <= level {
|
||||
let baggage: Baggage?
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), self.metadataProvider != nil {
|
||||
baggage = Baggage.current
|
||||
} else {
|
||||
baggage = nil
|
||||
}
|
||||
#else
|
||||
baggage = nil
|
||||
#endif
|
||||
let providerMetadata = self.metadataProvider?(baggage)
|
||||
let metadata: Metadata? = {
|
||||
guard let metadata = metadata(), !metadata.isEmpty else { return providerMetadata }
|
||||
guard let providerMetadata = providerMetadata else { return metadata }
|
||||
return providerMetadata.merging(metadata, uniquingKeysWith: { _, oneOffMetadata in oneOffMetadata })
|
||||
}()
|
||||
|
||||
self.handler.log(level: level,
|
||||
message: message(),
|
||||
metadata: metadata(),
|
||||
metadata: metadata,
|
||||
source: source() ?? Logger.currentModule(fileID: (file)),
|
||||
file: file, function: function, line: line)
|
||||
}
|
||||
@@ -133,18 +125,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func log(level: Logger.Level,
|
||||
_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: level, message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing the log level as a parameter.
|
||||
///
|
||||
/// If the ``logLevel`` passed to this method is more severe than the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -160,6 +140,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func log(level: Logger.Level,
|
||||
_ message: @autoclosure () -> Logger.Message,
|
||||
@@ -169,21 +150,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing the log level as a parameter.
|
||||
///
|
||||
/// If the ``logLevel`` passed to this method is more severe than the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - level: The log level to log `message` at. For the available log levels, see `Logger.Level`.
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func log(level: Logger.Level,
|
||||
_ message: @autoclosure () -> Logger.Message,
|
||||
@@ -225,18 +191,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
extension Logger {
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .trace, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/trace`` log level.
|
||||
///
|
||||
/// If `.trace` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -255,6 +209,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -264,25 +219,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/trace`` log level.
|
||||
///
|
||||
/// If `.trace` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
|
||||
@inlinable
|
||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -292,16 +228,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.trace(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
/// Log a message passing with the ``Logger/Level/trace`` log level.
|
||||
///
|
||||
/// If `.trace` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -316,7 +242,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#elseif compiler(>=5.3)
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -333,17 +259,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func debug(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .debug, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
/// Log a message passing with the ``Logger/Level/debug`` log level.
|
||||
///
|
||||
/// If `.debug` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -362,7 +277,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#elseif compiler(>=5.3)
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func debug(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -380,16 +295,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func debug(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.debug(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
/// Log a message passing with the ``Logger/Level/debug`` log level.
|
||||
///
|
||||
/// If `.debug` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -404,7 +309,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#elseif compiler(>=5.3)
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func debug(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -421,18 +326,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .info, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/info`` log level.
|
||||
///
|
||||
/// If `.info` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -451,6 +344,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -460,24 +354,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/info`` log level.
|
||||
///
|
||||
/// If `.info` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -487,17 +363,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.info(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/info`` log level.
|
||||
///
|
||||
/// If `.info` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -512,6 +377,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -520,20 +386,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/info`` log level.
|
||||
///
|
||||
/// If `.info` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -542,18 +394,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .notice, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/notice`` log level.
|
||||
///
|
||||
/// If `.notice` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -572,6 +412,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -581,24 +422,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/notice`` log level.
|
||||
///
|
||||
/// If `.notice` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -608,17 +431,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.notice(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/notice`` log level.
|
||||
///
|
||||
/// If `.notice` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -637,6 +449,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -645,24 +458,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/notice`` log level.
|
||||
///
|
||||
/// If `.notice` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||
@@ -670,18 +465,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .warning, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/warning`` log level.
|
||||
///
|
||||
/// If `.warning` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -700,6 +483,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -709,24 +493,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/warning`` log level.
|
||||
///
|
||||
/// If `.warning` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -736,17 +502,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.warning(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/warning`` log level.
|
||||
///
|
||||
/// If `.warning` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -761,6 +516,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -769,20 +525,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/warning`` log level.
|
||||
///
|
||||
/// If `.warning` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -791,18 +533,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .error, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/error`` log level.
|
||||
///
|
||||
/// If `.error` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -821,6 +551,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -830,24 +561,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/error`` log level.
|
||||
///
|
||||
/// If `.error` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -857,17 +570,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.error(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/error`` log level.
|
||||
///
|
||||
/// If `.error` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
@@ -882,6 +584,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -890,20 +593,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/error`` log level.
|
||||
///
|
||||
/// If `.error` is at least as severe as the `Logger`'s ``logLevel``, it will be logged,
|
||||
/// otherwise nothing will happen.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -912,18 +601,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
source: @autoclosure () -> String? = nil,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.log(level: .critical, message(), metadata: metadata(), baggage: baggage, source: source(), file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/critical`` log level.
|
||||
///
|
||||
/// `.critical` messages will always be logged.
|
||||
@@ -941,6 +618,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -950,23 +628,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/critical`` log level.
|
||||
///
|
||||
/// `.critical` messages will always be logged.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -976,17 +637,6 @@ extension Logger {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
@inlinable
|
||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
baggage: Baggage? = .current,
|
||||
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||
self.critical(message(), metadata: metadata(), baggage: baggage, source: nil, file: file, function: function, line: line)
|
||||
}
|
||||
|
||||
#elseif compiler(>=5.3)
|
||||
/// Log a message passing with the ``Logger/Level/critical`` log level.
|
||||
///
|
||||
/// `.critical` messages will always be logged.
|
||||
@@ -1004,6 +654,7 @@ extension Logger {
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
#if compiler(>=5.3)
|
||||
@inlinable
|
||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
@@ -1012,23 +663,6 @@ extension Logger {
|
||||
}
|
||||
|
||||
#else
|
||||
/// Log a message passing with the ``Logger/Level/critical`` log level.
|
||||
///
|
||||
/// `.critical` messages will always be logged.
|
||||
///
|
||||
/// - parameters:
|
||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
||||
/// - metadata: One-off metadata to attach to this log message.
|
||||
/// - source: The source this log messages originates from. Defaults
|
||||
/// to the module emitting the log message (on Swift 5.3 or
|
||||
/// newer and the folder name containing the log emitting file on Swift 5.2 or
|
||||
/// older).
|
||||
/// - file: The file this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#fileID` (on Swift 5.3 or newer and `#file` on Swift 5.2 or older).
|
||||
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||
/// it defaults to `#function`).
|
||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||
/// defaults to `#line`).
|
||||
@inlinable
|
||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||
|
||||
@@ -418,21 +418,21 @@ class LoggingTest: XCTestCase {
|
||||
var logger = Logger(label: "\(#function)")
|
||||
logger.logLevel = .trace
|
||||
|
||||
let trace = logger.trace(_:metadata:baggage:source:file:function:line:)
|
||||
let debug = logger.debug(_:metadata:baggage:source:file:function:line:)
|
||||
let info = logger.info(_:metadata:baggage:source:file:function:line:)
|
||||
let notice = logger.notice(_:metadata:baggage:source:file:function:line:)
|
||||
let warning = logger.warning(_:metadata:baggage:source:file:function:line:)
|
||||
let error = logger.error(_:metadata:baggage:source:file:function:line:)
|
||||
let critical = logger.critical(_:metadata:baggage:source:file:function:line:)
|
||||
let trace = logger.trace(_:metadata:source:file:function:line:)
|
||||
let debug = logger.debug(_:metadata:source:file:function:line:)
|
||||
let info = logger.info(_:metadata:source:file:function:line:)
|
||||
let notice = logger.notice(_:metadata:source:file:function:line:)
|
||||
let warning = logger.warning(_:metadata:source:file:function:line:)
|
||||
let error = logger.error(_:metadata:source:file:function:line:)
|
||||
let critical = logger.critical(_:metadata:source:file:function:line:)
|
||||
|
||||
trace("yes: trace", [:], nil, "foo", #file, #function, #line)
|
||||
debug("yes: debug", [:], nil, "foo", #file, #function, #line)
|
||||
info("yes: info", [:], nil, "foo", #file, #function, #line)
|
||||
notice("yes: notice", [:], nil, "foo", #file, #function, #line)
|
||||
warning("yes: warning", [:], nil, "foo", #file, #function, #line)
|
||||
error("yes: error", [:], nil, "foo", #file, #function, #line)
|
||||
critical("yes: critical", [:], nil, "foo", #file, #function, #line)
|
||||
trace("yes: trace", [:], "foo", #file, #function, #line)
|
||||
debug("yes: debug", [:], "foo", #file, #function, #line)
|
||||
info("yes: info", [:], "foo", #file, #function, #line)
|
||||
notice("yes: notice", [:], "foo", #file, #function, #line)
|
||||
warning("yes: warning", [:], "foo", #file, #function, #line)
|
||||
error("yes: error", [:], "foo", #file, #function, #line)
|
||||
critical("yes: critical", [:], "foo", #file, #function, #line)
|
||||
|
||||
testLogging.history.assertExist(level: .trace, message: "yes: trace", source: "foo")
|
||||
testLogging.history.assertExist(level: .debug, message: "yes: debug", source: "foo")
|
||||
@@ -538,6 +538,7 @@ class LoggingTest: XCTestCase {
|
||||
testLogging.history.assertExist(level: .debug, message: "hello world!")
|
||||
}
|
||||
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
func testLoggingWithMetadataProviderMergesOneOffMetadata() throws {
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
@@ -552,7 +553,10 @@ class LoggingTest: XCTestCase {
|
||||
|
||||
var baggage = Baggage.topLevel
|
||||
baggage[TestIDKey.self] = "42"
|
||||
logger.log(level: .info, "test", metadata: ["one-off": "42"], baggage: baggage)
|
||||
|
||||
Baggage.$current.withValue(baggage) {
|
||||
logger.log(level: .info, "test", metadata: ["one-off": "42"])
|
||||
}
|
||||
|
||||
logging.history.assertExist(level: .info, message: "test", metadata: ["one-off": "42", "provider": "42"])
|
||||
|
||||
@@ -561,6 +565,7 @@ class LoggingTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
|
||||
func testLoggingWithMetadataProviderPrefersOneOffMetadataOverProviderMetadata() throws {
|
||||
let logging = TestLogging()
|
||||
LoggingSystem.bootstrapInternal(logging.make)
|
||||
@@ -572,7 +577,9 @@ class LoggingTest: XCTestCase {
|
||||
]
|
||||
})
|
||||
|
||||
logger.log(level: .info, "test", metadata: ["one-off": "42", "common": "one-off"], baggage: .topLevel)
|
||||
Baggage.$current.withValue(.topLevel) {
|
||||
logger.log(level: .info, "test", metadata: ["one-off": "42", "common": "one-off"])
|
||||
}
|
||||
|
||||
logging.history.assertExist(level: .info,
|
||||
message: "test",
|
||||
@@ -583,7 +590,6 @@ class LoggingTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=5.5) && canImport(_Concurrency)
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
func testLoggingDefaultsToTaskLocalBaggage() throws {
|
||||
let logging = TestLogging()
|
||||
@@ -622,7 +628,6 @@ class LoggingTest: XCTestCase {
|
||||
typealias Value = String
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
func testMultiplexerIsValue() {
|
||||
let multi = MultiplexLogHandler([StreamLogHandler.standardOutput(label: "x"), StreamLogHandler.standardOutput(label: "y")])
|
||||
|
||||
Reference in new issue
Block a user