Crate tracing_gelf[−][src]
Provides Graylog structured logging using the tracing
.
Usage
use std::net::SocketAddr; use tracing_gelf::Logger; #[tokio::main] async fn main() { // Graylog address let address: SocketAddr = "127.0.0.1:12201".parse().unwrap(); // Start tracing let bg_task = Logger::builder().init_tcp(address).unwrap(); // Spawn background task // Any futures executor can be used tokio::spawn(bg_task); // Send a log to Graylog tracing::info!(message = "oooh, what's in here?"); // Create a span let span = tracing::info_span!("cave"); span.in_scope(|| { // Log inside a span let test = tracing::info_span!("deeper in cave", smell = "damp"); test.in_scope(|| { tracing::warn!(message = "oh god, it's dark in here"); }) }); // Log a structured log tracing::error!(message = "i'm glad to be out", spook_lvl = 3, ruck_sack = ?["glasses", "inhaler", "large bat"]); }
GELF Encoding
Events
are encoded into GELF format
as follows:
Event
fields are inserted asGELF
additional fields,_field_name
.Event
field namedmessage
is renamed toshort_message
.- If
short_message
(ormessage
)Event
field is missing thenshort_message
is set to the empty string. Event
fields whose names collide withGELF
required fields are coerced into the required types and overrides defaults given in the builder.- The hierarchy of spans is concatenated and inserted as
span_a:span_b:span_c
and inserted as an additional field_span
.
Modules
visitor | This module contains lower-level primitives for visiting fields. |
Structs
Builder | A builder for |
Logger |
|
Enums
BuilderError | The error type for |