journal_log_writer/lib.rs
1//! High-level journal log writer with rotation and retention policies
2//!
3//! This crate provides a high-level interface for writing to systemd journal files
4//! in a directory, with automatic rotation and retention management.
5//!
6//! ## Usage
7//!
8//! ```no_run
9//! use journal_log_writer::{Config, EntryTimestamps, Log, RotationPolicy, RetentionPolicy};
10//! use journal_registry::Origin;
11//! use std::path::Path;
12//!
13//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
14//! // Configure rotation and retention policies
15//! let rotation = RotationPolicy::default()
16//! .with_size_of_journal_file(100 * 1024 * 1024); // 100 MB per file
17//!
18//! let retention = RetentionPolicy::default()
19//! .with_number_of_journal_files(10); // Keep 10 files max
20//!
21//! let origin = Origin {
22//! machine_id: Some("00112233445566778899aabbccddeeff".parse()?),
23//! namespace: None,
24//! source: journal_registry::Source::System,
25//! };
26//!
27//! let config = Config::new(origin, rotation, retention)
28//! .with_boot_id("ffeeddccbbaa99887766554433221100".parse()?);
29//!
30//! // Create a log writer
31//! let mut log = Log::new(Path::new("/var/log/myapp"), config)?;
32//!
33//! // Write entries
34//! let entry = [
35//! b"MESSAGE=Hello, journal!" as &[u8],
36//! b"PRIORITY=6",
37//! ];
38//! let timestamps = EntryTimestamps::default()
39//! .with_entry_realtime_usec(1_700_000_000_000_000)
40//! .with_entry_monotonic_usec(1);
41//! log.write_entry_with_timestamps(&entry, timestamps)?;
42//! log.sync()?;
43//! # Ok(())
44//! # }
45//! ```
46
47mod error;
48mod log;
49
50pub use error::{Result, WriterError};
51pub use journal_core::file::{
52 Compression, EntryField, EntryWriteOptions, FieldNamePolicy, StructuredField,
53};
54pub use log::{
55 Config, EntryTimestamps, Log, LogArtifactSizer, LogIdentityMode, LogLifecycleEvent,
56 LogLifecycleObserver, LogLifecycleReason, LogOpenMode, RetentionPolicy, RotationPolicy,
57};