mio
.
log
has it's own set of cargo features to control compile time logging level
stdlog
global logger handler is set only for old-style log
crate logging
log
crate) through that given logger. Just like you would do it with slog
info!(that_global_logger, "something")
.
slog-scope
instead of you want to avoid passing a Logger
instances around.
#[macro_use(o, slog_log, slog_debug, slog_info, slog_warn, slog_error, slog_trace)]
extern crate slog;
#[macro_use]
extern crate slog_scope;
extern crate slog_term;
use slog::{Level, DrainExt};
fn main() {
let drain = slog_term::streamer().stderr().build();
let d = slog::level_filter(Level::Trace, drain);
let log = slog::Logger::root(d.fuse(), o!());
slog_scope::set_global_logger(log);
slog_scope::scope(slog_scope::logger().new(o!()), foo);
}
fn foo() {
error!("error {}", "I am foo");
warn!("warn {}", "I am foo");
info!("info {}", "I am foo");
debug!("debug {}", "I am foo");
trace!("trace {}", "I am foo");
}
impl Drain for FileDrain {
type Ok = ();
type Err = Never;
fn log(&self, record: &Record, _: &OwnedKVList) -> ::std::result::Result<(), Never> {
if let Ok(mut log_file) = self.file.try_clone() {
match writeln!(log_file, "{}", record.msg()) {
Ok(()) => {}
Err(_e) => {}
}
}
Ok(())
}
}
RefCell
in such drain.
Logger
you'll have to synchronize it: wrap it in logger that wil make it Sync
. Eg. slog_async::Async
or Mutex
.
Mutex<D : Drain>
implements Drain