6 releases (3 breaking)

new 0.22.0 Jan 13, 2021
0.21.0 Nov 12, 2020
0.20.1 Sep 15, 2020
0.19.1 Aug 28, 2020
0.19.0 Jun 18, 2020
Download history 45/week @ 2020-09-30 57/week @ 2020-10-07 87/week @ 2020-10-14 87/week @ 2020-10-21 160/week @ 2020-10-28 81/week @ 2020-11-04 106/week @ 2020-11-11 101/week @ 2020-11-18 37/week @ 2020-11-25 94/week @ 2020-12-02 133/week @ 2020-12-09 81/week @ 2020-12-16 77/week @ 2020-12-23 39/week @ 2020-12-30 90/week @ 2021-01-06 412/week @ 2021-01-13

403 downloads per month
Used in sentry

Apache-2.0

120KB
2K SLoC

Sentry Rust SDK: sentry-slog

Sentry slog Integration.

This mainly provides the SentryDrain, which wraps another [slog::Drain] and can be configured to forward [slog::Record]s to Sentry. The SentryDrain can be used to create a slog::Logger.

NOTE: This integration currently does not process any slog::KV pairs, but support for this will be added in the future.

Examples

use sentry::{init, ClientOptions};
use sentry_slog::SentryDrain;

let _sentry = sentry::init(());

let drain = SentryDrain::new(slog::Discard);
let root = slog::Logger::root(drain, slog::o!());

slog::info!(root, "recorded as breadcrumb");
slog::warn!(root, "recorded as regular event");

assert_eq!(
    captured_event.breadcrumbs.as_ref()[0].message.as_deref(),
    Some("recorded as breadcrumb")
);
assert_eq!(
    captured_event.message.as_deref(),
    Some("recorded as regular event")
);

slog::crit!(root, "recorded as exception event");

assert_eq!(captured_event.exception.len(), 1);

The Drain can also be customized with a filter, and a mapper:

use sentry_slog::{exception_from_record, LevelFilter, RecordMapping, SentryDrain};

let drain = SentryDrain::new(slog::Discard)
    .filter(|level| match level {
        slog::Level::Critical | slog::Level::Error => LevelFilter::Event,
        _ => LevelFilter::Ignore,
    })
    .mapper(|record, kv| match record.level() {
        slog::Level::Critical | slog::Level::Error => {
            RecordMapping::Event(exception_from_record(record, kv))
        }
        _ => RecordMapping::Ignore,
    });

When a mapper is specified, a corresponding filter should also be provided.

Resources

License: Apache-2.0

Dependencies

~3.5–4.5MB
~112K SLoC