Crate tracing_gelf
source · [−]Expand description
Provides a tracing Layer for Graylog structured logging.
Usage
use std::net::SocketAddr;
use tracing_gelf::Logger;
#[tokio::main]
async fn main() {
// Graylog address
let address = "127.0.0.1:12201";
// Initialize subscriber
let conn_handle = Logger::builder().init_tcp(address).unwrap();
// Spawn background task
// Any futures executor can be used
tokio::spawn(conn_handle.connect());
// 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(|| {
let test = tracing::info_span!("deeper in cave", smell = "damp");
test.in_scope(|| {
// Send a log to Graylog, inside a nested span
tracing::warn!(message = "oh god, it's dark in here");
})
});
// Send a log to Graylog
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:
Eventfields are inserted asGELFadditional fields,_field_name.Eventfield namedmessageis renamed toshort_message.- If
short_message(ormessage)Eventfield is missing thenshort_messageis set to the empty string. Eventfields whose names collide withGELFrequired 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_cand inserted as an additional field_span.
Structs
A sequence of errors which occurred during a connection attempt.
Provides an interface for connecting (and reconnecting) to Graylog. Without an established connection logs will not be sent. Messages logged without an established connection will sit in the buffer until they can be drained.
A TCP connection to Graylog.
A UDP connection to Graylog.
Enums
The error type for Logger building.