Add string log formatting witnesses and builder 👷 #252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
master
Motivation and Context
Until now, we relied on a custom string-based log format to convert log items into log messages. However, it was quite limited because it only allowed a predefined set of components/formats, evaluated the format string for every log item.
By modeling formatting as witnesses wrapping a closure that can be composed, more flexibility is achieved and items are formatted efficiently by performing a single (composed) closure.
To improve ergonomics, a new result builder was created to allow defining log formatting witnesses with a flexible DSL.
Description
Create
LogItemFormatComponent
protocol to model first class types for multiple composable format operations.Create
Log.ItemFormat
namespace, to nest:LogItemFormatComponent
implementations, operators and static helpers for most common operationsFormatting
witness and static helpersBuilder
result builderUpdate
Log.StringLogItemFormatter
to only require aFormatting
and be instantiated via aLog.ItemFormat.Builder
.Remove
LogLevelFormatter
s.Deprecate
Log.Item.testItem
in favor ofLog.Item.dummy()
.Fix and add relevant UTs.
Add
@inlinable
annotations for improved optimization possibilities.Log item formatting:
"<timestamp> <module>? | <level emoji> <level> | [<thread>/<queue>] <function> | <file>:<line> | <msg>"
Old
New