|
1 | 1 | # Changelog
|
2 | 2 |
|
| 3 | +## [Unreleased] |
| 4 | + |
| 5 | +- Attach logging context to exceptions when they would escape the scope of |
| 6 | + `withLoggingContext` |
| 7 | + - Previously, when an exception was thrown inside a logging context scope, one would lose that |
| 8 | + logging context if the exception was logged further up the stack (which is typical). But |
| 9 | + unexpected exceptions is when we need this context the most! So now, `withLoggingContext` |
| 10 | + attaches its context fields to any encountered exception before re-throwing it up the stack, and |
| 11 | + `Logger` includes these fields when the exception is logged. |
| 12 | +- Allow log fields to overwrite logging context fields for a single log |
| 13 | + - Previously, duplicate keys could appear in the log output if the same key was used on a |
| 14 | + single-log field as on a logging context field. |
| 15 | +- Use |
| 16 | + [Kotlin Contracts](https://github.com/Kotlin/KEEP/blob/2b887d02fbf4cbf8b520cb2fbca11f4a807a353e/proposals/KEEP-0139-kotlin-contracts.md) |
| 17 | + in `withLoggingContext` |
| 18 | + - This gives users more flexibility in what they can do in the given lambda. |
| 19 | +- **Breaking:** Rename `ExceptionWithLogFields` to `ExceptionWithLoggingContext`, and `HasLogFields` |
| 20 | + to `HasLoggingContext` |
| 21 | + - This makes the naming of these classes more consistent with the `withLoggingContext` function. |
| 22 | +- **Breaking:** `ExceptionWithLoggingContext` no longer implements the `HasLoggingContext` interface |
| 23 | + - When it implemented this interface, it needlessly had to expose its `logFields` property, which |
| 24 | + should be an implementation detail. |
| 25 | +- **Breaking:** Rename `getLoggingContext` to `getCopyOfLoggingContext`, change its return value to |
| 26 | + an opaque `LoggingContext` wrapper class, and add new `withLoggingContext` overload that accepts |
| 27 | + this new `LoggingContext` type |
| 28 | + - This new name is more explicit about what the function does, and also avoids competing with |
| 29 | + `getLogger` for autocomplete. |
| 30 | + - The `LoggingContext` wrapper class enables some performance optimizations, since we no longer |
| 31 | + need to turn the logging context into a `List`. |
| 32 | +- **Breaking:** Use `Collection` instead of `List` in public APIs that accept or provide multiple |
| 33 | + log fields |
| 34 | + - `Collection` is a more flexible interface than `List`. |
| 35 | +- **Breaking:** Change return type of `rawJson` function from |
| 36 | + `kotlinx.serialization.json.JsonElement` to custom `RawJson` wrapper type |
| 37 | + - This reduces the coupling of the library's API to `kotlinx.serialization`, while keeping the |
| 38 | + same serialization behavior. In the future, we may want to support e.g. Jackson serialization on |
| 39 | + the JVM, so this gives us more flexibility. |
| 40 | +- Change how JSON fields in `withLoggingContext` are handled, to avoid internal implementation |
| 41 | + details leaking out |
| 42 | + - In the previous implementation, a key suffix was used to identify logging context fields with |
| 43 | + JSON values. But in certain log output configurations, this implementation detail could leak |
| 44 | + out. This implementation has now been reworked, both to avoid leaking implementation details and |
| 45 | + also to improve performance (by avoiding allocations). |
| 46 | +- Minimize the amount of code in `inline` functions |
| 47 | + - Having a lot of code in `inline` functions increases code size (since that code is replicated |
| 48 | + wherever the `inline` function is called), which can negatively affect perforamnce. The library |
| 49 | + now only includes the most necessary code in `inline` blocks, delegating to normal functions |
| 50 | + where possible. |
| 51 | + |
3 | 52 | ## [v0.7.0] - 2025-06-12
|
4 | 53 |
|
5 | 54 | - Move `LoggingContextJsonFieldWriter` to `output.logback` subpackage, and rename to the more
|
|
0 commit comments