#logstash #logging-tracing #logging #tracing

tracing-logstash

Minimal library to output logstash formatted events

9 releases (breaking)

0.7.0 Jan 8, 2024
0.6.4 Nov 15, 2023
0.6.1 Sep 19, 2023
0.5.0 May 6, 2023
0.1.0 Feb 5, 2021

#180 in Debugging

Download history 188/week @ 2024-03-13 70/week @ 2024-03-20 27/week @ 2024-03-27 88/week @ 2024-04-03 123/week @ 2024-04-10 45/week @ 2024-04-17 60/week @ 2024-04-24 4/week @ 2024-05-01 17/week @ 2024-05-08 39/week @ 2024-05-15 88/week @ 2024-05-22 53/week @ 2024-05-29 12/week @ 2024-06-05 26/week @ 2024-06-12 8/week @ 2024-06-19 15/week @ 2024-06-26

62 downloads per month

MIT license

36KB
934 lines

tracing-logstash

The absolute minimum amount of code I could get away with for writing tracing messages/logs in the https://github.com/logstash/logstash-logback-encoder#standard-fields format.

Currently built for use in a single application with a single log consumer.

Installation

You can include this library in your Cargo.toml file:

[dependencies]
tracing-logstash = "0.6.1"

Usage

fn main() {
    let logger = tracing_logstash::Layer::default()
        .event_format(tracing_logstash::logstash::LogstashFormat::default()
            .with_constants(vec![
                ("service.name", "tracing-logstash".to_owned()),
            ])
        );

    let env_filter = EnvFilter::try_from_default_env()
        .or_else(|_| EnvFilter::try_new("info"))
        .unwrap();

    let collector = Registry::default().with(logger).with(env_filter);

    tracing::subscriber::set_global_default(collector).unwrap();
    
    tracing::info!("Hello, world!");
}

Logstash Format Reference

https://github.com/logstash/logstash-logback-encoder#standard-fields

Sample output (from example app)

{
  "@version": "1",
  "@timestamp": "2023-09-14T09:34:17.233512Z",
  "thread_name": "tokio-runtime-worker",
  "logger_name": "hyper",
  "level": "INFO",
  "level_value": 5,
  "message": "tracing crate macro",
  "some_tag": 43,
  "service.name": "tracing-logstash"
}

License

This library is distributed under the terms of the MIT License. See the LICENSE file for details.

Dependencies

~2.5MB
~44K SLoC