Skip to main content

output_modes/
output_modes.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: output_modes.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: working-tree by dnettoRaw
7//    ##   ## ##   ##    U: working-tree by dnettoRaw
8//      ###########      S: 1.0.2-rc
9// =============================================================================
10
11//! Select exactly one bounded logging behavior at application startup.
12
13use appcore_log::{FileSinkConfig, LogOutputMode, LoggerConfig, LOG_SIZE_2_MIB};
14
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}