pub struct Log { /* private fields */ }Expand description
Tracks rotation state for size and count limits.
Implementations§
Source§impl Log
impl Log
pub fn new_with_lifecycle_observer( path: &Path, config: Config, observer: Arc<dyn LogLifecycleObserver>, ) -> Result<Log, WriterError>
pub fn new_with_hooks( path: &Path, config: Config, observer: Option<Arc<dyn LogLifecycleObserver>>, artifact_sizer: Option<Arc<dyn LogArtifactSizer>>, ) -> Result<Log, WriterError>
pub fn with_lifecycle_observer( self, observer: Arc<dyn LogLifecycleObserver>, ) -> Log
pub fn with_artifact_sizer(self, sizer: Arc<dyn LogArtifactSizer>) -> Log
Sourcepub fn write_entry(
&mut self,
items: &[&[u8]],
source_realtime_usec: Option<u64>,
) -> Result<(), WriterError>
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.
Sourcepub fn write_entry_with_timestamps(
&mut self,
items: &[&[u8]],
timestamps: EntryTimestamps,
) -> Result<(), WriterError>
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 + 1usfloor) - entry monotonic is also clamped to strict monotonic progression (
last + 1usfloor)
Sourcepub fn write_fields(
&mut self,
fields: &[StructuredField<'_>],
source_realtime_usec: Option<u64>,
) -> Result<(), WriterError>
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.
Sourcepub fn write_fields_with_timestamps(
&mut self,
fields: &[StructuredField<'_>],
timestamps: EntryTimestamps,
) -> Result<(), WriterError>
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.
Sourcepub fn write_fields_with_options(
&mut self,
fields: &[StructuredField<'_>],
timestamps: EntryTimestamps,
options: EntryWriteOptions,
) -> Result<(), WriterError>
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.
Sourcepub fn sync(&mut self) -> Result<(), WriterError>
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.
Sourcepub fn close(self) -> Result<(), WriterError>
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.
pub fn active_file(&self) -> Option<&File>
pub fn active_path(&self) -> Option<&Path>
pub fn configured_directory(&self) -> &Path
pub fn journal_directory(&self) -> &Path
pub fn machine_id(&self) -> Uuid
pub fn boot_id(&self) -> Uuid
pub fn source(&self) -> &Source
Sourcepub fn enforce_retention(&mut self) -> Result<(), WriterError>
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.