#serde #gelf #logs #logging-framework #logging

log4rs-gelf

TCP Handler and GELF Encoder to use with the log4rs logging framework

5 releases

Uses old Rust 2015

0.1.4 Dec 2, 2019
0.1.3 Dec 2, 2019
0.1.2 Nov 29, 2019
0.1.1 May 14, 2019
0.1.0 May 14, 2019

#1771 in Encoding

46 downloads per month

BSD-3-Clause

19KB
171 lines

log4rs-gelf

Build Status Latest version Documentation License

log4rs-gelf - A TCP/Gelf appender for log4rs based on serde_gelf and gelf_logger.

Examples

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 !");
}

OVH Log Data Platform

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();

License

Licensed under BSD 3-Clause License or (https://opensource.org/licenses/BSD-3-Clause)

Dependencies

~3–13MB
~164K SLoC