#serde #logs #GELF

gelf_logger

Minimal rust logger to send log entries in GELF

5 releases

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

#165 in Encoding

Download history 28/week @ 2019-08-26 18/week @ 2019-09-02 5/week @ 2019-09-09 42/week @ 2019-09-16 8/week @ 2019-09-23 10/week @ 2019-09-30 10/week @ 2019-10-14 20/week @ 2019-10-21 3/week @ 2019-10-28 5/week @ 2019-11-04 4/week @ 2019-11-11 10/week @ 2019-11-18 29/week @ 2019-11-25

56 downloads per month
Used in 1 crate

BSD-3-Clause

42KB
738 lines

gelf_logger

Build Status Latest version Documentation License

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:

  1. serialize log entries using the serde_gelf crate.
  2. bufferize the result into memory.
  3. batch send over network using TCP/TLS.

Example

#[macro_use]
extern crate gelf_logger;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
extern crate serde_value;

use serde_gelf::GelfLevel;

use gelf_logger::Config;

#[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(),
        }
    }
}

fn main() {
    let cfg = Config::builder()
        .set_hostname("localhost".into())
        .set_port(12202)
        .set_level(GelfLevel::Informational)
        .set_buffer_duration(300)
        .set_buffer_size(500)
        .put_additional_field("myValue".into(), serde_value::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();
}

License

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

Dependencies

~1.7–2.6MB
~58K SLoC