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
Log a debug level message using current scope logger
Log a error level message using current scope logger
Log a info level message using current scope logger
Log a trace level message using current scope logger
Log a warning level message using current scope logger
Structs
Async logger drain that sends log messages to a background task.
Configuration for the logging crate.
Wrapper for the global logger guard.
Forground logger drain that logs to stderr.
Background logger drain to log to syslog.
Enums
Logging errors.
Traits
Local trait that can be used by the async logger.
Functions
Return a new global async logger.
Initialize the global logger context.
Return a new global sync logger.
Helper to derive log level from verbosity.