Struct systemd_journal_logger::JournalLog
source · 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>
impl<K: AsRef<str>, V: AsRef<str>> JournalLog<K, V>
sourcepub fn with_extra_fields<KK: AsRef<str>, VV: AsRef<str>>(
self,
extra_fields: Vec<(KK, VV)>
) -> JournalLog<KK, VV>
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.
sourcepub fn with_syslog_identifier(self, identifier: String) -> Self
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.
sourcepub fn journal_send(&self, record: &Record<'_>) -> Result<(), SdError>
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.
Trait Implementations§
source§impl Default for JournalLog<String, String>
impl Default for JournalLog<String, String>
source§fn default() -> Self
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,
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
fn enabled(&self, _metadata: &Metadata<'_>) -> bool
Whether this logger is enabled.
Always returns true
.
source§fn log(&self, record: &Record<'_>)
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.