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:
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:
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>
* add flush api to default stdout/stderr logger
motivation: default logger may not flush the streams on crush, so need to make flushing moe explicit
changes:
* add a constructor argument to control flushing behaviour, default to "everytime"
* add a "flush" method to allow user defined flush timing. this api is now internal but we could expose it if there is a need
* add tests
* fixup
* better documentation around MetadataValue being expressible by literals
Motivation:
In many examples, I could see that users seem to construct metadata
values using the explicit enum cases `.string("foo")`, `.array(...)`, as
well as `.dictionary(...)`. It's much more readable and easier to type
to just use `"foo"`, `["bar", "buz"]`, and `["qux": "quux"]` and rely on
the `ExpressibleBy...Literal` conformances.
Modifications:
Add the docs and examples.
Result:
Hopefully, users will read the docs and write more idiomatic code.
* Update Logging.swift
motivaiton: unified format
changes:
* use official docker image 🎉
* fix outstanding formatting issues
* add a call to swiftformat as part of sanity script
* fix sanity script language check debugging statements
Expose `StreamLogHandler` to the public which replaces the previously internal `StdoutLogHandlers`. Users can choose now the output stream, while `stdout` is the default.
### Motivation:
As discussed on #51 and #60
### Modifications:
Rename `StdoutLogHandler` to `StreamLogHandler` and provide 2 factory methods `standardOutput(label:)` and `standardError(label:)` for using during bootstrapping.
### Result:
Users who adopt other logging backends during `LoggingSystem` bootstrapping will still be able to use the default log handler to get very basic console output to their choice of `stdout` or `stderr`.
### Example:
```
// Log to both stderr and stdout for good measure
LoggingSystem.bootstrap {
MultiplexLogHandler([
FancyLoggingBackend(label: $0),
StreamLogHandler.standardError(label: $0),
StreamLogHandler.standardOutput(label: $0)
])
}
```
motivation: use consistent formatting
changes: update generate_linux_tests to match the formatting rules we use: `swiftformat --self insert --patternlet inline --stripunusedargs unnamed-only --comments ignore`
The original issue that was https://bugs.swift.org/browse/SR-9687 has been closed as duplicate of https://bugs.swift.org/browse/SR-9686
Perhaps it would be less confusing for others reading the code if we linked to the not-closed issue?
Not a big deal, just something I noticed; if we want to continue to link to the original issue that's fine too.
Motivation:
Logger had two ways to access the metadata:
logger[metadataKey: "foo"] = "bar"
and
logger.metadata["foo"] = "bar"
. The first one is the preferred API (as it doesn't force the
`LogHandler`s to store it in a dictionary) but the second one was still
available for cases where you need to import/export the whole metadata
storage.
Instead of exposing this as a dictionary, we should make the
'whole-metadata import/export' opaque. We're close to tagging 1.0.0
however let's design this API properly and add a sensible implementation
for 1.1.0 or so.
Moditications:
remove `Logger.metadata` property
Result:
- We can design the import/export APIs and add them when they're ready.
- the `LogHandler` API is unchanged
Motivation:
The syslog log level was unnatural in order (`.error` < `.info`) but also
didn't have `.trace` and instead the odd `.emergency` and `.alert`.
Modification:
As per https://forums.swift.org/t/logging-levels-for-swifts-server-side-logging-apis-and-new-os-log-apis/20365/56 ,
we decided to go for
trace < debug < info < notice < warning < error < critical
and also remove the integrals completely. The levels remain comparable
though.
Result:
log levels more natural
Motivation:
Correct `LogHandler` implementation is very imprortant for a working
swift-log ecosystem. Treating the `logLevel` as a value has lead to
confusion in the discussion leading to this project though.
Modification:
- add documentation on the implementation of a `LogHandler`
- move `LogHandler` to its own file
- add a unit test showcasing a global log level override
Result:
better docs
Motivation:
With the new, awesome Swift 5 `String`s, there doesn't seem to be any
point in using `StaticString`s anymore. `String` seems to use immortal
strings for literals now and is in fact 1 byte less wide than
StaticString.
Modification:
Switch all StaticString for String
Result:
better asm (slightly shorter), fewer registers burnt, more features