pub struct JournalLog<K: AsRef<str>, V: AsRef<str>> { /* private fields */ }
Expand description

A systemd journal logger.

Implementations§

source§

impl<K: AsRef<str>, V: AsRef<str>> JournalLog<K, V>

source

pub fn with_extra_fields<KK: AsRef<str>, VV: AsRef<str>>( self, extra_fields: Vec<(KK, VV)> ) -> JournalLog<KK, VV>

Set extra fields to be added to every log entry.

Journal fields

extra_fields is a sequence of key value pairs to add as extra fields to every log entry logged through the new logger. The extra fields will be appended to the standard journal fields written by the logger.

Restrictions on field names

Each key in the sequence must be a valid journal field name, i.e. contain only uppercase alphanumeric characters and the underscore, and it must not start with an underscore.

Invalid keys in extra_fields are escaped with escape_journal_key, which transforms them to ASCII uppercase and replaces all invalid characters with underscores.

extra_fields should not contain any of the journal fields already added by this logger; while journald supports multiple values for a field journald clients may not handle unexpected multi-value fields properly and likely show only the first value. Specifically even journalctl will only shouw the first MESSAGE value of journal entries.

See the crate documentation at crate for details about the standard journal fields this logger uses.

Restrictions on values

There are no restrictions on the value.

source

pub fn with_syslog_identifier(self, identifier: String) -> Self

Set the given syslog identifier for this logger.

The logger writes this string in the SYSLOG_IDENTIFIER field, which can be filtered for with journalctl -t.

Use current_exe_identifier() to obtain the standard identifier for the current executable.

source

pub fn journal_send(&self, record: &Record<'_>) -> Result<(), SdError>

Send a single log record to the journal.

Extract the standard fields from record (see crate documentation), and append all extra_fields; the send the resulting fields to the systemd journal with libsystemd::logging::journal_send and return the result of that function.

source§

impl<K, V> JournalLog<K, V>where K: AsRef<str> + Send + Sync + 'static, V: AsRef<str> + Send + Sync + 'static,

source

pub fn install(self) -> Result<(), SetLoggerError>

Install this logger globally.

See log::set_boxed_logger.

source§

impl JournalLog<String, String>

source

pub fn empty() -> Self

Create an empty journal log instance, with no extra fields and no syslog identifier.

Trait Implementations§

source§

impl Default for JournalLog<String, String>

source§

fn default() -> Self

Create a journal logger with no extra fields and a syslog identifier obtained with current_exe_identifier().

If current_exe_identifier() fails use no syslog identifier.

source§

impl<K, V> Log for JournalLog<K, V>where K: AsRef<str> + Sync + Send, V: AsRef<str> + Sync + Send,

The Log interface for JournalLog.

source§

fn enabled(&self, _metadata: &Metadata<'_>) -> bool

Whether this logger is enabled.

Always returns true.

source§

fn log(&self, record: &Record<'_>)

Send the given record to the systemd journal.

Errors

Panic if sending the record to journald fails, i.e. if journald is not running.

See JournalLog::journal_send for a function which returns any error which might have occurred while sending the record to the journal.

source§

fn flush(&self)

Flush log records.

A no-op for journal logging.

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for JournalLog<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for JournalLog<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for JournalLog<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for JournalLog<K, V>where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for JournalLog<K, V>where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.