### Motivation:
`MultiplexLogHandler.metadataProvider`'s setter only forwards the new
provider to the underlying handlers. Since #522, `log(event:)` also
merges the provider passed to `init(_:metadataProvider:)` on top of the
underlying handlers' metadata, so after a set that old provider still
overrides the new one for conflicting keys, setting `nil` doesn't remove
it, and the getter keeps returning it.
This shows up through `Logger(label:metadataProvider:)`, which calls the
factory and then sets `handler.metadataProvider`. If the bootstrapped
factory returns a `MultiplexLogHandler` with its own provider, the
provider the library passed is silently overridden. With a plain handler
the same code uses the library's provider, which is what
`Logger(label:metadataProvider:)` documents ("the custom metadata
provider this logger should invoke, instead of the system wide
bootstrapped one").
### Modifications:
- In the setter, also replace the multiplex handler's own provider with
the new value. It is still forwarded to the underlying handlers as
before.
- Document the setter.
- Add regression tests: setting a provider replaces the initializer's
provider for one and two handlers, and setting `nil` clears it (both the
getter and emitted logs). Another test covers an underlying handler that
doesn't support metadata providers.
I kept forwarding to the underlying handlers and replace the multiplex
handler's own provider as well, rather than clearing it. Clearing it
would drop provider metadata for underlying handlers that use the
default `metadataProvider` implementation in the
`Logger(label:metadataProvider:)` case, which works today.
### Result:
After `handler.metadataProvider = p`, logs and the getter use `p`. After
`handler.metadataProvider = nil`, no provider metadata is added. In the
common setup where the factory passes its provider into the
`MultiplexLogHandler` initializer, the number of provider calls per log
stays the same. When the multiplex handler had no provider of its own, a
set now also applies the provider once at the multiplex level, so
underlying handlers without provider support get its metadata too.
The new tests fail on main and pass with this change. All tests pass
locally on macOS (Swift 6.3.3), and `swift format lint` is clean on the
changed files. I couldn't run the benchmarks locally.
This change was drafted with Claude Code (claude-opus-5-5); the test
results above are from the runs described.
When a module name (via `-module-alias`) is a raw identifier (SE-0451),
`#fileID` formats the module component enclosed in backticks (for
example, `` `/a/b/c`/File.swift ``). If the raw identifier contains '/',
splitting on the first '/' in `#fileID` truncates the module name at the
slash inside the backticks.
When `#fileID` starts with a backtick, advance past the matching closing
backtick before searching for the '/' separator that ends the module
name, preserving the enclosing backticks.
Fixes#498
## Problem
`MultiplexLogHandler` had inconsistent metadata priority:
- `subscript(metadataKey:)` reads the value from the **first** handler
that has the key (documented: "the first handler's values are more
important")
- `metadata` (full dictionary) merged handlers **last-wins**, so the
value came from the **last** handler with that key
## Fix
The `metadata` getter now merges handlers in their initialization order,
keeping the already-stored value on conflicts — the **first handler
wins**, matching the subscript and the docs.
The multiplex handler's own `metadataProvider` still takes priority over
all underlying handlers/providers, matching its documented role ("runs
after all metadata providers of the multiplexed handlers").
## Testing
- Updated `multiplexLogHandlerMetadata_readingHandlerMetadata` and
`multiplexMetadataProviderSet`, which encoded the last-wins behavior
- Extended `multiplexMetadataProviderSet` with subscript-vs-dictionary
consistency checks (both must give the first handler's value on
conflicting keys, including provider-provided metadata)
- Full suite: 174 tests in 17 suites, all passing
---------
Co-authored-by: awaisdev <awais@airtechsolutions.pk>
Co-authored-by: awaisdev5765 <awaisdev5765@users.noreply.github.com>
Co-authored-by: Vladimir Kukushkin <kukushechkin@apple.com>
`StreamLogHandler` timestamps only have second precision, so when
several log lines land in the same second you can't tell what order they
happened in.
This adds an **opt-in** setting for millisecond precision. The default
output doesn't change, since some users parse it.
**Changes**
- Adds `public var timestampPrecision: TimestampPrecision = .seconds` to
`StreamLogHandler`.
- Adds a nested `TimestampPrecision` enum (`@nonexhaustive`, `Sendable`)
with `.seconds` and `.milliseconds`.
- With `.milliseconds`, the timestamp includes a 3-digit millisecond
field:
- default (`.seconds`): `2021-11-06T18:47:14+0300 info myapp: message`
- `.milliseconds`: `2021-11-06T18:47:14.123+0300 info myapp: message`
- How each platform reads the time:
- Darwin, Linux and Android use `clock_gettime(CLOCK_REALTIME)`.
- Windows uses `_ftime64_s`.
- WASI only has second resolution (`CLOCK_REALTIME` isn't importable
there), so `.milliseconds` always prints `.000`. The doc comments say
so.
- Both new symbols are added to the DocC reference page.
**Tests**
- The default precision is `.seconds`.
- `.milliseconds` produces the expected format (checked with a regex).
- Milliseconds are always zero-padded to 3 digits.
- The existing output-format tests are unchanged and still pass, which
confirms the default format.
Fixes#212
Give `Logger.handler` a `_modify` accessor and replace its `get` with
`_read`, so metadata writes update the stored handler instead of a copy.
### Motivation:
`Logger.handler` only has `get` and `set`. A write such as
`logger[metadataKey: "k"] = "v"` gets a copy of the handler, writes to
it while the stored handler still shares the metadata dictionary, and
sets it back. So every write copies the whole dictionary, and
`withLogger(mergingMetadata:)` does that once per key.
### Modifications:
- Give `Logger.handler` `_read`, `set` and `_modify` accessors. `_read`
yields the stored handler. `_modify` keeps the existing uniqueness check
on the storage and then yields the stored handler, so metadata and log
level writes change it in place. `set` keeps the same check for plain
`logger.handler = newHandler` assignments, which are cheaper through a
setter than through `_modify`.
- Add a test handler that counts copies of its metadata, with tests for
direct writes and for `withLogger(mergingMetadata:)`. Without the change
they report 10 copies instead of 0, and 5 instead of 1.
### Result:
A metadata write on a logger that owns its storage no longer copies the
dictionary. A copied logger still copies once on its first write, so
value semantics are unchanged.
1,000 metadata writes with a handler that keeps metadata in a plain
dictionary, debug build, three runs each:
| Keys on the logger | Before | After |
|---|---|---|
| 10 | 7.2 to 8.1 ms | 0.46 to 0.50 ms |
| 1,000 | 20.2 to 20.6 ms | 0.46 to 0.55 ms |
| 10,000 | 134.0 to 134.4 ms | 0.47 to 0.50 ms |
| 100,000 | 1.29 to 1.30 s | 0.32 to 0.35 ms |
`withLogger(mergingMetadata:)` with 10,000 keys went from 0.64 to 0.65 s
down to 2.9 to 3.1 ms. `StreamLogHandler` still rebuilds its pretty
metadata string on every write; this change does not touch that.
All 176 tests pass on macOS with Swift 6.4, and `swift format lint
--strict` and `swift package diagnose-api-breaking-changes` are clean.
Once yielding accessors land, `_read` and `_modify` can become `yielding
borrow` and `yielding mutate`.
Fixes#526.
Ensure metadata from the multiplex handler’s own provider reaches
emitted logs.
Fixes#521.
## Motivation
`MultiplexLogHandler` accepts a metadata provider in its initializer,
but `log(event:)` never invokes it. Provider values such as trace IDs
are therefore missing from downstream logs.
## Modifications
- Merge the multiplex provider’s metadata into the event before
forwarding it.
- Preserve explicit per-message metadata overrides.
- Add regression tests covering one and two downstream handlers and
metadata precedence.
## Result
The supplied provider’s metadata is included in emitted logs.
Regression tests fail before the fix and pass afterward. All 174 tests
pass on macOS with Swift 6.4. Formatting and `git diff --check` also
pass.
Fixes#519.
## Motivation
When both `logLevel` and `handler` are provided, `withLogger` sets the
level on the current handler before replacing it. Since
`Logger.logLevel` forwards to the handler, the replacement discards the
requested level and uses its own instead.
## Modifications
- Install the replacement handler before applying the explicit log level
in both sync and async overloads.
- Add regression tests for `.debug` and `.warning` in both overloads,
covering filtering and scope isolation.
## Result
The scoped logger filters messages at the requested level.
Regression tests fail before the fix and pass afterward. All 172 tests
pass on macOS with Swift 6.4. Formatting and `git diff --check` also
pass.
Only quote leaf metadata values.
### Motivation:
There are several issues with how nested `MetadataValue`s are handled:
1. For highly nested (10k+) metadata, `.description` and `==` operator
hit stack overflow. This is probably not very realistic depth, but
still.
2. For not so highly nested metadata (starting at about 20)
`.description` and `==` operator get very computationally intensive
because of re-escaping of the already escaped children. This makes the
above stack overflow crash not reachable in practice.
3. This also results in simple structured metadata to be rendered
something like
`["[\"[\\\"[\\\\\\\"[\\\\\\\\\\\\\\\"leaf\\\\\\\\\\\\\\\"]\\\\\\\"]\\\"]\"]"]`.
4. Finally, even after solving the re-quoting and stack over flow on
rendering, there is still an issue of [recursion in
`.deinit`](https://github.com/swiftlang/swift/issues/58080), resulting
in a _different_ stack overflow crash.
This PR provides a fix for 2 and 3, leaving 1 and 4 out because there is
no practical way of fixing it in this package, while the case is
borderline unrealistic.
### Modifications:
- Only quote left `String` and `StringRepresentable` values in
`Logger.MetadataValue.description`.
- Add benchmarks for metadata values description rendering.
### Result:
100 nested metadata values render cleanly.
Resolves#515
### Alternatives
This is discussable if this fix is really necessary. Iterative approach,
because of allocations, is slower than recursion.
- Is it worth fixing the recursion, or a metadata depth check is enough?
- Is it worth fixing the nested metadata formatting?
### Motivation:
The two deprecated `LogHandler` defaults forward to each other: the
source-carrying `log(level:message:metadata:source:file:function:line:)`
default calls `log(event:)`, whose default calls the source-carrying
method, and the SwiftLog 1.0
`log(level:message:metadata:file:function:line:)` default calls the
source-carrying method. A handler that implements only `log(event:)`, as
the protocol documentation asks, therefore recurses until the stack
overflows whenever anything calls the 1.0 method on it. Handlers written
against SwiftLog 1.0 that wrap another handler and forward through the
1.0 method reach this path.
Differs from #248, where the handler implemented no log method at all.
### Modifications:
The 1.0 default builds a `LogEvent` and calls `log(event:)` directly.
The source is still the module derived from `file`, as before. Two tests
in `CompatibilityTest`: the 1.0 method reaching an event-only handler
(SIGSEGV at `main` before the change) and reaching a source-only
handler.
### Result:
A `LogHandler` implementing only `log(event:)` can be called through
every deprecated entry point. No source-breaking change; both deprecated
defaults remain.
Verified on Linux with Swift 6.1.2: `swift test -Xswiftc
-warnings-as-errors --explicit-target-dependency-import-check error
-Xswiftc -require-explicit-sendable` (166 tests) and `swift-format lint
--strict` on the changed files.
Found by an automated audit loop (Claude); patch and description
reviewed by me.
---------
Co-authored-by: Vladimir Kukushkin <kukushechkin@apple.com>
Simulators seem to have stabilized in CI, we can enabled the tests.
### Motivation:
`swift-log` is expected to be used on various platforms, we should run
tests against them.
### Modifications:
- Run tests on various tests in simulators in PRs and nightly.
- Fix tests to actually compile there.
### Result:
Tests are now running in simulators. Supersedes #431.
This proposal adds task-local logger storage so that metadata can
accumulate across async
call stacks without threading a `Logger` through every function
signature.
### Motivation:
Metadata propagation requires threading a logger through every layer.
Every function on
the path from request ingress to the bottom of the call stack has to
accept, mutate, and
forward a `Logger`. Libraries must choose between polluting their public
API with a `logger:` parameter and
losing all the caller's context. There is no third option today.
### Modifications:
- New API surface for reading and modifying the `@TaskLocal` `Logger`
instance added.
- Best practices on how to correctly propagate logger into libraries
updated with `Logger.current` API.
### Result:
Users can now automatically propagate accumulated metadata into
libraries without explicitly passing loggers through the API boundaries.
---------
Co-authored-by: Franz Busch <privat@franz-busch.de>
Add [Default String
Interpolation](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0477-default-interpolation-values.md)
overloads for `MetadataValue` to restore compatibility with
`\(default:)` interpolation.
### Motivation:
1.13.0 introduced a breaking change to the default string interpolation
compatibility. We do not want to revert the custom string interpolation,
but can fix compatibility with the default string interpolation as much
as possible.
### Modifications:
Add `\(default:)` overloads to `MetadataValue.StringInterpolation`,
similar to the once in `DefaultStringInterpolation`.
### Result:
Compatibility with `logger.info("Log message", metadata: ["value":
"\(value, default: "none")"])` is restored.
Proposal discussion thread:
https://forums.swift.org/t/proposal-slg-0004-metadata-value-attributes-revision-2/86488
Add an extensible per-value attribute mechanism for metadata.
### Motivation:
Metadata values in `swift-log` are opaque strings by the time the
`LogHandler` receives them. The call site often
knows things about a value that the handler cannot infer — for example,
whether the value should be redacted in
different environments.
### Modifications:
- SLG-0004 proposal is updated based on the feedback.
- Added `AttributedStringCarrier: CustomStringConvertible`-based
mechanism to `Logging`.
- Added benchmarks and benchmark thresholds for the new attributed
metadata.
### Result:
`swift-log` provides an optional extensible mechanism for attaching
attributes to metadata values.
---------
Co-authored-by: Franz Busch <privat@franz-busch.de>
Add tests for SwiftLogNoOpLogHandler
### Motivation:
`SwiftLogNoOpLogHandler` is a public type with no dedicated test
coverage.
### Modifications:
* Add tests for both initialisers, `logLevel`, `metadata`, the metadata
subscript, `log(event:)`, and end-to-end usage via `Logger`.
### Result:
`SwiftLogNoOpLogHandler` has test coverage on par with other handlers.
Coverage from 89% over all tests, to 90%.
Improve readability by extracting separate types to their own files
### Motivation:
`Logger.swift` is >2000 LoC, which makes it hard to navigate both for
contributors and users of `swift-log`. Widely different concepts, such
as concrete `LogHandler` implementations, are mixed with core types such
as `Logger.Level`. Extracting separate types should make it easier to
find what you are looking for.
Closes#441
### Modifications:
* Extract all (not `Logger`-namespaced) types from `Logging.swift` to
separate files.
* Rename `Logging.swift` to `Logger.swift`, as this is the only
remaining top-level type.
* Change `LoggingSystem.factory` from `fileprivate` to `internal` to be
accessible from `Logger.swift`.
### Result:
Each (non-private) top-level type lives in a separate file, named after
the type.
---------
Co-authored-by: Vladimir Kukushkin <kukushechkin@mac.com>
Add new methods on `Logger` that allows the caller to attach `Error`s to
log events, which will be propagated to the `LogHandler` as-is.
### Motivation:
Error information is typically of high interest in logs and log
analysis. Currently, however, there is no standardized way of attaching
`Error` information to logs, forcing users to either append it to the
log message (`logger.warning("Something went wrong: \(error)")`), or
attach it as metadata. By providing a separate parameter for this, and
passing it as-is to the `LogHandler`, we both provide a standard,
visible way to attach it, while also letting the `LogHandler` format it
as it sees fit.
Closes#291
### Modifications:
* New methods on `Logger` that accept an (optional) `Error`.
* An `error` property is added to `LogEvent`, which contains the `Error`
from the new `Logger` methods.
* Adjust `LogHandler` implementations to serialize error as metadata.
### Result:
Users of `Logger` can use the new methods to attach `Error`s to their
logs, which should help unify how `Error`s get logged in various code
bases.
`LogHandler` implementations can use the new `error` property on
`LogEvent` and serialize it in a way that's suitable for that
implementation. In general, extracting the string representation and the
(qualified) type name should be a good baseline.
---------
Co-authored-by: Vladimir Kukushkin <kukushechkin@mac.com>
Rewrites the default log handler to avoid typing out what the C file
pointer looks like on different platforms.
This fixes#374 - as we do not make any assumptions at compile time
about what `FILE*` is imported as in Swift.
Replace the flat-parameter
`log(level:message:metadata:source:file:function:line:)` method on
`LogHandler` with
`log(event: LogEvent)`, enabling forward-compatible evolution of the
`LogHandler` interface without breaking existing
handler implementations.
### Motivation:
Changes to the `LogHandler` API require dance around creating new
overloads, deprecating old overloads, which unnecessary bloats
`LogHandler` protocol surface (like happened with the source:
parameter). We have upcoming changes that would introduce new
capabilities to the `LogHandler` protocol, for example
https://forums.swift.org/t/proposal-slg-0003-standardized-error-metadata-via-logger-convenience/84518/35.
It makes sense to introduce a single container structure for all the
data associated with a log event before introducing any new overloads in
`LogHandler` protocol.
### Modifications:
- New struct `LogEvent` is added.
- `LogHandler` protocol now has an additional `log(event: LogEvent)`
method.
- `Logger` is calling handler's `log(event: LogEvent)` method.
### Result:
Further changes to the `LogEvent` with new information passed from the
`Logger` to a `LogHandler` does not require changes in the `LogHandler`
API. As a bonus, `LogEvent` makes `source` a computable variable,
improving performance for log handlers who do not need the default
source created based on the log file location.
I've added support for FreeBSD. I've only tested this PR on FreeBSD, but
I believe it should also work on OpenBSD.
### Motivation:
closes#372
Also, [Swift on FreeBSD preview
toolchain](https://forums.swift.org/t/swift-on-freebsd-preview/83064) is
now available.
### Modifications:
- changed pthread-related code for *BSD
- changed `Glibc.stdout` and `Glibc.stderr` for *BSD because they are
non-optional on *BSD
### Result:
swift-log and packages depending on it will be usable on FreeBSD.
### Checks:
I tested it with `swift build` and `swift test`. All tests have passed.
```console
$ swift test
...
Test Suite 'All tests' passed at 2025-11-07 04:29:34.003
Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds
...
✔ Test run with 52 tests in 7 suites passed after 0.309 seconds.
```
Environment:
```console
$ uname -a
FreeBSD Coconut-rhinoceros-beetle 15.0-BETA4 FreeBSD 15.0-BETA4 releng/15.0-n280841-a7707f2a3bf4 GENERIC amd64
$ swift --version
Swift version 6.3-dev (LLVM bff1370bd79c983, Swift 57cf4ce563f700b)
Target: x86_64-unknown-freebsd14.3
Build config: +assertions
```
Swift toolchain is from
https://forums.swift.org/t/swift-on-freebsd-preview/83064.
---------
Co-authored-by: Franz Busch <f.busch@apple.com>
Conform `Logger.Level` to `CustomStringConvertible` and
`LosslessStringConvertible`.
### Motivation:
There are libraries, such as Vapor, that add these conformances
privately and `@retroactive`ly. This would avoid having to implement
these conformances manually in each library and would unify and
standardise the implementation.
### Modifications:
Make `Logger.Level` conform to `CustomStringConvertible` and
`LosslessStringConvertible`, adding a public `description` computed
property that returns the `rawValue` and a public initializer that takes
a `description` string, lowercases it, and passes it to the `rawValue`
initializer.
### Result:
`Logger.Level` conforms to `CustomStringConvertible` and
`LosslessStringConvertible`.
Make InMemoryLogging available on all platforms
### Motivation:
Users might want to adopt the in memory logger on lower platform
versions.
### Modifications:
Remove availability annotations by using swift-logs own Lock instead of
Mutex
### Result:
In memory logger can be used on all platforms that swift-log supports
Add an InMemoryLogHandler
### Motivation:
Library maintainers should be able to test that their libraries log what
they expect
### Modifications:
Create a new InMemoryLogging product, which contains an
InMemoryLogHandler
This log handler can be used to make a logger, pass the logger into some
function, and then assert that logs were emitted.
See the tests for example usage
### Future:
For now i have left this very bare-bones. We could in future add
convenience functions. For example
- a function to assert that a particular log message was logged
- a static function to create a logger with this handler
---------
Co-authored-by: Franz Busch <privat@franz-busch.de>
Migrating `swift-log` from XCTest to Swift Testing
### Motivation
Swift Testing is a modern alternative to XCTest. Swift Server Ecosystem
packages should serve as reference implementations for modern Swift
features and best practices.
### Modifications
- 1-to-1 migration of test suites, tests, and assertions to Swift
Testing syntax with XCTest import removed
- XCTest references removed from documentation
- `.trace` log level added to relevant tests
- `GlobalLoggerTest` suite serialized to handle global `LoggingSystem`
access (XCTest runs tests serially by default; Swift Testing runs in
parallel, so serializing this suite avoids requiring `swift test
--no-parallel` across all CI and development environments)
### Result
Successfully executes 52 tests with `swift test --disable-xctest`.
Make Swift 6.0 the minimum support version.
### Motivation:
`swift-log` supports 3 latest Swift releases, which is at this point
6.0, 6.1 and 6.2. Swift 5 is no longer supported.
### Modifications:
- Package.swift swift tools
- CI configs
- Imports checking if compiler is <6.0
### Result:
Swift 5 is no longer supported.
Co-authored-by: Honza Dvorsky <honza@apple.com>
### Motivation:
`StreamLogHandler` has at some point in time acquired an extra
whitespace:
```
2025-07-18T10:09:12+0100 notice label : hello
^
|
this one is superfluous
```
but we don't typically put spaces in front of `:`s. This PR changes it
to
```
2025-07-18T10:09:12+0100 notice label: hello
^
|
no extra space
```
Additionally, if the label is empty (`""`), then we shouldn't print any
spaces there. So with an empty label, we go from
```
2025-07-18T10:09:12+0100 notice : hello
^^
|
two superfluous spaces
```
to
```
2025-07-18T10:09:12+0100 notice: hello
^
|
no extra spaces
```
### Modifications:
- Remove superfluous space if label is not empty
- Remove two superfluous spaces if label is empty
### Result:
- Somewhat more compact output
- Nicer output
### Motivation:
Fixes https://github.com/apple/swift-log/issues/278.
### Modifications:
Fixed tests to successfully compile on Fedora 39 and Ubuntu 24.04, which
they previously failed on.
### Result:
Ability to run tests on these two platforms again.
# Motivation
Fixes https://github.com/apple/swift-log/issues/330.
We had a few warnings since we were using deprecated POSIX methods on Windows.
# Modification
Moves to the non-deprecated underscored methods.
# Result
Windows build is warning free.
Motivation:
Latest swift introduces new warnings when deprecated default
implementations are used.
Modifications:
Add new log implementation to NoopLogHandler.
Mark test of old method as deprecated to silence warning.
Result:
Warning free builds on latest swift 6 compiler.
Motivation:
This becomes a critical feature in swift 6.
Modifications:
Add Sendability annotations where required.
Factor out code protected by locks.
Result:
Compiles without warnings with Sendability checking
Motivation:
Calling through protocols is more expensive than many other types of call.
Modifications:
Annotate each protocol usage with any or some keywords.
Result:
Protocol usage now obvious
motivation: adjust to swift 5.6
changes:
* define sendable shims for protocols and structs that may be used in async context
* adjust tests
* add a test to make sure no warning are emitted
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).
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.