1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! # ltrace — Rolling file writer for `tracing` and `log`
//!
//! This crate provides a high-performance rolling file writer with:
//!
//! - **Log rotation by time**: MINUTELY, HOURLY, DAILY
//! - **Log rotation by size**: configurable max file size (independent of time rotation)
//! - **Time + size combined rotation**: even when using time-based rotation (e.g. Daily),
//! a size limit still triggers additional rotations within that window (e.g., multiple
//! rotations per day if the log exceeds the size threshold)
//! - **Compression**: optional gzip compression for rotated files (feature `compression`),
//! performed on a background thread so it does not block writes
//! - **Max file count**: automatically prune old log files
//! - **Dynamic log level**: change the `log` crate log level at runtime via [`log_layer::LogHandle`]
//! - **Timezone configuration**: UTC (default) or local timezone for rotation timestamps
//! - **Auto-create directories**: parent directories are created automatically if they don't exist
//!
//! ## Rotated file naming
//!
//! Rotated filenames use a nanosecond-precision timestamp (nanoseconds since UNIX epoch)
//! to guarantee strict ordering and uniqueness, with an optional date prefix:
//!
//! - Daily rotation: `app.log.2024-01-15T1780358400000000000`
//! - Hourly rotation: `app.log.2024-01-15-14T1780358400000000000`
//! - Minutely rotation: `app.log.2024-01-15-14-30T1780358400000000000`
//! - Size-only (Never): `app.log.1780358400000000000`
//!
//! With gzip compression enabled: `app.log.2024-01-15T1780358400000000000.gz`
//!
//! # Using with `tracing`
//!
//! Since `RollingWriter` implements `std::io::Write`, you can use it with
//! `tracing_appender::non_blocking()` to get non-blocking writes:
//!
//! ```ignore
//! use ltrace::{RollingWriter, Rotation};
//!
//! let writer = RollingWriter::builder("/var/log/myapp/app.log")
//! .rotation(Rotation::Daily)
//! .max_file_size(10 * 1024 * 1024) // 10 MB
//! .max_files(10)
//! .compression(ltrace::Compression::Gzip)
//! .build()
//! .unwrap();
//!
//! let (non_blocking, _guard) = tracing_appender::non_blocking(writer);
//! tracing_subscriber::fmt()
//! .with_ansi(false)
//! .with_writer(non_blocking)
//! .finish()
//! .try_init()
//! .unwrap();
//! ```
//!
//! # Using with `log`
//!
//! Enable the `log` feature in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! ltrace = { version = "0.1", features = ["log"] }
//! ```
//!
//! The recommended way is to chain [`init`](log_layer::LogWriterBuilder::init) directly on the builder:
//!
//! ```ignore
//! use ltrace::log_layer::LogWriterBuilder;
//! use ltrace::{Rotation, Compression};
//!
//! let handle = LogWriterBuilder::new("/var/log/myapp/app.log")
//! .rotation(Rotation::Daily)
//! .max_file_size(10 * 1024 * 1024) // optional: also rotate within the same day if size exceeded
//! .max_files(5)
//! .compression(Compression::Gzip)
//! .level(log::LevelFilter::Info)
//! .init()?;
//!
//! // Dynamically change level at runtime:
//! handle.set_level(log::LevelFilter::Debug);
//! ```
//!
//! # Dynamic log level control
//!
//! [`log_layer::LogHandle`] is `Clone + Send + Sync`, so you can move it to other threads:
//!
//! ```ignore
//! let handle = LogWriterBuilder::new("app.log")
//! .level(log::LevelFilter::Info)
//! .init()?;
//!
//! // Spawn a thread that listens for signals to change the log level.
//! let handle_clone = handle.clone();
//! std::thread::spawn(move || {
//! // e.g., listen for SIGHUP or an HTTP endpoint
//! handle_clone.set_level(log::LevelFilter::Debug);
//! });
//! ```
pub use ;
pub use RollingWriter;