This adds support for running the tests on Windows. However, running
the tests on Windows requires SPM currently. While it is possible to
enable executing tests with CMake, the expectation is that SPM builds
would be the most common and CMake is largely used for bootstrapping.
The changes here require alterations to remove the POSIX threading to
get the thread ID. Additionally, pipes on Windows are not similar to
pipes on Unix platforms. Finally, we must add Windows to the platform
list, which is temporary (it would be better to use test discovery in
SPM).
Windows recommends the safety extension usage which in this case
explicitly allow you to be informed of failures. This just avoids an
annoying warning when using logging in projects.
Motivation:
`LogHandler` facotories are given a label as input and return a
`LogHandler`. Since the no-op handler doesn't care about the label
callers must provide a thunk: `{ _ in SwiftLogNoOpLogHandler() }`.
That's fine but slightly more annoying to type than it needs to be.
Modifications:
- Add `SwiftLogNoOpLogHandler.init(_: String)`
Result:
Users can create a logger with the no-op handler with:
```swift
Logger(label: "foo", factory: SwiftLogNoOpLogHandler.init)
```
instead of:
```swift
Logger(label: "foo", factory: { _ in SwiftLogNoOpLogHandler() })
```
Motivation:
Right now, we use the full path (`#file`) for the logging as well as for
parsing out the module name (which goes into `source` by default).
This has two problems:
1. The file names contain the build server's full path, ie. aren't
portable across different compiles (and are very long).
2. The module name parsing fails if we log from a file that's not in a
directory named just like the module.
Modification:
Switch `#file` for `#fileID`. This changes a bunch of things:
- `source` is always the module name by default (great!)
- `file` changes from `/the/full/path/on/disk` to `ModuleName/FileBaseName.swift` (I think better, but it's a change)
Result:
`source` is more correct, `file` will be different.
Replaced `fputs` with `fwrite`, added test and made spelling corrections
Motivation:
If a 0 byte is logged, `fputs` would not output the content after the 0 byte making it harder to debug (see #180). `fwrite` uses a count argument so content after 0 byte can be logged.
Modifications:
Replaced `fputs` with the correct call to `fwrite`. Added helper internal func `contiguousUTF8(_ string: String) -> String.UTF8View`. Added `testStdioOutputStreamWrite()` to test ability to log content after 0 byte.
Result:
Improved debugging experience
Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Motivation:
When using the same Logger across an application in combination
with the default StreamLogHandler, it may be difficult to differentiate
between logs produced by different modules. ServiceLifecycle works around
this by prepending the log message with [Lifecycle], which is what I'd like
to do StreamLogHandler by default, leveraging the source log parameter.
Modifications:
StreamLogHandler will include the source in brackets right before
the log message when writing a log.
Result:
Logs from different modules are easily differentiable when produced
using the same Logger instance.
Motivation:
When using the recently re-introduced source-less version of trace, the function parameter that reaches the underlying LogHandler is wrong.
Modifications:
Pass the function parameter to trace with source parameter.
Result:
With these changes, the function parameter that reaches the underlying LogHandler has the correct value.
Motivation:
- When `source:` was added in #135, the API was accidentally broken
despite source compatability.
Modifications:
- Add back source-less API calls which defer to the decls with source.
- Note we can't deprecate the calls we're adding back:
`log.info("some message")` refers to the implementation we're adding
back rather and would therefore require users to explicitly specify a source
to suppress the deprecation warning message.
Result:
- API is no longer broken.
Co-authored-by: Konrad `ktoso` Malawski <ktoso@apple.com>
motivation: we are not actually using symbolicate-linux-fatal in any meaningful way in CI and it's pinned to the master branch which has been removed
changes: remove symbolicate-linux-fatal fetching from Docker
Motivation:
The stream log handler doesn't print metadata in a stable order. While
swift-log is an API package and shouldn't provide all the bells and
whistles for formatting logs, it should make the default log handler
at least somewhat sensible.
Modifications:
- Sort the metadata by key when 'prettifying' it
Result:
- The stream log handler emits logs with metadata in a stable order
- Resolves#128
* =multiplex #139 more properly handle logLevel in multiplex handler
* swift 5.0 needs explicit return
* no need to loop over the settings
* =metadata MultiplexLogHandler now consistently handles metadata read/write
* Apply suggestions from code review
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: George Barnett <gbrntt@gmail.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: George Barnett <gbrntt@gmail.com>
* Update comments in Locks.swift to correctly reflect the Windows implementation and to correctly describe the operation of the `ReadWriteLock`.
* Add error messages to the preconditions on pthread function call return values. Copied from NIO's `Lock` implementation.
* In `Lock`, create the underlying mutex (where applicable) using `PTHREAD_MUTEX_ERRORCHECK`. Copied from NIO's `Lock` implementation. Performance loss is minor on Xenial, Bionic, CentOS, and AmazonLinux; no loss was measurable on Focal at all.
* On Windows, correctly set the `shared` flag in `ReadWriteLock` so the correct `ReleaseSRWLock*()` function is called in `unlock()`. It appears that in practice Windows does not actually care whether the correct release function is called for the type of lock the thread was holding, but this is undocumented (along with most other semantics of `SRWLOCK`) and thus can not be relied upon.
* Fix formatting (that's what I get for copy-pasting from NIO verbatim)
Motivation:
Swift 5.3 will keep `#file` == `#filePath` but starts warning if you
pass `#file` to an argument that's `#filePath` defaulted (XCTest).
Modification:
- Replace `#file` with `(#file)` to silence the warning. In Swift 5.3
`#file` == `#filePath`.
Result:
No warnings
Motivation:
The current docstring seems to be missing some words that indicate
when a 'trace' log level is more appropriate than a 'debug' log
level. This was brought up in https://github.com/vapor/docs/issues/463
and has been fixed there. This PR is being submitted to the upstream
project as a courtesy.
Modifications:
This PR adds a clause to the docstring of the 'trace' log level to
clearly indicate when this log level shuld be used.
Result:
The docstring for the 'trace' log level will mirror the structure of
the docstring for the 'debug' log level, but will include a clear
opinion of when the 'trace' log level is appropriate.
Signed-off-by: zach wick <zach@zachwick.com>