pub struct Journal(/* private fields */);
Expand description
A reader for systemd journal.
Supports read, next, previous, and seek operations.
Note that the Journal
is not Send
nor Sync
: it cannot be used in any thread other
than the one which creates it.
Implementations§
Source§impl Journal
impl Journal
Sourcepub fn open(
files: JournalFiles,
runtime_only: bool,
local_only: bool,
) -> Result<Journal>
👎Deprecated since 0.8.0: Use OpenOptions
instead. It removes the blind boolean options, and allows complete specification of the selected/filtered files
pub fn open( files: JournalFiles, runtime_only: bool, local_only: bool, ) -> Result<Journal>
OpenOptions
instead. It removes the blind boolean options, and allows complete specification of the selected/filtered filesOpen a Journal
corresponding to files
for reading
If the calling process doesn’t have permission to read the system journal, a call to
Journal::open
with System
or All
will succeed, but system journal entries won’t be
included. This behavior is due to systemd.
If runtime_only
is true, include only journal entries from the current boot. If false,
include all entries.
If local_only
is true, include only journal entries originating from localhost. If false,
include all entries.
Methods from Deref<Target = JournalRef>§
Sourcepub fn fd(&self) -> Result<c_int>
pub fn fd(&self) -> Result<c_int>
Returns a file descriptor a file descriptor that may be asynchronously polled in an external event loop and is signaled as soon as the journal changes, because new entries or files were added, rotation took place, or files have been deleted, and similar. The file descriptor is suitable for usage in poll(2).
This corresponds to sd_journal_get_fd
Sourcepub fn data_threshold(&mut self) -> Result<usize>
pub fn data_threshold(&mut self) -> Result<usize>
Fields that are longer that this number of bytes may be truncated when retrieved by this Journal
instance.
Use [set_data_threshold()
] to adjust.
Sourcepub fn set_data_threshold(&mut self, new_theshold: usize) -> Result<()>
pub fn set_data_threshold(&mut self, new_theshold: usize) -> Result<()>
Set the number of bytes after which returned fields may be truncated when retrieved by
this Journal
instance.
Setting this as small as possible for your application can allow the library to avoid decompressing large objects in full.
Sourcepub fn get_data<A: CStrArgument>(
&mut self,
field: A,
) -> Result<Option<JournalEntryField<'_>>>
pub fn get_data<A: CStrArgument>( &mut self, field: A, ) -> Result<Option<JournalEntryField<'_>>>
Get the data associated with a particular field from the current journal entry
Note that this may be affected by the current data threshold, see data_threshold()
and
set_data_threshold()
.
Note: the use of &mut
here is because calls to some (though not all) other journal
functions can invalidate the reference returned within JournalEntryField
. In particular:
any other obtaining of data (enumerate, etc) or any adjustment of the read pointer
(seeking, etc) invalidates the returned reference.
Corresponds to sd_journal_get_data()
.
Sourcepub fn restart_data(&mut self)
pub fn restart_data(&mut self)
Restart the iteration done by [enumerate_data()
] and [enumerate_avaliable_data()
] over
fields of the current entry.
Corresponds to sd_journal_restart_data()
Sourcepub fn enumerate_data(&mut self) -> Result<Option<JournalEntryField<'_>>>
pub fn enumerate_data(&mut self) -> Result<Option<JournalEntryField<'_>>>
Obtain the next data
Corresponds to sd_journal_enumerate_data()
Sourcepub fn display_entry_data(&mut self) -> DisplayEntryData<'_>
pub fn display_entry_data(&mut self) -> DisplayEntryData<'_>
Obtain a display-able that display’s the current entrie’s fields
Sourcepub fn next(&mut self) -> Result<u64>
pub fn next(&mut self) -> Result<u64>
Iterate over journal entries.
Corresponds to sd_journal_next()
Sourcepub fn next_skip(&mut self, skip_count: u64) -> Result<u64>
pub fn next_skip(&mut self, skip_count: u64) -> Result<u64>
Iterate over journal entries, skipping skip_count
of them
Corresponds to sd_journal_next_skip()
Sourcepub fn previous(&mut self) -> Result<u64>
pub fn previous(&mut self) -> Result<u64>
Iterate in reverse over journal entries
Corresponds to sd_journal_previous()
Sourcepub fn previous_skip(&mut self, skip_count: u64) -> Result<usize>
pub fn previous_skip(&mut self, skip_count: u64) -> Result<usize>
Iterate in reverse over journal entries, skipping skip_count
of them.
Corresponds to sd_journal_previous_skip()
Sourcepub fn next_entry(&mut self) -> Result<Option<JournalRecord>>
pub fn next_entry(&mut self) -> Result<Option<JournalRecord>>
Read the next entry from the journal. Returns Ok(None)
if there
are no more entries to read.
Sourcepub fn previous_entry(&mut self) -> Result<Option<JournalRecord>>
pub fn previous_entry(&mut self) -> Result<Option<JournalRecord>>
Read the previous entry from the journal. Returns Ok(None)
if there
are no more entries to read.
Sourcepub fn wait(&mut self, wait_time: Option<Duration>) -> Result<JournalWaitResult>
pub fn wait(&mut self, wait_time: Option<Duration>) -> Result<JournalWaitResult>
Wait for next entry to arrive.
Using a wait_time
of None
will wait for an unlimited period for new entries.
Corresponds to sd_journal_wait()
.
Sourcepub fn await_next_entry(
&mut self,
wait_time: Option<Duration>,
) -> Result<Option<JournalRecord>>
pub fn await_next_entry( &mut self, wait_time: Option<Duration>, ) -> Result<Option<JournalRecord>>
Wait for the next entry to appear. Returns Ok(None)
if there were no
new entries in the given wait time.
Pass wait_time None
to wait for an unlimited period for new entries.
Sourcepub fn watch_all_elements<F>(&mut self, f: F) -> Result<()>
pub fn watch_all_elements<F>(&mut self, f: F) -> Result<()>
Iterate through all elements from the current cursor, then await the next entry(s) and wait again.
Sourcepub fn seek_monotonic_usec(&mut self, boot_id: Id128, usec: u64) -> Result<()>
pub fn seek_monotonic_usec(&mut self, boot_id: Id128, usec: u64) -> Result<()>
Corresponds to sd_journal_seek_monotonic_usec()
Sourcepub fn seek_realtime_usec(&mut self, usec: u64) -> Result<()>
pub fn seek_realtime_usec(&mut self, usec: u64) -> Result<()>
Corresponds to sd_journal_seek_realtime_usec()
Sourcepub fn seek_cursor<A: CStrArgument>(&mut self, cursor: A) -> Result<()>
pub fn seek_cursor<A: CStrArgument>(&mut self, cursor: A) -> Result<()>
Corresponds to sd_journal_seek_cursor()
Sourcepub fn seek(&mut self, seek: JournalSeek) -> Result<()>
pub fn seek(&mut self, seek: JournalSeek) -> Result<()>
Seek to a specific position in journal using a general JournalSeek
Note: after seeking, this Journal
does not refer to any entry (and consequently can not
obtain information about an entry, like [cursor()
], etc). Use the iteration functions
([next()
], [previous()
], [next_skip()
], and [previous_skip()
]) to move onto an
entry.
Sourcepub fn test_cursor<A: CStrArgument>(&self, cursor: A) -> Result<bool>
pub fn test_cursor<A: CStrArgument>(&self, cursor: A) -> Result<bool>
Test if a given cursor matches the current postition in the journal
Corresponds to sd_journal_test_cursor()
.
Sourcepub fn timestamp(&self) -> Result<SystemTime>
pub fn timestamp(&self) -> Result<SystemTime>
Returns timestamp at which current journal entry was recorded.
Sourcepub fn monotonic_timestamp(&self) -> Result<(u64, Id128)>
pub fn monotonic_timestamp(&self) -> Result<(u64, Id128)>
Returns monotonic timestamp and boot ID at which current journal entry was recorded.
Sourcepub fn monotonic_timestamp_current_boot(&self) -> Result<u64>
pub fn monotonic_timestamp_current_boot(&self) -> Result<u64>
Returns monotonic timestamp at which current journal entry was recorded. Returns an error if the current entry is not from the current system boot.
Sourcepub fn match_add<T: Into<Vec<u8>>>(
&mut self,
key: &str,
val: T,
) -> Result<&mut JournalRef>
pub fn match_add<T: Into<Vec<u8>>>( &mut self, key: &str, val: T, ) -> Result<&mut JournalRef>
Adds a match by which to filter the entries of the journal. If a match is applied, only entries with this field set will be iterated.
Sourcepub fn match_or(&mut self) -> Result<&mut JournalRef>
pub fn match_or(&mut self) -> Result<&mut JournalRef>
Inserts a disjunction (i.e. logical OR) in the match list.
Sourcepub fn match_and(&mut self) -> Result<&mut JournalRef>
pub fn match_and(&mut self) -> Result<&mut JournalRef>
Inserts a conjunction (i.e. logical AND) in the match list.
Sourcepub fn match_flush(&mut self) -> Result<&mut JournalRef>
pub fn match_flush(&mut self) -> Result<&mut JournalRef>
Flushes all matches, disjunction and conjunction terms. After this call all filtering is removed and all entries in the journal will be iterated again.