Skip to main content

Log

Struct Log 

Source
pub struct Log { /* private fields */ }
Expand description

Tracks rotation state for size and count limits.

Implementations§

Source§

impl Log

Source

pub fn new(path: &Path, config: Config) -> Result<Log, WriterError>

Creates a new journal log.

Source

pub fn new_with_lifecycle_observer( path: &Path, config: Config, observer: Arc<dyn LogLifecycleObserver>, ) -> Result<Log, WriterError>

Source

pub fn new_with_hooks( path: &Path, config: Config, observer: Option<Arc<dyn LogLifecycleObserver>>, artifact_sizer: Option<Arc<dyn LogArtifactSizer>>, ) -> Result<Log, WriterError>

Source

pub fn with_lifecycle_observer( self, observer: Arc<dyn LogLifecycleObserver>, ) -> Log

Source

pub fn with_artifact_sizer(self, sizer: Arc<dyn LogArtifactSizer>) -> Log

Source

pub fn write_entry( &mut self, items: &[&[u8]], source_realtime_usec: Option<u64>, ) -> Result<(), WriterError>

Writes a journal entry.

If source_realtime_usec is provided, a _SOURCE_REALTIME_TIMESTAMP field will be added to record the original timestamp from the source (in microseconds since Unix epoch). This is useful when ingesting logs from external sources that have their own timestamps.

Source

pub fn write_entry_with_timestamps( &mut self, items: &[&[u8]], timestamps: EntryTimestamps, ) -> Result<(), WriterError>

Writes a journal entry with optional source and entry timestamp overrides.

Overrides are safe by construction:

  • entry realtime is clamped to strict monotonic progression (last + 1us floor)
  • entry monotonic is also clamped to strict monotonic progression (last + 1us floor)
Source

pub fn write_fields( &mut self, fields: &[StructuredField<'_>], source_realtime_usec: Option<u64>, ) -> Result<(), WriterError>

Writes a journal entry from structured field names and binary-safe values.

This is the preferred path when the producer already has split field names and values. If source_realtime_usec is provided, a _SOURCE_REALTIME_TIMESTAMP field is added.

Source

pub fn write_fields_with_timestamps( &mut self, fields: &[StructuredField<'_>], timestamps: EntryTimestamps, ) -> Result<(), WriterError>

Writes structured fields with optional source and entry timestamp overrides.

Entry realtime and monotonic overrides use the same monotonic clamping rules as Log::write_entry_with_timestamps.

Source

pub fn write_fields_with_options( &mut self, fields: &[StructuredField<'_>], timestamps: EntryTimestamps, options: EntryWriteOptions, ) -> Result<(), WriterError>

Writes structured fields with explicit low-level entry write options.

Use this only when the caller can satisfy any invariants required by the selected EntryWriteOptions, especially no duplicate full KEY=value payloads when trusted_unique_payloads is enabled.

Source

pub fn sync(&mut self) -> Result<(), WriterError>

Syncs all written data to disk, ensuring durability.

This should be called after writing a batch of log entries to ensure they are persisted to disk before acknowledging the request.

Source

pub fn close(self) -> Result<(), WriterError>

Archives and closes the active file.

In strict systemd naming mode this renames <source>.journal to the chain filename before retention, matching the explicit close behavior of the other SDK implementations. Drop remains best-effort for callers that do not explicitly close.

Source

pub fn active_file(&self) -> Option<&File>

Source

pub fn active_path(&self) -> Option<&Path>

Source

pub fn configured_directory(&self) -> &Path

Source

pub fn journal_directory(&self) -> &Path

Source

pub fn machine_id(&self) -> Uuid

Source

pub fn boot_id(&self) -> Uuid

Source

pub fn source(&self) -> &Source

Source

pub fn enforce_retention(&mut self) -> Result<(), WriterError>

Applies the configured retention policy without requiring a rotation or close. The current active file is counted in retention envelopes and is protected from deletion.

Trait Implementations§

Source§

impl Drop for Log

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Freeze for Log

§

impl !RefUnwindSafe for Log

§

impl !Sync for Log

§

impl !UnwindSafe for Log

§

impl Send for Log

§

impl Unpin for Log

§

impl UnsafeUnpin for Log

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more