pub struct Client { /* private fields */ }Expand description
dontpanic library client.
Implementations§
Source§impl Client
impl Client
Sourcepub fn set_enabled(&self, enabled: bool)
pub fn set_enabled(&self, enabled: bool)
Sets the enabled state of the client. This is useful when using the same client instance across different environments.
By default the enabled state is true
use anyhow::Result;
fn main() -> Result<()> {
let dontpanic = dontpanic::builder("<PROJECT_API_KEY>").build()?;
// Enable in release builds only
dontpanic.set_enabled(!cfg!(debug_assertions));
Ok(())
}Sourcepub fn set_logger(&self, logger: impl Log + 'static) -> Result<(), Error>
Available on crate feature log only.
pub fn set_logger(&self, logger: impl Log + 'static) -> Result<(), Error>
log only.Register a Log implementor with this library, this sets it as the default logger. Works with any type that implements Log
See Available logging implementations in the log crate.
Example with env_logger:
fn main() {
let dontpanic = dontpanic::builder("<PROJECT_API_KEY>").build().unwrap()
// Important: call .build() not .init()
let logger = env_logger::Builder::from_default_env().build();
dontpanic.set_logger(logger)?;
log::info!("Luke, I am your father.");
panic!("Noooooo");
}Sourcepub fn tracing_layer(&self) -> TracingLayer
Available on crate feature tracing only.
pub fn tracing_layer(&self) -> TracingLayer
tracing only.Creates and returns a tracing Layer implementation.
Use with tracing_subscriber::registry to create a Layer stack and add this layer alongside your chosen tracing subscriber implementation.
Example with tracing_subscriber::fmt:
use tracing_subscriber::prelude::*;
fn main() {
let dontpanic = dontpanic::builder("<PROJECT_API_KEY>").build().unwrap()
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(dontpanic.tracing_layer())
.init();
log::info!("Mr. Stark, I don't feel so good");
panic!("Noooooo");
}Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more