tracing-scribe
A tracing-subscriber layer for beautifully printing spans and events to the
terminal.
This crate provides a ConsoleLayer that can be used with tracing to format
and display log messages in a hierarchical and easy-to-read format. It is
designed to make command line applications more pleasant by providing clear
visual cues for different log levels, tracking the duration of spans, and
indicating success or failure states.
Features
- Pretty Printing: Spans and events are displayed with icons, colors, and indentation to create a clear visual hierarchy.
- Automatic
ResultHandling: Theconsole!macro automatically logs the outcome of aResult, indicating success or failure. - Span Timings: The layer automatically tracks and displays the execution time of each span.
- Error Propagation: Errors inside spans are propagated to parent spans, marking them as failed.
Installation
[]
= "0.1"
Usage
To use ConsoleLayer, add it to your tracing subscriber registry. The
console! macro can then be used to log events with different status levels.
Example
Here is a complete example demonstrating a successful execution with nested
spans and #[tracing::instrument].
use info_span;
use console;
use *;
use Registry;
let subscriber = default.with;
with_default;
This will produce the following output:
Error Handling
The ConsoleLayer also handles errors gracefully. When a span instrumented
with #[tracing::instrument(err)] returns an error, the span and its parents
are marked as failed.
use Error;
use fmt;
use info_span;
use console;
use *;
use Registry;
;
let subscriber = default.with;
with_default;
This will produce the following output:
Asynchronous tasks
Asynchronous tasks are handled their own way by tracing. To make sure they end up with the right indentation, you might have to wrap them with a tracing instrumentation call.
use Instrument;
use console;
async
async
Attaching Extra Information
The extra field can be used to attach additional context to a span, which
will be displayed alongside the span name.
use info_span;
use console;
use *;
use Registry;
let subscriber = default.with;
with_default;
This will produce the following output:
Custom Colors
You can customize colors via the ColorScheme builder.
use colors;
use ;
let colors = default
.with_success_color
.with_error_color
.with_tree_color;
let layer = default.with_colors;
See examples/custom_colors.rs for a full example:
Custom Status
The with_status method allows you to customize the icons used for the
different statuses. See the API documentation for the Status and
StatusFactory traits.
Examples
Run the bundled examples to see the layer in action:
License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).