log4rs-gelf

Crates.iolog4rs-gelf
lib.rslog4rs-gelf
version0.1.4
sourcesrc
created_at2019-05-14 16:04:54.719732
updated_at2019-12-02 11:52:49.987225
descriptionTCP Handler and GELF Encoder to use with the log4rs logging framework.
homepage
repositoryhttps://github.com/ovh/rust-log4rs-gelf
max_upload_size
id134328
size27,061
ovh-cds (ovh-cds)

documentation

README

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)

Commit count: 35

cargo fmt