Crate privsep_log[−][src]
Expand description
Simple async logging crate inspired by OpenBSD’s log.c
.
Examples
The logger is typically started from the programs’s main function:
let _guard = privsep_log::sync_logger("test", true).unwrap(); info!("Started");
The async logger is provided to run inside of a tokio
runtime.
use privsep_log::info; #[tokio::main] async fn main() { let _guard = privsep_log::async_logger("test", true).await.unwrap(); info!("Started"); }
The sync_logger
and async_logger
functions take two arguments:
the name of the program and the options, an arbitrary variable
that implements Into<Config>
. A simple boolean can be passed to
indicate if logging should happen in foreground via standard error
output or in the background via syslog; this is identical to
passing the Config
struct with the foreground
option:
// Lazily initialize the default logger. privsep_log::init(); // Parse configuration or command-line options... let args = std::env::args().collect::<Vec<_>>(); debug!("Reading configuration..."); let config = Config { foreground: false, ..Default::default() }; let name = &args[0]; // Now start the background logger. let _guard = privsep_log::sync_logger(name, config).unwrap(); info!("Started");
Macros
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
Async | Async logger drain that sends log messages to a background task. |
Config | Configuration for the logging crate. |
LoggerGuard | Wrapper for the global logger guard. |
Stderr | Forground logger drain that logs to stderr. |
Syslog | Background logger drain to log to syslog. |
Enums
Error | Logging errors. |
Traits
Target | Local trait that can be used by the async logger. |
Functions
async_logger | Return a new global async logger. |
init | Initialize the global logger context. |
sync_logger | Return a new global sync logger. |
verbose | Helper to derive log level from verbosity. |