lyte_observer/
lib.rs

1#[allow(unused_imports)]
2pub mod prelude {
3    pub mod crates {
4        pub use color_eyre;
5        pub use tracing;
6        pub use tracing_subscriber;
7    }
8    pub use super::{observe, observe_info, trace_crate};
9    pub use color_eyre::{Report, Result};
10    pub use crates::*;
11    pub use tracing::{debug, error, event, info, instrument, trace, warn, Instrument, Level};
12    pub type Error = Report;
13}
14
15pub use prelude::crates::*;
16use prelude::*;
17pub use prelude::{Error, Report, Result};
18
19#[instrument]
20/// This function is marked unsafe because it's very likely you do not want to
21/// do this.
22///
23/// Analagous to `observe("trace")`
24pub unsafe fn very_verbosely_trace_everything() -> Result<()> {
25    observe("trace")
26}
27
28#[instrument]
29/// Analagous to `observe("info")`
30pub fn observe_info() -> Result<()> {
31    observe("info")
32}
33
34#[instrument]
35/// Analagous to `observe(&format!("{}=trace,info", crate_name))`
36pub fn trace_crate(crate_name: &str) -> Result<()> {
37    observe(&format!("{}=trace,info", crate_name))
38}
39
40/// Sets up `color_eyre` and a basic logging tracing subscriber with the
41/// specified `filter_str`. Everything a growing application needs.
42#[instrument]
43pub fn observe(filter_str: &str) -> Result<()> {
44    color_eyre::install()?;
45
46    // I'm guessing a v2 of this lib will involve a builder or registry so that
47    // we can inject other subscribers for things like metrics exporters or file
48    // loggers as well.
49    let filter = tracing_subscriber::EnvFilter::builder()
50        .with_default_directive(<tracing_subscriber::filter::Directive>::from(
51            tracing::level_filters::LevelFilter::TRACE,
52        ))
53        .parse_lossy(filter_str);
54
55    tracing_subscriber::fmt()
56        // .pretty()
57        .with_env_filter(filter)
58        .init();
59
60    debug!("setup complete");
61
62    Ok(())
63}