Crate privsep_log[][src]

Expand description

Simple async logging crate inspired by OpenBSD’s log.c.


The logger is typically started from the programs’s main function:

let _guard = privsep_log::sync_logger("test", true).unwrap();


The async logger is provided to run inside of a tokio runtime.

use privsep_log::info;

async fn main() {
    let _guard = privsep_log::async_logger("test", true).await.unwrap();


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.

// Parse configuration or command-line options...
let args = std::env::args().collect::<Vec<_>>();

debug!("Reading configuration...");
let config = Config {
    foreground: false,
let name = &args[0];

// Now start the background logger.
let _guard = privsep_log::sync_logger(name, config).unwrap();



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


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.


Logging errors.


Local trait that can be used by the async logger.


Return a new global async logger.

Initialize the global logger context.

Return a new global sync logger.

Helper to derive log level from verbosity.