Crate slog_scope [−] [src]
Logging scopes for slog-rs
Logging scopes are convinience functionality for slog-rs to free user from manually passing
Logger
objects around.
Set of macros is also provided as an alternative to original slog
crate macros, for logging
directly to Logger
of the current logging scope.
Note: Part of a slog
logging philosophy is ability to freely express logging contexts
according to logical structure, rather than code structure. By using logging scopes the logging
context is tied to code flow again, which is less expressive.
It is generally advised NOT to use slog_scope
in libraries. Read more in
slog-rs FAQ
#[macro_use(slog_o, slog_info, slog_log, slog_record, slog_record_static, slog_b, slog_kv)] extern crate slog; #[macro_use] extern crate slog_scope; extern crate slog_term; use slog::Drain; fn foo() { slog_info!(slog_scope::logger(), "foo"); info!("foo"); // Same as above, but more ergonomic. } fn main() { let plain = slog_term::PlainSyncDecorator::new(std::io::stdout()); let log = slog::Logger::root( slog_term::FullFormat::new(plain) .build().fuse(), slog_o!() ); slog_scope::set_global_logger(log); slog_scope::scope(slog_scope::logger().new(slog_o!("scope" => "1")), || foo() ); }
Macros
crit |
Log a critical level message using current scope logger |
debug |
Log a debug level message using current scope logger |
error |
Log a error level message using current scope logger |
info |
Log a info level message using current scope logger |
trace |
Log a trace level message using current scope logger |
warn |
Log a warning level message using current scope logger |
Structs
GlobalLoggerGuard |
Guard resetting global logger |
Functions
logger |
Access the |
scope |
Execute code in a logging scope |
set_global_logger |
Set global |