Crates.io | log4rs-gelf |
lib.rs | log4rs-gelf |
version | 0.1.4 |
source | src |
created_at | 2019-05-14 16:04:54.719732 |
updated_at | 2019-12-02 11:52:49.987225 |
description | TCP Handler and GELF Encoder to use with the log4rs logging framework. |
homepage | |
repository | https://github.com/ovh/rust-log4rs-gelf |
max_upload_size | |
id | 134328 |
size | 27,061 |
log4rs-gelf
- A TCP/Gelf appender for log4rs based on
serde_gelf and gelf_logger.
Configuration via a YAML file:
appenders:
ldp:
additional_fields:
component: rust-cs
buffer_duration: 5
buffer_size: 5
hostname: 127.0.0.1
kind: buffer
level: Informational
null_character: true
port: 12202
use_tls: false
root:
appenders:
- ldp
level: info
log4rs_gelf::init_file("/tmp/log4rs.yml", None).unwrap();
Programmatically constructing a configuration:
use serde_gelf::GelfLevel;
use serde_value::Value;
use log4rs::config::{Config, Appender, Root};
use log::LevelFilter;
fn main() {
let buffer = log4rs_gelf::BufferAppender::builder()
.set_level(GelfLevel::Informational)
.set_hostname("localhost")
.set_port(12202)
.set_use_tls(false)
.set_null_character(true)
.set_buffer_size(Some(5))
.set_buffer_duration(Some(5))
.put_additional_field("component", Value::String("rust-cs".to_string()))
.build()
.unwrap();
let config = Config::builder()
.appender(Appender::builder().build("gelf", Box::new(buffer)))
.build(Root::builder().appender("gelf").build(LevelFilter::Info))
.unwrap();
log4rs_gelf::init_config(config).unwrap();
// Do whatever
log4rs_gelf::flush().expect("Failed to send buffer, log records can be lost !");
}
You can activate the OVH LDP feature including field typing and an preconfigured handler:
[dependencies]
log4rs_gelf = { version = "0.1", features = ["ovh-ldp"] }
And then build the appender:
let buffer = BufferAppender::builder("gra1.logs.ovh.com","XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
.put_additional_field("component", Value::String("rust-cs".to_string()))
.build()
.unwrap();
Licensed under BSD 3-Clause License or (https://opensource.org/licenses/BSD-3-Clause)