Crate sentry_log

Source
Expand description

Adds support for automatic Breadcrumb, Event, and Log capturing from log records.

The log crate is supported in three ways:

  • Records can be captured as Sentry events. These are grouped and show up in the Sentry issues page, representing high severity issues to be acted upon.
  • Records can be captured as breadcrumbs. Breadcrumbs create a trail of what happened prior to an event, and are therefore sent only when an event is captured, either manually through e.g. sentry::capture_message or through integrations (e.g. the panic integration is enabled (default) and a panic happens).
  • Records can be captured as traditional logs Logs can be viewed and queried in the Logs explorer.

By default anything above Info is recorded as a breadcrumb and anything above Error is captured as error event.

To capture records as Sentry logs:

  1. Enable the logs feature of the sentry crate.
  2. Initialize the SDK with enable_logs: true in your client options.
  3. Set up a custom filter (see below) to map records to logs (LogFilter::Log) based on criteria such as severity.

§Examples

let mut log_builder = pretty_env_logger::formatted_builder();
log_builder.parse_filters("info");
let logger = sentry_log::SentryLogger::with_dest(log_builder.build());

log::set_boxed_logger(Box::new(logger)).unwrap();
log::set_max_level(log::LevelFilter::Info);

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

log::info!("Generates a breadcrumb");
log::error!("Generates an event");

Or one might also set an explicit filter, to customize how to treat log records:

use sentry_log::LogFilter;

let logger = sentry_log::SentryLogger::new().filter(|md| match md.level() {
    log::Level::Error => LogFilter::Event,
    _ => LogFilter::Ignore,
});

Structs§

NoopLogger
A noop log::Log that just ignores everything.
SentryLogger
Provides a dispatching logger.

Enums§

LogFilter
The action that Sentry should perform for a log::Metadata.
RecordMapping
The type of Data Sentry should ingest for a log::Record.

Functions§

breadcrumb_from_record
Creates a Breadcrumb from a given log::Record.
convert_log_level
Converts a log::Level to a Sentry Level, used for Event and Breadcrumb.
default_filter
The default log filter.
event_from_record
Creates an Event from a given log::Record.
exception_from_record
Creates an exception Event from a given log::Record.