Struct Journal

Source
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

Source

pub 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

Open 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>§

Source

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

Source

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.

Source

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.

Source

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().

Source

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()

Source

pub fn enumerate_data(&mut self) -> Result<Option<JournalEntryField<'_>>>

Obtain the next data

Corresponds to sd_journal_enumerate_data()

Source

pub fn display_entry_data(&mut self) -> DisplayEntryData<'_>

Obtain a display-able that display’s the current entrie’s fields

Source

pub fn next(&mut self) -> Result<u64>

Iterate over journal entries.

Corresponds to sd_journal_next()

Source

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()

Source

pub fn previous(&mut self) -> Result<u64>

Iterate in reverse over journal entries

Corresponds to sd_journal_previous()

Source

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()

Source

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.

Source

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.

Source

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().

Source

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.

Source

pub fn watch_all_elements<F>(&mut self, f: F) -> Result<()>
where F: FnMut(JournalRecord) -> Result<()>,

Iterate through all elements from the current cursor, then await the next entry(s) and wait again.

Source

pub fn seek_head(&mut self) -> Result<()>

Corresponds to sd_journal_seek_head()

Source

pub fn seek_tail(&mut self) -> Result<()>

Corresponds to sd_journal_seek_tail()

Source

pub fn seek_monotonic_usec(&mut self, boot_id: Id128, usec: u64) -> Result<()>

Corresponds to sd_journal_seek_monotonic_usec()

Source

pub fn seek_realtime_usec(&mut self, usec: u64) -> Result<()>

Corresponds to sd_journal_seek_realtime_usec()

Source

pub fn seek_cursor<A: CStrArgument>(&mut self, cursor: A) -> Result<()>

Corresponds to sd_journal_seek_cursor()

Source

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.

Source

pub fn cursor(&self) -> Result<String>

Returns the cursor of current journal entry.

Source

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().

Source

pub fn timestamp(&self) -> Result<SystemTime>

Returns timestamp at which current journal entry was recorded.

Source

pub fn monotonic_timestamp(&self) -> Result<(u64, Id128)>

Returns monotonic timestamp and boot ID at which current journal entry was recorded.

Source

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.

Source

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.

Source

pub fn match_or(&mut self) -> Result<&mut JournalRef>

Inserts a disjunction (i.e. logical OR) in the match list.

Source

pub fn match_and(&mut self) -> Result<&mut JournalRef>

Inserts a conjunction (i.e. logical AND) in the match list.

Source

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.

Trait Implementations§

Source§

impl AsMut<JournalRef> for Journal

Source§

fn as_mut(&mut self) -> &mut JournalRef

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<JournalRef> for Journal

Source§

fn as_ref(&self) -> &JournalRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<JournalRef> for Journal

Source§

fn borrow(&self) -> &JournalRef

Immutably borrows from an owned value. Read more
Source§

impl BorrowMut<JournalRef> for Journal

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl Deref for Journal

Source§

type Target = JournalRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &JournalRef

Dereferences the value.
Source§

impl DerefMut for Journal

Source§

fn deref_mut(&mut self) -> &mut JournalRef

Mutably dereferences the value.
Source§

impl Drop for Journal

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ForeignType for Journal

Source§

type CType = sd_journal

The raw C type.
Source§

type Ref = JournalRef

The type representing a reference to this type.
Source§

unsafe fn from_ptr(ptr: *mut sd_journal) -> Journal

Constructs an instance of this type from its raw type. Read more
Source§

fn as_ptr(&self) -> *mut sd_journal

Returns a raw pointer to the wrapped value.
Source§

fn into_ptr(self) -> *mut Self::CType

Consumes the wrapper and returns the raw pointer.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.