1 unstable release

0.1.0 May 3, 2022

#934 in Debugging

MPL-2.0 OR MIT OR Apache-2.0

22KB
184 lines

slog_prometheus - Logging metrics

Why?

Loads of times, using the tracing ecosystem is a very good option. But sometimes, I have a small piece of software, which does simple logging and as I try to be a responsible dev, it should be monitored. So i give it some metrics.

This library tries to add a few simple metrics about what has been logged, making it easy to have a catch-all alert for things logging errors.

How?

let drain = slog_prometheus::MonitoringDrainBuilder::new(drain)
        .build()
        .expect("Failed configuring setting up prometheus")
        .fuse();

Feel free to open an issue if you encounter any problems or are interested in features.


lib.rs:

Record prometheus metrics for messages logged.

Use the MonitoringDrainBuilder to configure a drain, putting it in an appropriate spot in the slog drain stack.

use slog::{info, Drain};

let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::FullFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build();

let drain = slog_prometheus::MonitoringDrainBuilder::new(drain)
    .build()
    .expect("Failed configuring setting up prometheus")
    .fuse();
let drain = slog::LevelFilter::new(drain, slog::Level::Info).fuse();

let logger = slog::Logger::root(drain, slog::o!());

info!(logger, "Finished setting up!");

Dependencies

~2.5–7.5MB
~69K SLoC