Macro woodpecker::wp_init
[−]
[src]
macro_rules! wp_init { () => { ... }; ($config:expr) => { ... }; }
Initializes the crate's kitchen.
An optional parameter may be passed to define initial logging configuration.
Takes into account RUST_LOG
environment variable
which must conform to the spec.
The WP_LOG_THREAD
environment variable overrides the passed configuration.
Example
#[macro_use] extern crate woodpecker; use woodpecker as wp; fn main() { wp_init!(); wp_set_level!(wp::LogLevel::INFO).unwrap(); info!("Coucou!"); }
If log thread is activated consider using sync to ensure that all log records are properly flushed.
Example
#[macro_use] extern crate woodpecker; use woodpecker as wp; use std::sync::{Arc, Mutex}; use std::ops::Deref; fn main() { wp_init!(wp::Config { thread: true, ..Default::default() }); let out = Arc::new(Mutex::new(String::new())); { let out = out.clone(); wp_register_handler!(Box::new(move |record| { out.lock().unwrap().push_str(record.msg().deref()); })); warn!("foo"); } wp::sync(); assert_eq!(*out.lock().unwrap(), "foo".to_string()); }