Skip to main content

ckb_sentry_log/
lib.rs

1//! Adds support for automatic Breadcrumb and Event capturing from logs.
2//!
3//! The `log` crate is supported in two ways. First, logs can be captured as
4//! breadcrumbs for later. Secondly, error logs can be captured as events to
5//! Sentry. By default anything above `Info` is recorded as breadcrumb and
6//! anything above `Error` is captured as error event.
7//!
8//! # Examples
9//!
10//! ```
11//! use ckb_sentry_log as sentry_log;
12//!
13//! let mut log_builder = pretty_env_logger::formatted_builder();
14//! log_builder.parse_filters("info");
15//! let logger = sentry_log::SentryLogger::with_dest(log_builder.build());
16//!
17//! log::set_boxed_logger(Box::new(logger)).unwrap();
18//! log::set_max_level(log::LevelFilter::Info);
19//!
20//! let _sentry = sentry::init(());
21//!
22//! log::info!("Generates a breadcrumb");
23//! log::error!("Generates an event");
24//! ```
25//!
26//! Or one might also set an explicit filter, to customize how to treat log
27//! records:
28//!
29//! ```
30//! use ckb_sentry_log as sentry_log;
31//!
32//! use sentry_log::LogFilter;
33//!
34//! let logger = sentry_log::SentryLogger::new().filter(|md| match md.level() {
35//!     log::Level::Error => LogFilter::Event,
36//!     _ => LogFilter::Ignore,
37//! });
38//! ```
39
40#![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")]
41#![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")]
42#![warn(missing_docs)]
43
44mod converters;
45mod logger;
46
47pub use converters::*;
48pub use logger::*;