mirror of
https://github.com/apple/swift-log
synced 2026-11-28 04:14:20 +00:00
Compare commits
12
Commits
1.4.2
...
tomerd-patch-3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edc4555381 | ||
|
|
a7e6d7fef5 | ||
|
|
9cdea8c2af | ||
|
|
d8af258aec | ||
|
|
02770d91fc | ||
|
|
7ebe44cb03 | ||
|
|
65a8e5e921 | ||
|
|
08ec50d7b1 | ||
|
|
3577a992d3 | ||
|
|
b1d1c0372a | ||
|
|
bc049d05d0 | ||
|
|
bda2661797 |
No files matched your search
@@ -10,7 +10,7 @@ If you have a server-side Swift application, or maybe a cross-platform (for exam
|
|||||||
|
|
||||||
#### Adding the dependency
|
#### Adding the dependency
|
||||||
|
|
||||||
`SwiftLog` is designed for Swift 5, the `1.0.0` release requires Swift 5 (however we will soon tag a `0.x` version that will work with Swift 4 for the transition period). To depend on the logging API package, you need to declare your dependency in your `Package.swift`:
|
`SwiftLog` is designed for Swift 5. To depend on the logging API package, you need to declare your dependency in your `Package.swift`:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
|
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
|
||||||
@@ -82,6 +82,8 @@ As the API has just launched, not many implementations exist yet. If you are int
|
|||||||
| [crspybits/swift-log-file](https://github.com/crspybits/swift-log-file) | a simple local file logger (using `Foundation` `FileManager`) |
|
| [crspybits/swift-log-file](https://github.com/crspybits/swift-log-file) | a simple local file logger (using `Foundation` `FileManager`) |
|
||||||
| [sushichop/Puppy](https://github.com/sushichop/Puppy) | a logging backend that supports multiple transports(console, file, syslog, etc.) and has the feature with formatting and file log rotation |
|
| [sushichop/Puppy](https://github.com/sushichop/Puppy) | a logging backend that supports multiple transports(console, file, syslog, etc.) and has the feature with formatting and file log rotation |
|
||||||
| [luoxiu/LogDog](https://github.com/luoxiu/LogDog) | user-friendly logging with sinks and appenders |
|
| [luoxiu/LogDog](https://github.com/luoxiu/LogDog) | user-friendly logging with sinks and appenders |
|
||||||
|
| [ShivaHuang/swift-log-SwiftyBeaver](https://github.com/ShivaHuang/swift-log-SwiftyBeaver) | a logging backend for printing colored logging to Xcode console / file, or sending encrypted logging to [SwiftyBeaver](https://swiftybeaver.com) platform. |
|
||||||
|
| [Apodini/swift-log-elk](https://github.com/Apodini/swift-log-elk) | a logging backend that formats, caches and sends log data to [elastic/logstash](https://github.com/elastic/logstash) |
|
||||||
| Your library? | [Get in touch!](https://forums.swift.org/c/server) |
|
| Your library? | [Get in touch!](https://forums.swift.org/c/server) |
|
||||||
|
|
||||||
## What is an API package?
|
## What is an API package?
|
||||||
@@ -202,6 +204,10 @@ around between libraries to preserve metadata and the like.
|
|||||||
If you want to filter all log messages originating from a certain subsystem, filter by `source` which defaults to the module that is emitting the
|
If you want to filter all log messages originating from a certain subsystem, filter by `source` which defaults to the module that is emitting the
|
||||||
log message.
|
log message.
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
Please see [SECURITY.md](SECURITY.md) for SwiftLog's security process.
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
This logging API was designed with the contributors to the Swift on Server community and approved by the [SSWG (Swift Server Work Group)](https://swift.org/server/) to the 'sandbox level' of the SSWG's [incubation process](https://github.com/swift-server/sswg/blob/master/process/incubation.md).
|
This logging API was designed with the contributors to the Swift on Server community and approved by the [SSWG (Swift Server Work Group)](https://swift.org/server/) to the 'sandbox level' of the SSWG's [incubation process](https://github.com/swift-server/sswg/blob/master/process/incubation.md).
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
# Security
|
||||||
|
|
||||||
|
This document specifies the security process for the SwiftLog project.
|
||||||
|
|
||||||
|
## Disclosures
|
||||||
|
|
||||||
|
### Private Disclosure Process
|
||||||
|
|
||||||
|
The SwiftLog maintainers ask that known and suspected vulnerabilities be
|
||||||
|
privately and responsibly disclosed by emailing
|
||||||
|
[sswg-security-reports@forums.swift.org](mailto:sswg-security-reports@forums.swift.org)
|
||||||
|
with the all the required detail.
|
||||||
|
**Do not file a public issue.**
|
||||||
|
|
||||||
|
#### When to report a vulnerability
|
||||||
|
|
||||||
|
* You think you have discovered a potential security vulnerability in SwiftLog.
|
||||||
|
* You are unsure how a vulnerability affects SwiftLog.
|
||||||
|
|
||||||
|
#### What happens next?
|
||||||
|
|
||||||
|
* A member of the team will acknowledge receipt of the report within 3
|
||||||
|
working days (United States). This may include a request for additional
|
||||||
|
information about reproducing the vulnerability.
|
||||||
|
* We will privately inform the Swift Server Work Group ([SSWG][sswg]) of the
|
||||||
|
vulnerability within 10 days of the report as per their [security
|
||||||
|
guidelines][sswg-security].
|
||||||
|
* Once we have identified a fix we may ask you to validate it. We aim to do this
|
||||||
|
within 30 days. In some cases this may not be possible, for example when the
|
||||||
|
vulnerability exists at the protocol level and the industry must coordinate on
|
||||||
|
the disclosure process.
|
||||||
|
* If a CVE number is required, one will be requested from [MITRE][mitre]
|
||||||
|
providing you with full credit for the discovery.
|
||||||
|
* We will decide on a planned release date and let you know when it is.
|
||||||
|
* Prior to release, we will inform major dependents that a security-related
|
||||||
|
patch is impending.
|
||||||
|
* Once the fix has been released we will publish a security advisory on GitHub
|
||||||
|
and in the Server → Security Updates category on the [Swift forums][swift-forums-sec].
|
||||||
|
|
||||||
|
[sswg]: https://github.com/swift-server/sswg
|
||||||
|
[sswg-security]: https://github.com/swift-server/sswg/blob/main/security/README.md
|
||||||
|
[swift-forums-sec]: https://forums.swift.org/c/server/security-updates/
|
||||||
|
[mitre]: https://cveform.mitre.org/
|
||||||
+268
-40
@@ -49,6 +49,7 @@ public struct Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Logger {
|
extension Logger {
|
||||||
|
#if compiler(>=5.3)
|
||||||
/// Log a message passing the log level as a parameter.
|
/// 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,
|
/// 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`.
|
/// - 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.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// defaults to `#line`).
|
||||||
@inlinable
|
@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,
|
public func log(level: Logger.Level,
|
||||||
_ message: @autoclosure () -> Logger.Message,
|
_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -80,6 +99,7 @@ extension Logger {
|
|||||||
file: file, function: function, line: line)
|
file: file, function: function, line: line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Log a message passing the log level as a parameter.
|
/// 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.
|
/// - 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.
|
/// - 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func log(level: Logger.Level,
|
public func log(level: Logger.Level,
|
||||||
_ message: @autoclosure () -> Logger.Message,
|
_ message: @autoclosure () -> Logger.Message,
|
||||||
@@ -103,6 +133,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: level, message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Add, change, or remove a logging metadata item.
|
||||||
///
|
///
|
||||||
@@ -144,14 +175,26 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -159,6 +202,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .trace, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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,
|
/// If `.trace` is at least as severe as the `Logger`'s `logLevel`, it will be logged,
|
||||||
/// otherwise nothing will happen.
|
/// 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.
|
/// - 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
|
/// - 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func trace(_ message: @autoclosure () -> Logger.Message,
|
public func trace(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.trace(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.debug` log level.
|
||||||
///
|
///
|
||||||
@@ -187,21 +241,33 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// defaults to `#line`).
|
||||||
|
#if compiler(>=5.3)
|
||||||
@inlinable
|
@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,
|
public func debug(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
source: @autoclosure () -> String? = nil,
|
source: @autoclosure () -> String? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .debug, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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.
|
/// 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.
|
/// - 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.
|
/// - 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func debug(_ message: @autoclosure () -> Logger.Message,
|
public func debug(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.debug(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.info` log level.
|
||||||
///
|
///
|
||||||
@@ -232,14 +308,26 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -247,6 +335,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .info, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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.
|
/// 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.
|
/// - 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.
|
/// - 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func info(_ message: @autoclosure () -> Logger.Message,
|
public func info(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.info(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.notice` log level.
|
||||||
///
|
///
|
||||||
@@ -277,14 +376,26 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func notice(_ message: @autoclosure () -> Logger.Message,
|
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -292,6 +403,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .notice, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.notice` log level.
|
||||||
///
|
///
|
||||||
@@ -301,20 +413,31 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// defaults to `#line`).
|
||||||
|
#if compiler(>=5.3)
|
||||||
@inlinable
|
@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,
|
public func notice(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.notice(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.warning` log level.
|
||||||
///
|
///
|
||||||
@@ -324,14 +447,26 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -339,6 +474,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .warning, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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.
|
/// 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.
|
/// - 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.
|
/// - 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func warning(_ message: @autoclosure () -> Logger.Message,
|
public func warning(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.warning(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.error` log level.
|
||||||
///
|
///
|
||||||
@@ -369,14 +515,26 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -384,6 +542,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .error, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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.
|
/// 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.
|
/// - 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.
|
/// - 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func error(_ message: @autoclosure () -> Logger.Message,
|
public func error(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.error(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.critical` log level.
|
||||||
///
|
///
|
||||||
@@ -413,14 +582,26 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
@@ -428,6 +609,7 @@ extension Logger {
|
|||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.log(level: .critical, message(), metadata: metadata(), source: source(), file: file, function: function, line: 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.
|
/// Log a message passing with the `Logger.Level.critical` log level.
|
||||||
///
|
///
|
||||||
@@ -436,20 +618,32 @@ extension Logger {
|
|||||||
/// - parameters:
|
/// - parameters:
|
||||||
/// - message: The message to be logged. `message` can be used with any string interpolation literal.
|
/// - 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.
|
/// - 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
|
/// - source: The source this log messages originates from. Defaults
|
||||||
/// file that is emitting the log message, which usually is the module.
|
/// 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
|
/// - 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
|
/// - function: The function this log message originates from (there's usually no need to pass it explicitly as
|
||||||
/// it defaults to `#function`).
|
/// it defaults to `#function`).
|
||||||
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
/// - line: The line this log message originates from (there's usually no need to pass it explicitly as it
|
||||||
/// defaults to `#line`).
|
/// 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
|
@inlinable
|
||||||
public func critical(_ message: @autoclosure () -> Logger.Message,
|
public func critical(_ message: @autoclosure () -> Logger.Message,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.critical(message(), metadata: metadata(), source: nil, file: file, function: function, line: 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
|
/// 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 let flushMode: FlushMode
|
||||||
|
|
||||||
internal func write(_ string: String) {
|
internal func write(_ string: String) {
|
||||||
string.withCString { ptr in
|
self.contiguousUTF8(string).withContiguousStorageIfAvailable { utf8Bytes in
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
_lock_file(self.file)
|
_lock_file(self.file)
|
||||||
#elseif canImport(WASILibc)
|
#elseif canImport(WASILibc)
|
||||||
@@ -825,11 +1019,11 @@ internal struct StdioOutputStream: TextOutputStream {
|
|||||||
funlockfile(self.file)
|
funlockfile(self.file)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
_ = fputs(ptr, self.file)
|
_ = fwrite(utf8Bytes.baseAddress!, 1, utf8Bytes.count, self.file)
|
||||||
if case .always = self.flushMode {
|
if case .always = self.flushMode {
|
||||||
self.flush()
|
self.flush()
|
||||||
}
|
}
|
||||||
}
|
}!
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Flush the underlying stream.
|
/// Flush the underlying stream.
|
||||||
@@ -838,6 +1032,16 @@ internal struct StdioOutputStream: TextOutputStream {
|
|||||||
_ = fflush(self.file)
|
_ = 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 stderr = StdioOutputStream(file: systemStderr, flushMode: .always)
|
||||||
internal static let stdout = StdioOutputStream(file: systemStdout, 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 }))
|
: self.prettify(self.metadata.merging(metadata!, uniquingKeysWith: { _, new in new }))
|
||||||
|
|
||||||
var stream = self.stream
|
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? {
|
private func prettify(_ metadata: Logger.Metadata) -> String? {
|
||||||
@@ -928,9 +1132,19 @@ public struct StreamLogHandler: LogHandler {
|
|||||||
|
|
||||||
private func timestamp() -> String {
|
private func timestamp() -> String {
|
||||||
var buffer = [Int8](repeating: 0, count: 255)
|
var buffer = [Int8](repeating: 0, count: 255)
|
||||||
|
#if os(Windows)
|
||||||
|
var timestamp: __time64_t = __time64_t()
|
||||||
|
_ = _time64(×tamp)
|
||||||
|
|
||||||
|
var localTime: tm = tm()
|
||||||
|
_ = _localtime64_s(&localTime, ×tamp)
|
||||||
|
|
||||||
|
_ = strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", &localTime)
|
||||||
|
#else
|
||||||
var timestamp = time(nil)
|
var timestamp = time(nil)
|
||||||
let localTime = localtime(×tamp)
|
let localTime = localtime(×tamp)
|
||||||
strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
|
strftime(&buffer, buffer.count, "%Y-%m-%dT%H:%M:%S%z", localTime)
|
||||||
|
#endif
|
||||||
return buffer.withUnsafeBufferPointer {
|
return buffer.withUnsafeBufferPointer {
|
||||||
$0.withMemoryRebound(to: CChar.self) {
|
$0.withMemoryRebound(to: CChar.self) {
|
||||||
String(cString: $0.baseAddress!)
|
String(cString: $0.baseAddress!)
|
||||||
@@ -943,6 +1157,8 @@ public struct StreamLogHandler: LogHandler {
|
|||||||
public struct SwiftLogNoOpLogHandler: LogHandler {
|
public struct SwiftLogNoOpLogHandler: LogHandler {
|
||||||
public init() {}
|
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 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? {
|
@inlinable public subscript(metadataKey _: String) -> Logger.Metadata.Value? {
|
||||||
@@ -979,6 +1195,18 @@ extension Logger {
|
|||||||
String($0)
|
String($0)
|
||||||
} ?? "n/a"
|
} ?? "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
|
// Extension has to be done on explicit type rather than Logger.Metadata.Value as workaround for
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import XCTest
|
|||||||
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
|
||||||
///
|
///
|
||||||
|
|
||||||
#if os(Linux) || os(FreeBSD)
|
#if os(Linux) || os(FreeBSD) || os(Windows)
|
||||||
@testable import LoggingTests
|
@testable import LoggingTests
|
||||||
|
|
||||||
XCTMain([
|
XCTMain([
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ extension LoggingTest {
|
|||||||
("testAllLogLevelsWork", testAllLogLevelsWork),
|
("testAllLogLevelsWork", testAllLogLevelsWork),
|
||||||
("testAllLogLevelByFunctionRefWithSource", testAllLogLevelByFunctionRefWithSource),
|
("testAllLogLevelByFunctionRefWithSource", testAllLogLevelByFunctionRefWithSource),
|
||||||
("testAllLogLevelByFunctionRefWithoutSource", testAllLogLevelByFunctionRefWithoutSource),
|
("testAllLogLevelByFunctionRefWithoutSource", testAllLogLevelByFunctionRefWithoutSource),
|
||||||
|
("testLogsEmittedFromSubdirectoryGetCorrectModuleInNewerSwifts", testLogsEmittedFromSubdirectoryGetCorrectModuleInNewerSwifts),
|
||||||
("testLogMessageWithStringInterpolation", testLogMessageWithStringInterpolation),
|
("testLogMessageWithStringInterpolation", testLogMessageWithStringInterpolation),
|
||||||
("testLoggingAString", testLoggingAString),
|
("testLoggingAString", testLoggingAString),
|
||||||
("testMultiplexerIsValue", testMultiplexerIsValue),
|
("testMultiplexerIsValue", testMultiplexerIsValue),
|
||||||
@@ -51,6 +52,7 @@ extension LoggingTest {
|
|||||||
("testStreamLogHandlerOutputFormat", testStreamLogHandlerOutputFormat),
|
("testStreamLogHandlerOutputFormat", testStreamLogHandlerOutputFormat),
|
||||||
("testStreamLogHandlerOutputFormatWithMetaData", testStreamLogHandlerOutputFormatWithMetaData),
|
("testStreamLogHandlerOutputFormatWithMetaData", testStreamLogHandlerOutputFormatWithMetaData),
|
||||||
("testStreamLogHandlerOutputFormatWithOrderedMetadata", testStreamLogHandlerOutputFormatWithOrderedMetadata),
|
("testStreamLogHandlerOutputFormatWithOrderedMetadata", testStreamLogHandlerOutputFormatWithOrderedMetadata),
|
||||||
|
("testStdioOutputStreamWrite", testStdioOutputStreamWrite),
|
||||||
("testStdioOutputStreamFlush", testStdioOutputStreamFlush),
|
("testStdioOutputStreamFlush", testStdioOutputStreamFlush),
|
||||||
("testOverloadingError", testOverloadingError),
|
("testOverloadingError", testOverloadingError),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import XCTest
|
|||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
||||||
import Darwin
|
import Darwin
|
||||||
|
#elseif os(Windows)
|
||||||
|
import WinSDK
|
||||||
#else
|
#else
|
||||||
import Glibc
|
import Glibc
|
||||||
#endif
|
#endif
|
||||||
@@ -301,7 +303,7 @@ class LoggingTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func dontEvaluateThisString(file: StaticString = #file, line: UInt = #line) -> Logger.Message {
|
private func dontEvaluateThisString(file: StaticString = #file, line: UInt = #line) -> Logger.Message {
|
||||||
XCTFail("should not have been evaluated", file: (file), line: line)
|
XCTFail("should not have been evaluated", file: file, line: line)
|
||||||
return "should not have been evaluated"
|
return "should not have been evaluated"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,6 +457,15 @@ class LoggingTest: XCTestCase {
|
|||||||
let error = logger.error(_:metadata:file:function:line:)
|
let error = logger.error(_:metadata:file:function:line:)
|
||||||
let critical = logger.critical(_:metadata:file:function:line:)
|
let critical = logger.critical(_:metadata:file:function:line:)
|
||||||
|
|
||||||
|
#if compiler(>=5.3)
|
||||||
|
trace("yes: trace", [:], #fileID, #function, #line)
|
||||||
|
debug("yes: debug", [:], #fileID, #function, #line)
|
||||||
|
info("yes: info", [:], #fileID, #function, #line)
|
||||||
|
notice("yes: notice", [:], #fileID, #function, #line)
|
||||||
|
warning("yes: warning", [:], #fileID, #function, #line)
|
||||||
|
error("yes: error", [:], #fileID, #function, #line)
|
||||||
|
critical("yes: critical", [:], #fileID, #function, #line)
|
||||||
|
#else
|
||||||
trace("yes: trace", [:], #file, #function, #line)
|
trace("yes: trace", [:], #file, #function, #line)
|
||||||
debug("yes: debug", [:], #file, #function, #line)
|
debug("yes: debug", [:], #file, #function, #line)
|
||||||
info("yes: info", [:], #file, #function, #line)
|
info("yes: info", [:], #file, #function, #line)
|
||||||
@@ -462,6 +473,7 @@ class LoggingTest: XCTestCase {
|
|||||||
warning("yes: warning", [:], #file, #function, #line)
|
warning("yes: warning", [:], #file, #function, #line)
|
||||||
error("yes: error", [:], #file, #function, #line)
|
error("yes: error", [:], #file, #function, #line)
|
||||||
critical("yes: critical", [:], #file, #function, #line)
|
critical("yes: critical", [:], #file, #function, #line)
|
||||||
|
#endif
|
||||||
|
|
||||||
testLogging.history.assertExist(level: .trace, message: "yes: trace")
|
testLogging.history.assertExist(level: .trace, message: "yes: trace")
|
||||||
testLogging.history.assertExist(level: .debug, message: "yes: debug")
|
testLogging.history.assertExist(level: .debug, message: "yes: debug")
|
||||||
@@ -472,6 +484,30 @@ class LoggingTest: XCTestCase {
|
|||||||
testLogging.history.assertExist(level: .critical, message: "yes: critical")
|
testLogging.history.assertExist(level: .critical, message: "yes: critical")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testLogsEmittedFromSubdirectoryGetCorrectModuleInNewerSwifts() {
|
||||||
|
let testLogging = TestLogging()
|
||||||
|
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||||
|
|
||||||
|
var logger = Logger(label: "\(#function)")
|
||||||
|
logger.logLevel = .trace
|
||||||
|
|
||||||
|
emitLogMessage("hello", to: logger)
|
||||||
|
|
||||||
|
#if compiler(>=5.3)
|
||||||
|
let moduleName = "LoggingTests" // the actual name
|
||||||
|
#else
|
||||||
|
let moduleName = "SubDirectoryOfLoggingTests" // the last path component of `#file` showing the failure mode
|
||||||
|
#endif
|
||||||
|
|
||||||
|
testLogging.history.assertExist(level: .trace, message: "hello", source: moduleName)
|
||||||
|
testLogging.history.assertExist(level: .debug, message: "hello", source: moduleName)
|
||||||
|
testLogging.history.assertExist(level: .info, message: "hello", source: moduleName)
|
||||||
|
testLogging.history.assertExist(level: .notice, message: "hello", source: moduleName)
|
||||||
|
testLogging.history.assertExist(level: .warning, message: "hello", source: moduleName)
|
||||||
|
testLogging.history.assertExist(level: .error, message: "hello", source: moduleName)
|
||||||
|
testLogging.history.assertExist(level: .critical, message: "hello", source: moduleName)
|
||||||
|
}
|
||||||
|
|
||||||
func testLogMessageWithStringInterpolation() {
|
func testLogMessageWithStringInterpolation() {
|
||||||
let testLogging = TestLogging()
|
let testLogging = TestLogging()
|
||||||
LoggingSystem.bootstrapInternal(testLogging.make)
|
LoggingSystem.bootstrapInternal(testLogging.make)
|
||||||
@@ -669,12 +705,13 @@ class LoggingTest: XCTestCase {
|
|||||||
LoggingSystem.bootstrapInternal { _ in
|
LoggingSystem.bootstrapInternal { _ in
|
||||||
StreamLogHandler(label: label, stream: interceptStream)
|
StreamLogHandler(label: label, stream: interceptStream)
|
||||||
}
|
}
|
||||||
|
let source = "testSource"
|
||||||
let log = Logger(label: label)
|
let log = Logger(label: label)
|
||||||
|
|
||||||
let testString = "my message is better than yours"
|
let testString = "my message is better than yours"
|
||||||
log.critical("\(testString)")
|
log.critical("\(testString)", source: source)
|
||||||
|
|
||||||
let pattern = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\+|-)\\d{4}\\s\(Logger.Level.critical)\\s\(label)\\s:\\s\(testString)$"
|
let pattern = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\+|-)\\d{4}\\s\(Logger.Level.critical)\\s\(label)\\s:\\s\\[\(source)\\]\\s\(testString)$"
|
||||||
|
|
||||||
let messageSucceeded = interceptStream.interceptedText?.trimmingCharacters(in: .whitespacesAndNewlines).range(of: pattern, options: .regularExpression) != nil
|
let messageSucceeded = interceptStream.interceptedText?.trimmingCharacters(in: .whitespacesAndNewlines).range(of: pattern, options: .regularExpression) != nil
|
||||||
|
|
||||||
@@ -688,12 +725,13 @@ class LoggingTest: XCTestCase {
|
|||||||
LoggingSystem.bootstrapInternal { _ in
|
LoggingSystem.bootstrapInternal { _ in
|
||||||
StreamLogHandler(label: label, stream: interceptStream)
|
StreamLogHandler(label: label, stream: interceptStream)
|
||||||
}
|
}
|
||||||
|
let source = "testSource"
|
||||||
let log = Logger(label: label)
|
let log = Logger(label: label)
|
||||||
|
|
||||||
let testString = "my message is better than yours"
|
let testString = "my message is better than yours"
|
||||||
log.critical("\(testString)", metadata: ["test": "test"])
|
log.critical("\(testString)", metadata: ["test": "test"], source: source)
|
||||||
|
|
||||||
let pattern = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\+|-)\\d{4}\\s\(Logger.Level.critical)\\s\(label)\\s:\\stest=test\\s\(testString)$"
|
let pattern = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\+|-)\\d{4}\\s\(Logger.Level.critical)\\s\(label)\\s:\\stest=test\\s\\[\(source)\\]\\s\(testString)$"
|
||||||
|
|
||||||
let messageSucceeded = interceptStream.interceptedText?.trimmingCharacters(in: .whitespacesAndNewlines).range(of: pattern, options: .regularExpression) != nil
|
let messageSucceeded = interceptStream.interceptedText?.trimmingCharacters(in: .whitespacesAndNewlines).range(of: pattern, options: .regularExpression) != nil
|
||||||
|
|
||||||
@@ -723,6 +761,22 @@ class LoggingTest: XCTestCase {
|
|||||||
XCTAssert(interceptStream.strings[1].contains("a=a1 b=b1"))
|
XCTAssert(interceptStream.strings[1].contains("a=a1 b=b1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testStdioOutputStreamWrite() {
|
||||||
|
self.withWriteReadFDsAndReadBuffer { writeFD, readFD, readBuffer in
|
||||||
|
let logStream = StdioOutputStream(file: writeFD, flushMode: .always)
|
||||||
|
LoggingSystem.bootstrapInternal { StreamLogHandler(label: $0, stream: logStream) }
|
||||||
|
let log = Logger(label: "test")
|
||||||
|
let testString = "hello\u{0} world"
|
||||||
|
log.critical("\(testString)")
|
||||||
|
|
||||||
|
let size = read(readFD, readBuffer, 256)
|
||||||
|
|
||||||
|
let output = String(decoding: UnsafeRawBufferPointer(start: UnsafeRawPointer(readBuffer), count: numericCast(size)), as: UTF8.self)
|
||||||
|
let messageSucceeded = output.trimmingCharacters(in: .whitespacesAndNewlines).hasSuffix(testString)
|
||||||
|
XCTAssertTrue(messageSucceeded)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testStdioOutputStreamFlush() {
|
func testStdioOutputStreamFlush() {
|
||||||
// flush on every statement
|
// flush on every statement
|
||||||
self.withWriteReadFDsAndReadBuffer { writeFD, readFD, readBuffer in
|
self.withWriteReadFDsAndReadBuffer { writeFD, readFD, readBuffer in
|
||||||
@@ -754,10 +808,17 @@ class LoggingTest: XCTestCase {
|
|||||||
|
|
||||||
func withWriteReadFDsAndReadBuffer(_ body: (UnsafeMutablePointer<FILE>, CInt, UnsafeMutablePointer<Int8>) -> Void) {
|
func withWriteReadFDsAndReadBuffer(_ body: (UnsafeMutablePointer<FILE>, CInt, UnsafeMutablePointer<Int8>) -> Void) {
|
||||||
var fds: [Int32] = [-1, -1]
|
var fds: [Int32] = [-1, -1]
|
||||||
|
#if os(Windows)
|
||||||
|
fds.withUnsafeMutableBufferPointer {
|
||||||
|
let err = _pipe($0.baseAddress, 256, _O_BINARY)
|
||||||
|
XCTAssertEqual(err, 0, "_pipe failed \(err)")
|
||||||
|
}
|
||||||
|
#else
|
||||||
fds.withUnsafeMutableBufferPointer { ptr in
|
fds.withUnsafeMutableBufferPointer { ptr in
|
||||||
let err = pipe(ptr.baseAddress!)
|
let err = pipe(ptr.baseAddress!)
|
||||||
XCTAssertEqual(err, 0, "pipe faild \(err)")
|
XCTAssertEqual(err, 0, "pipe failed \(err)")
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
let writeFD = fdopen(fds[1], "w")
|
let writeFD = fdopen(fds[1], "w")
|
||||||
let writeBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: 256)
|
let writeBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: 256)
|
||||||
@@ -767,11 +828,20 @@ class LoggingTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err = setvbuf(writeFD, writeBuffer, _IOFBF, 256)
|
var err = setvbuf(writeFD, writeBuffer, _IOFBF, 256)
|
||||||
XCTAssertEqual(err, 0, "setvbuf faild \(err)")
|
XCTAssertEqual(err, 0, "setvbuf failed \(err)")
|
||||||
|
|
||||||
let readFD = fds[0]
|
let readFD = fds[0]
|
||||||
|
#if os(Windows)
|
||||||
|
let hPipe: HANDLE = HANDLE(bitPattern: _get_osfhandle(readFD))!
|
||||||
|
XCTAssertFalse(hPipe == INVALID_HANDLE_VALUE)
|
||||||
|
|
||||||
|
var dwMode: DWORD = DWORD(PIPE_NOWAIT)
|
||||||
|
let bSucceeded = SetNamedPipeHandleState(hPipe, &dwMode, nil, nil)
|
||||||
|
XCTAssertTrue(bSucceeded)
|
||||||
|
#else
|
||||||
err = fcntl(readFD, F_SETFL, fcntl(readFD, F_GETFL) | O_NONBLOCK)
|
err = fcntl(readFD, F_SETFL, fcntl(readFD, F_GETFL) | O_NONBLOCK)
|
||||||
XCTAssertEqual(err, 0, "fcntl faild \(err)")
|
XCTAssertEqual(err, 0, "fcntl failed \(err)")
|
||||||
|
#endif
|
||||||
|
|
||||||
let readBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: 256)
|
let readBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: 256)
|
||||||
defer {
|
defer {
|
||||||
@@ -804,9 +874,18 @@ class LoggingTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Logger {
|
extension Logger {
|
||||||
|
#if compiler(>=5.3)
|
||||||
|
public func error(error: Error,
|
||||||
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
|
file: String = #fileID, function: String = #function, line: UInt = #line) {
|
||||||
|
self.error("\(error.localizedDescription)", metadata: metadata(), file: file, function: function, line: line)
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
public func error(error: Error,
|
public func error(error: Error,
|
||||||
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
metadata: @autoclosure () -> Logger.Metadata? = nil,
|
||||||
file: String = #file, function: String = #function, line: UInt = #line) {
|
file: String = #file, function: String = #function, line: UInt = #line) {
|
||||||
self.error("\(error.localizedDescription)", metadata: metadata(), file: file, function: function, line: line)
|
self.error("\(error.localizedDescription)", metadata: metadata(), file: file, function: function, line: line)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This source file is part of the Swift Logging API open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2021 Apple Inc. and the Swift Logging API project authors
|
||||||
|
// Licensed under Apache License v2.0
|
||||||
|
//
|
||||||
|
// See LICENSE.txt for license information
|
||||||
|
// See CONTRIBUTORS.txt for the list of Swift Logging API project authors
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
import Logging
|
||||||
|
|
||||||
|
internal func emitLogMessage(_ message: Logger.Message, to logger: Logger) {
|
||||||
|
logger.trace(message)
|
||||||
|
logger.debug(message)
|
||||||
|
logger.info(message)
|
||||||
|
logger.notice(message)
|
||||||
|
logger.warning(message)
|
||||||
|
logger.error(message)
|
||||||
|
logger.critical(message)
|
||||||
|
}
|
||||||
@@ -14,6 +14,9 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
@testable import Logging
|
@testable import Logging
|
||||||
import XCTest
|
import XCTest
|
||||||
|
#if os(Windows)
|
||||||
|
import WinSDK
|
||||||
|
#endif
|
||||||
|
|
||||||
internal struct TestLogging {
|
internal struct TestLogging {
|
||||||
private let _config = Config() // shared among loggers
|
private let _config = Config() // shared among loggers
|
||||||
@@ -174,6 +177,34 @@ internal struct LogEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension History {
|
extension History {
|
||||||
|
#if compiler(>=5.3)
|
||||||
|
func assertExist(level: Logger.Level,
|
||||||
|
message: String,
|
||||||
|
metadata: Logger.Metadata? = nil,
|
||||||
|
source: String? = nil,
|
||||||
|
file: StaticString = #file,
|
||||||
|
fileID: String = #fileID,
|
||||||
|
line: UInt = #line) {
|
||||||
|
let source = source ?? Logger.currentModule(fileID: "\(fileID)")
|
||||||
|
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
||||||
|
XCTAssertNotNil(entry, "entry not found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
||||||
|
file: file, line: line)
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertNotExist(level: Logger.Level,
|
||||||
|
message: String,
|
||||||
|
metadata: Logger.Metadata? = nil,
|
||||||
|
source: String? = nil,
|
||||||
|
file: StaticString = #file,
|
||||||
|
fileID: String = #file,
|
||||||
|
line: UInt = #line) {
|
||||||
|
let source = source ?? Logger.currentModule(fileID: "\(fileID)")
|
||||||
|
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
||||||
|
XCTAssertNil(entry, "entry was found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
||||||
|
file: file, line: line)
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
func assertExist(level: Logger.Level,
|
func assertExist(level: Logger.Level,
|
||||||
message: String,
|
message: String,
|
||||||
metadata: Logger.Metadata? = nil,
|
metadata: Logger.Metadata? = nil,
|
||||||
@@ -183,7 +214,7 @@ extension History {
|
|||||||
let source = source ?? Logger.currentModule(filePath: "\(file)")
|
let source = source ?? Logger.currentModule(filePath: "\(file)")
|
||||||
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
||||||
XCTAssertNotNil(entry, "entry not found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
XCTAssertNotNil(entry, "entry not found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
||||||
file: (file), line: line)
|
file: file, line: line)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertNotExist(level: Logger.Level,
|
func assertNotExist(level: Logger.Level,
|
||||||
@@ -195,8 +226,9 @@ extension History {
|
|||||||
let source = source ?? Logger.currentModule(filePath: "\(file)")
|
let source = source ?? Logger.currentModule(filePath: "\(file)")
|
||||||
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
let entry = self.find(level: level, message: message, metadata: metadata, source: source)
|
||||||
XCTAssertNil(entry, "entry was found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
XCTAssertNil(entry, "entry was found: \(level), \(source), \(String(describing: metadata)), \(message)",
|
||||||
file: (file), line: line)
|
file: file, line: line)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
func find(level: Logger.Level, message: String, metadata: Logger.Metadata? = nil, source: String) -> LogEntry? {
|
func find(level: Logger.Level, message: String, metadata: Logger.Metadata? = nil, source: String) -> LogEntry? {
|
||||||
return self.entries.first { entry in
|
return self.entries.first { entry in
|
||||||
@@ -270,6 +302,8 @@ public class MDC {
|
|||||||
private var threadId: Int {
|
private var threadId: Int {
|
||||||
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
||||||
return Int(pthread_mach_thread_np(pthread_self()))
|
return Int(pthread_mach_thread_np(pthread_self()))
|
||||||
|
#elseif os(Windows)
|
||||||
|
return Int(GetCurrentThreadId())
|
||||||
#else
|
#else
|
||||||
return Int(pthread_self())
|
return Int(pthread_self())
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+2
-3
@@ -18,10 +18,9 @@ RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools
|
|||||||
|
|
||||||
# ruby and jazzy for docs generation
|
# ruby and jazzy for docs generation
|
||||||
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev build-essential
|
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev build-essential
|
||||||
# switch of gem docs building
|
|
||||||
RUN echo "gem: --no-document" > ~/.gemrc
|
|
||||||
# jazzy no longer works on xenial as ruby is too old.
|
# jazzy no longer works on xenial as ruby is too old.
|
||||||
RUN if [ "${ubuntu_version}" != "xenial" ] ; then gem install jazzy; fi
|
RUN if [ "${ubuntu_version}" = "focal" ] ; then echo "gem: --no-document" > ~/.gemrc; fi
|
||||||
|
RUN if [ "${ubuntu_version}" = "focal" ] ; then gem install jazzy; fi
|
||||||
|
|
||||||
# tools
|
# tools
|
||||||
RUN mkdir -p $HOME/.tools
|
RUN mkdir -p $HOME/.tools
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ services:
|
|||||||
image: swift-log:20.04-5.4
|
image: swift-log:20.04-5.4
|
||||||
build:
|
build:
|
||||||
args:
|
args:
|
||||||
base_image: "swiftlang/swift:nightly-5.4-focal"
|
ubuntu_version: "focal"
|
||||||
|
swift_version: "5.4"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
image: swift-log:20.04-5.4
|
image: swift-log:20.04-5.4
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ def createLinuxMain(testsDirectory, allTestSubDirectories, files)
|
|||||||
file.write header(fileName)
|
file.write header(fileName)
|
||||||
file.write "\n"
|
file.write "\n"
|
||||||
|
|
||||||
file.write "#if os(Linux) || os(FreeBSD)\n"
|
file.write "#if os(Linux) || os(FreeBSD) || os(Windows)\n"
|
||||||
for testSubDirectory in allTestSubDirectories.sort { |x, y| x <=> y }
|
for testSubDirectory in allTestSubDirectories.sort { |x, y| x <=> y }
|
||||||
file.write '@testable import ' + testSubDirectory + "\n"
|
file.write '@testable import ' + testSubDirectory + "\n"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user