|
|
|
@@ -49,6 +49,7 @@ public struct Logger {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension Logger {
|
|
|
|
|
#if 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,
|
|
|
|
@@ -58,15 +59,33 @@ extension Logger {
|
|
|
|
|
/// - 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.
|
|
|
|
|
/// - source: The source this log messages originates to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
if self.logLevel <= level {
|
|
|
|
|
self.handler.log(level: level,
|
|
|
|
|
message: message(),
|
|
|
|
|
metadata: metadata(),
|
|
|
|
|
source: source() ?? Logger.currentModule(fileID: (file)),
|
|
|
|
|
file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func log(level: Logger.Level,
|
|
|
|
|
_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -80,6 +99,7 @@ extension Logger {
|
|
|
|
|
file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing the log level as a parameter.
|
|
|
|
|
///
|
|
|
|
@@ -91,11 +111,21 @@ extension Logger {
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func log(level: Logger.Level,
|
|
|
|
|
_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: level, message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func log(level: Logger.Level,
|
|
|
|
|
_ message: @autoclosure () -> Logger.Message,
|
|
|
|
@@ -103,6 +133,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: level, message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Add, change, or remove a logging metadata item.
|
|
|
|
|
///
|
|
|
|
@@ -144,14 +175,26 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func trace(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .trace, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func trace(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -159,6 +202,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .trace, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// If `.trace` is at least as severe as the `Logger`'s `logLevel`, it will be logged,
|
|
|
|
|
/// otherwise nothing will happen.
|
|
|
|
@@ -167,17 +211,27 @@ extension Logger {
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func trace(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.trace(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func trace(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.trace(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.debug` log level.
|
|
|
|
|
///
|
|
|
|
@@ -187,21 +241,33 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func debug(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .debug, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
public func debug(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .debug, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.debug` log level.
|
|
|
|
|
///
|
|
|
|
@@ -212,17 +278,27 @@ extension Logger {
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func debug(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.debug(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func debug(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.debug(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.info` log level.
|
|
|
|
|
///
|
|
|
|
@@ -232,14 +308,26 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func info(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .info, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func info(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -247,6 +335,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .info, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.info` log level.
|
|
|
|
|
///
|
|
|
|
@@ -257,17 +346,27 @@ extension Logger {
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func info(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.info(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func info(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.info(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.notice` log level.
|
|
|
|
|
///
|
|
|
|
@@ -277,14 +376,26 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func notice(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .notice, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func notice(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -292,6 +403,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .notice, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.notice` log level.
|
|
|
|
|
///
|
|
|
|
@@ -301,20 +413,31 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func notice(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.notice(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
public func notice(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.notice(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.warning` log level.
|
|
|
|
|
///
|
|
|
|
@@ -324,14 +447,26 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func warning(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .warning, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func warning(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -339,6 +474,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .warning, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.warning` log level.
|
|
|
|
|
///
|
|
|
|
@@ -349,17 +485,27 @@ extension Logger {
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func warning(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.warning(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func warning(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.warning(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.error` log level.
|
|
|
|
|
///
|
|
|
|
@@ -369,14 +515,26 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func error(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .error, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func error(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -384,6 +542,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .error, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.error` log level.
|
|
|
|
|
///
|
|
|
|
@@ -394,17 +553,27 @@ extension Logger {
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func error(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.error(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func error(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.error(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.critical` log level.
|
|
|
|
|
///
|
|
|
|
@@ -413,14 +582,26 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func critical(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
source: @autoclosure () -> String? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .critical, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func critical(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
@@ -428,6 +609,7 @@ extension Logger {
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.log(level: .critical, message(), metadata: metadata(), source: source(), file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// Log a message passing with the `Logger.Level.critical` log level.
|
|
|
|
|
///
|
|
|
|
@@ -436,20 +618,32 @@ extension Logger {
|
|
|
|
|
/// - 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 to. Currently, it defaults to the folder containing the
|
|
|
|
|
/// file that is emitting the log message, which usually is the module.
|
|
|
|
|
/// - 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 `#file`).
|
|
|
|
|
/// 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`).
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
public func critical(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.critical(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
@inlinable
|
|
|
|
|
public func critical(_ message: @autoclosure () -> Logger.Message,
|
|
|
|
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
|
|
|
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
|
|
|
|
self.critical(message(), metadata: metadata(), source: nil, file: file, function: function, line: line)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The `LoggingSystem` is a global facility where the default logging backend implementation (`LogHandler`) can be
|
|
|
|
@@ -808,7 +1002,7 @@ internal struct StdioOutputStream: TextOutputStream {
|
|
|
|
|
internal let flushMode: FlushMode
|
|
|
|
|
|
|
|
|
|
internal func write(_ string: String) {
|
|
|
|
|
string.withCString { ptr in
|
|
|
|
|
self.contiguousUTF8(string).withContiguousStorageIfAvailable { utf8Bytes in
|
|
|
|
|
#if os(Windows)
|
|
|
|
|
_lock_file(self.file)
|
|
|
|
|
#elseif canImport(WASILibc)
|
|
|
|
@@ -825,11 +1019,11 @@ internal struct StdioOutputStream: TextOutputStream {
|
|
|
|
|
funlockfile(self.file)
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
_ = fputs(ptr, self.file)
|
|
|
|
|
_ = fwrite(utf8Bytes.baseAddress!, 1, utf8Bytes.count, self.file)
|
|
|
|
|
if case .always = self.flushMode {
|
|
|
|
|
self.flush()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Flush the underlying stream.
|
|
|
|
@@ -838,6 +1032,16 @@ internal struct StdioOutputStream: TextOutputStream {
|
|
|
|
|
_ = fflush(self.file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal func contiguousUTF8(_ string: String) -> String.UTF8View {
|
|
|
|
|
var contiguousString = string
|
|
|
|
|
#if compiler(>=5.1)
|
|
|
|
|
contiguousString.makeContiguousUTF8()
|
|
|
|
|
#else
|
|
|
|
|
contiguousString = string + ""
|
|
|
|
|
#endif
|
|
|
|
|
return contiguousString.utf8
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static let stderr = StdioOutputStream(file: systemStderr, flushMode: .always)
|
|
|
|
|
internal static let stdout = StdioOutputStream(file: systemStdout, flushMode: .always)
|
|
|
|
|
|
|
|
|
@@ -917,7 +1121,7 @@ public struct StreamLogHandler: LogHandler {
|
|
|
|
|
: self.prettify(self.metadata.merging(metadata!, uniquingKeysWith: { _, new in new }))
|
|
|
|
|
|
|
|
|
|
var stream = self.stream
|
|
|
|
|
stream.write("\(self.timestamp()) \(level) \(self.label) :\(prettyMetadata.map { " \($0)" } ?? "") \(message)\n")
|
|
|
|
|
stream.write("\(self.timestamp()) \(level) \(self.label) :\(prettyMetadata.map { " \($0)" } ?? "") [\(source)] \(message)\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func prettify(_ metadata: Logger.Metadata) -> String? {
|
|
|
|
@@ -943,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? {
|
|
|
|
@@ -979,6 +1185,18 @@ extension Logger {
|
|
|
|
|
String($0)
|
|
|
|
|
} ?? "n/a"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if compiler(>=5.3)
|
|
|
|
|
@inlinable
|
|
|
|
|
internal static func currentModule(fileID: String = #fileID) -> String {
|
|
|
|
|
let utf8All = fileID.utf8
|
|
|
|
|
if let slashIndex = utf8All.firstIndex(of: UInt8(ascii: "/")) {
|
|
|
|
|
return String(fileID[..<slashIndex])
|
|
|
|
|
} else {
|
|
|
|
|
return "n/a"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extension has to be done on explicit type rather than Logger.Metadata.Value as workaround for
|
|
|
|
|