Crate gelf_logger
source ·Expand description
§gelf_logger
The Graylog Extended Log Format (GELF) is a log format that avoids the shortcomings of classic log formats. GELF is a great choice for logging from within applications. There are libraries and appenders for many programming languages and logging frameworks so it is easy to implement. You could use GELF to send every exception as a log message to your Graylog cluster.
The logger will:
- serialize log entries using the serde_gelf crate.
- bufferize the result into memory.
- batch send over network using TCP/TLS.
§Example
use std::time::Duration;
use gelf_logger::{gelf_warn, Config, GelfLevel};
use log::info;
use serde_derive::Serialize;
#[derive(Serialize)]
struct Myapp {
name: String,
version: String,
}
impl Default for Myapp {
fn default() -> Myapp {
Myapp {
name: env!("CARGO_PKG_NAME").into(),
version: env!("CARGO_PKG_VERSION").into(),
}
}
}
let cfg = Config::builder()
.set_hostname("localhost".into())
.set_port(12202)
.set_level(GelfLevel::Informational)
.set_buffer_duration(Duration::from_millis(300))
.set_buffer_size(500)
.put_additional_field("myValue".into(), gelf_logger::Value::I64(10))
.set_null_character(true)
.build();
// Initialize logger
gelf_logger::init(cfg).unwrap();
// Send log using a macro defined in the create log
info!("common message");
// Use a macro from gelf_logger to send additional data
gelf_warn!(extra: &Myapp::default(), "My app info");
// make sure all buffered records are sent before exiting
gelf_logger::flush().unwrap();
Re-exports§
pub use serde_gelf::GelfLevel;
pub use serde_gelf::GelfRecord;
pub use serde_value::Value;
Macros§
- Logs a message at the alert level (Should be corrected immediately).
- Logs a message at the critical level (Should be corrected immediately).
- Logs a message at the debug level (Mainly used by developers).
- Logs a message at the emergency level (A “panic” condition).
- Logs a message at the error level (Non-urgent failures).
- Logs a message at the info level (Normal message).
- The standard logging macro.
- Logs a message at the notice level (Unusual event).
- Logs a message at the warning level (Warning messages).
Structs§
- Struct to send event in thread
- struct to store a buffer of
GelfRecord
- Struct to manipulate configuration.
- Builder for
Config
. - Struct to send
GelfRecord
into a TCP socket
Enums§
- Enum to represent errors
Traits§
- Trait for async batch processing of
GelfRecord
.
Functions§
- Force current logger record buffer to be sent to the remote server.
- Initialize the logger using the given
Config
. - Initialize the logger using a configuration file.
- Initialize the BatchProcessor.
- Returns a reference to the batch processor.