Expand description
tracing-glog
is a glog-inspired formatter for tracing-subscriber
.
tracing-glog
is meant to be used with tracing-subscriber
’s fmt::Subscriber
and fmt::Layer
to format events in a glog
-inspired fashion. Similar to
tracing-subscriber
’s Full
formatter, this formatter shows the span context before
printing event data. Spans are displayed including their names and fields. The severity,
time, PID, thread name, file, and line are also included.
§Example Output
I1201 01:13:04.724801 1025672 main [yak_shave] examples/yak-shave.rs:34] preparing to shave yaks, number_of_yaks: 3 I1201 01:13:04.724948 1025672 main [yak_shave] examples/yak-shave.rs:75] [shaving_yaks{yaks: 3}] shaving yaks W1201 01:13:04.725071 1025672 main [yak_shave] examples/yak-shave.rs:56] [shaving_yaks{yaks: 3}, shave{yak: 3}] could not locate yak E1201 01:13:04.725135 1025672 main [yak_shave] examples/yak-shave.rs:85] [shaving_yaks{yaks: 3}] failed to shave yak, yak: 3, error: out of cash I1201 01:13:04.725195 1025672 main [yak_shave] examples/yak-shave.rs:38] yak shaving completed, all_yaks_shaved: false
§Usage
With fmt::Subscriber
:
use tracing_glog::{Glog, GlogFields};
tracing_subscriber::fmt()
.event_format(Glog::default())
.fmt_fields(GlogFields::default())
.init();
With fmt::Layer
:
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, Registry};
use tracing_glog::{Glog, GlogFields};
let fmt = fmt::Layer::default()
.event_format(Glog::default())
.fmt_fields(GlogFields::default());
let subscriber = Registry::default().with(fmt);
tracing::subscriber::set_global_default(subscriber).expect("Unable to set global subscriber");
With UtcTime
:
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, Registry};
use tracing_glog::{Glog, GlogFields};
let fmt = fmt::Layer::default()
.event_format(Glog::default().with_timer(tracing_glog::UtcTime::default()))
.fmt_fields(GlogFields::default());
let subscriber = Registry::default().with(fmt);
tracing::subscriber::set_global_default(subscriber).expect("Unable to set global subscriber");
With LocalTime
:
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, Registry};
use tracing_glog::{Glog, GlogFields};
let fmt = fmt::Layer::default()
.event_format(Glog::default().with_timer(tracing_glog::LocalTime::default()))
.fmt_fields(GlogFields::default());
let subscriber = Registry::default().with(fmt);
tracing::subscriber::set_global_default(subscriber).expect("Unable to set global subscriber");
Warning: Thetime
crate must be compiled with--cfg unsound_local_offset
in order to use `LocalTime`. When this cfg is not enabled, local timestamps cannot be recorded, and no events will be emitted.See the
time
documentation for more details.
Modules§
Structs§
- Format
Level Chars - Glog
- A glog-inspired span and event formatter.
- Glog
Fields - Local
Time - Formats the current
local time
usingchrono
crate. - UtcTime
- Formats the current UTC time using
chrono
crate.