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.

The integration also supports [slog::KV] pairs. They will be added to the breadcrumb data or the event extra properties respectively.

Examples

```rust use sentry_slog::SentryDrain;

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

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

slog::info!(root, "recorded as breadcrumb"; "breadcrumbkv" => Some("breadcrumb")); slog::warn!(root, "recorded as regular event"; "eventkv" => "event");

let breadcrumb = &capturedevent.breadcrumbs.asref()[0]; asserteq!( breadcrumb.message.asderef(), Some("recorded as breadcrumb") ); asserteq!(breadcrumb.data["breadcrumbkv"], "breadcrumb"); asserteq!(breadcrumb.data["globalkv"], 1234);

asserteq!( capturedevent.message.asderef(), Some("recorded as regular event") ); asserteq!(capturedevent.extra["eventkv"], "event"); asserteq!(capturedevent.extra["global_kv"], 1234);

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

asserteq!( capturedevent.message.as_deref(), Some("recorded as exception event") ); ```

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

```rust use sentryslog::{exceptionfrom_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(exceptionfromrecord(record, kv)) } _ => RecordMapping::Ignore, }); ```

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

Resources

License: Apache-2.0