pub struct LoggerConfig {
pub policy: LogPolicy,
pub output: LogOutputMode,
pub file: Option<FileSinkConfig>,
pub crash_events: usize,
pub crash_bytes: usize,
}Expand description
Complete explicit logger configuration.
Fields§
§policy: LogPolicyFiltering and sanitization policy.
output: LogOutputModeTerminal, file, both, disabled or crash-only behavior.
file: Option<FileSinkConfig>File configuration used by file output or an explicit crash dump.
crash_events: usizeMaximum events retained by crash-only mode.
crash_bytes: usizeMaximum estimated bytes retained by crash-only mode.
Implementations§
Source§impl LoggerConfig
impl LoggerConfig
Sourcepub fn build(self) -> Result<ConfiguredLogger, LogConfigError>
pub fn build(self) -> Result<ConfiguredLogger, LogConfigError>
Builds a logger with no hidden global state or background thread.
Examples found in repository?
examples/basic.rs (line 24)
18fn main() -> Result<(), appcore_log::LogConfigError> {
19 // Safe V4 terminal logging is explicit and creates no global state.
20 let logger = LoggerConfig {
21 output: LogOutputMode::Terminal,
22 ..LoggerConfig::default()
23 }
24 .build()?;
25
26 // The builder defaults to V4 and can be kept for related events.
27 let log = logger.dispatcher().event(0, "application");
28
29 log.info("application started");
30 log.warn("connection is slower than expected");
31 log.error("document could not be saved");
32
33 Ok(())
34}More examples
examples/output_modes.rs (line 32)
15fn main() -> Result<(), appcore_log::LogConfigError> {
16 // Replace this with Disabled, Terminal, File, TerminalAndFile or CrashOnly.
17 let output = LogOutputMode::CrashOnly;
18
19 let logger = LoggerConfig {
20 output,
21 file: Some(FileSinkConfig {
22 path: std::env::temp_dir().join("my-application-crash.jsonl"),
23 max_bytes: LOG_SIZE_2_MIB,
24 sync_each_write: true,
25 retention: 1,
26 archive: None,
27 }),
28 crash_events: 128,
29 crash_bytes: 512 * 1024,
30 ..LoggerConfig::default()
31 }
32 .build()?;
33
34 let log = logger.dispatcher().event(0, "application");
35
36 log.info("kept only in the bounded crash ring");
37
38 // Call this from the application's panic/crash boundary. In every other
39 // mode it is a no-op and returns zero.
40 let _written_events = logger.dump_crash()?;
41
42 Ok(())
43}examples/file_logging.rs (line 50)
22fn main() -> Result<(), appcore_log::LogConfigError> {
23 // Keep generated output predictable and inside Cargo's ignored target tree.
24 let output_directory = PathBuf::from("target/appcore-log-example");
25 std::fs::create_dir_all(&output_directory).map_err(|_| LogConfigError::Sink(LogError::Io))?;
26
27 let active_file = output_directory.join("application.jsonl");
28
29 // Two rotations stay beside the active file. Older rotations move into
30 // archive/YYYY/MM and the complete archive never exceeds 120 files.
31 let archive_directory = output_directory.join("archive");
32 let mut policy = LogPolicy::new(Verbosity::V4);
33 policy.set_component("sync", Verbosity::V8);
34
35 let logger = LoggerConfig {
36 policy,
37 output: LogOutputMode::TerminalAndFile,
38 file: Some(FileSinkConfig {
39 path: active_file,
40 max_bytes: LOG_SIZE_8_MIB,
41 sync_each_write: false,
42 retention: 2,
43 archive: Some(FileArchiveConfig {
44 directory: archive_directory,
45 max_files: 120,
46 }),
47 }),
48 ..LoggerConfig::default()
49 }
50 .build()?;
51
52 let application = logger.dispatcher().event(0, "application");
53 let sync = logger.dispatcher().event(1, "sync.transport");
54
55 application.info("application ready; inspect target/appcore-log-example/application.jsonl");
56
57 // The parent component policy makes this V7 diagnostic visible.
58 sync.verbosity(7).debug("replication batch sent");
59
60 sync.warn("peer response was delayed");
61
62 let stats = logger.dispatcher().stats();
63 assert_eq!(stats.sink_failures, 0);
64
65 Ok(())
66}Trait Implementations§
Source§impl Clone for LoggerConfig
impl Clone for LoggerConfig
Source§fn clone(&self) -> LoggerConfig
fn clone(&self) -> LoggerConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LoggerConfig
impl Debug for LoggerConfig
Auto Trait Implementations§
impl Freeze for LoggerConfig
impl RefUnwindSafe for LoggerConfig
impl Send for LoggerConfig
impl Sync for LoggerConfig
impl Unpin for LoggerConfig
impl UnsafeUnpin for LoggerConfig
impl UnwindSafe for LoggerConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more