Macro woodpecker::wp_register_handler
[−]
[src]
macro_rules! wp_register_handler { ($handler:expr) => { ... }; }
Registers a log record handler.
The handler takes a log record as an argument and pushes it into a custom sink.
By default if no log handler is registered woodpecker
emits
log records into stdout
.
If at least one handler is registered than the stdout
handler
must be registered explicitly if it's still desired.
See the definition of the Handler
type for the details.
Example
In this example string "foo" will be logged three times into stdout
but only one caught by the log handler.
#[macro_use] extern crate woodpecker; use woodpecker as wp; use std::sync::{Arc, Mutex}; use std::ops::Deref; fn main() { wp_init!(); warn!("foo"); let out = Arc::new(Mutex::new(String::new())); { wp_register_handler!(wp::handlers::stdout::handler()); warn!("foo"); let out = out.clone(); wp_register_handler!(Box::new(move |record| { out.lock().unwrap().push_str(record.msg().deref()); })); warn!("foo"); } if cfg!(feature = "test-thread-log") { wp::sync(); } assert_eq!(*out.lock().unwrap(), "foo".to_string()); }