Crate systemd_journal_logger[][src]

Expand description

A log logger for the systemd journal.

Usage

Use init at the beginning of your main function to setup journal logging, configure the logging level and then use the standard macros from the log crate to send log messages to the systemd journal:

use log::{info, warn, error, LevelFilter};

systemd_journal_logger::init().unwrap();
log::set_max_level(LevelFilter::Info);

info!("hello log");
warn!("warning");
error!("oops");

Journal fields

The journald logger always sets the following standard journal fields

  • PRIORITY: The log level mapped to a priority (see below).
  • MESSAGE: The formatted log message (see log::Record::args()).
  • SYSLOG_IDENTIFIER: The short name of the running process, i.e. the file name of std::env::current_exe() if successful.
  • SYSLOG_PID: The PID of the running process (see std::process::id()).
  • CODE_FILE: The filename the log message originates from (see log::Record::file(), only if present).
  • CODE_LINE: The line number the log message originates from (see log::Record::line(), only if present).

Additionally it also adds the following non-standard fields:

Log levels and priorities

The journal logger maps log::Level to journal priorities as follows:

Structs

JournalLog

A systemd journal logger.

Statics

LOG

The static instance of systemd journal logger.

Functions

init

Initialize journal logging.