sentry_log/lib.rs
1//! Adds support for automatic Breadcrumb, Event, and Log capturing from `log` records.
2//!
3//! The `log` crate is supported in three ways:
4//! - Records can be captured as Sentry events. These are grouped and show up in the Sentry
5//! [issues](https://docs.sentry.io/product/issues/) page, representing high severity issues to be
6//! acted upon.
7//! - Records can be captured as [breadcrumbs](https://docs.sentry.io/product/issues/issue-details/breadcrumbs/).
8//! Breadcrumbs create a trail of what happened prior to an event, and are therefore sent only when
9//! an event is captured, either manually through e.g. `sentry::capture_message` or through integrations
10//! (e.g. the panic integration is enabled (default) and a panic happens).
11//! - Records can be captured as traditional [logs](https://docs.sentry.io/product/explore/logs/)
12//! Logs can be viewed and queried in the Logs explorer.
13//!
14//! By default anything above `Info` is recorded as a breadcrumb and
15//! anything above `Error` is captured as error event.
16//!
17//! To capture records as Sentry logs:
18//! 1. Enable the `logs` feature of the `sentry` crate.
19//! 2. Initialize the SDK with `enable_logs: true` in your client options.
20//! 3. Set up a custom filter (see below) to map records to logs (`LogFilter::Log`) based on criteria such as severity.
21//!
22//! # Examples
23//!
24//! ```
25//! let mut log_builder = pretty_env_logger::formatted_builder();
26//! log_builder.parse_filters("info");
27//! let logger = sentry_log::SentryLogger::with_dest(log_builder.build());
28//!
29//! log::set_boxed_logger(Box::new(logger)).unwrap();
30//! log::set_max_level(log::LevelFilter::Info);
31//!
32//! let _sentry = sentry::init(());
33//!
34//! log::info!("Generates a breadcrumb");
35//! log::error!("Generates an event");
36//! ```
37//!
38//! Or one might also set an explicit filter, to customize how to treat log
39//! records:
40//!
41//! ```
42//! use sentry_log::LogFilter;
43//!
44//! let logger = sentry_log::SentryLogger::new().filter(|md| match md.level() {
45//! log::Level::Error => LogFilter::Event,
46//! _ => LogFilter::Ignore,
47//! });
48//! ```
49
50#![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")]
51#![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")]
52#![warn(missing_docs)]
53
54mod converters;
55mod logger;
56
57pub use converters::*;
58pub use logger::*;