4 releases

0.20.1 Sep 15, 2020
0.20.0 Sep 9, 2020
0.19.1 Aug 28, 2020
0.19.0 Jun 18, 2020
Download history 14/week @ 2020-06-13 4/week @ 2020-06-20 3/week @ 2020-06-27 2/week @ 2020-07-04 9/week @ 2020-07-11 5/week @ 2020-07-18 3/week @ 2020-07-25 14/week @ 2020-08-01 66/week @ 2020-08-08 53/week @ 2020-08-15 44/week @ 2020-08-22 49/week @ 2020-08-29 25/week @ 2020-09-05 33/week @ 2020-09-12 22/week @ 2020-09-19

107 downloads per month
Used in sentry

Apache-2.0

110KB
2K SLoC

Sentry Rust SDK: sentry-slog

Sentry slog Integration.

The sentry slog integration consists of two parts, the SlogIntegration which configures how sentry should treat slog::Records, and the SentryDrain, which 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, SlogIntegration};

let integration = SlogIntegration::default();
let options = ClientOptions::default().add_integration(integration);
let _sentry = sentry::init(options);

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 integration can also be customized with a filter, and a mapper:

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

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

Please not that the mapper can override any classification from the previous filter.

Resources

License: Apache-2.0

Dependencies

~4.5MB
~108K SLoC