1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
//! 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`. //! //! *NOTE*: This integration currently does not process any `slog::KV` pairs, //! but support for this will be added in the future. //! //! # Examples //! //! ``` //! use ckb_sentry_slog as sentry_slog; //! //! use sentry::{init, ClientOptions}; //! use sentry_slog::SentryDrain; //! //! let _sentry = sentry::init(()); //! //! let drain = SentryDrain::new(slog::Discard); //! let root = slog::Logger::root(drain, slog::o!()); //! //! # let events = sentry::test::with_captured_events(|| { //! slog::info!(root, "recorded as breadcrumb"); //! slog::warn!(root, "recorded as regular event"); //! # }); //! # let captured_event = events.into_iter().next().unwrap(); //! //! 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") //! ); //! //! # let events = sentry::test::with_captured_events(|| { //! slog::crit!(root, "recorded as exception event"); //! # }); //! # let captured_event = events.into_iter().next().unwrap(); //! //! assert_eq!(captured_event.exception.len(), 1); //! ``` //! //! The Drain can also be customized with a `filter`, and a `mapper`: //! //! ``` //! use ckb_sentry_slog as sentry_slog; //! //! use sentry_slog::{exception_from_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(exception_from_record(record, kv)) //! } //! _ => RecordMapping::Ignore, //! }); //! ``` //! //! When a `mapper` is specified, a corresponding `filter` should also be //! provided. //! //! [`SentryDrain`]: struct.SentryDrain.html #![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")] #![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")] #![warn(missing_docs)] #![deny(unsafe_code)] mod converters; mod drain; pub use converters::*; pub use drain::{default_filter, LevelFilter, RecordMapping, SentryDrain};