Code Monkey home page Code Monkey logo

rust-gelf_logger's Introduction

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)

rust-gelf_logger's People

Contributors

cdumay avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.