Skip to main content

08_configured_logging/
configured_logging.rs

1// =============================================================================
2//        #######
3//     ###       ###     F: configured_logging.rs
4//    ##   ## ##   ##    P: AppCore-Runtime
5//         ## ##
6//                       C: working-tree by dnettoRaw
7//    ##   ## ##   ##    U: working-tree by dnettoRaw
8//      ###########      S: 1.0.0-rc.1
9// =============================================================================
10
11//! Configure application logging without creating a host or background worker.
12
13use appcore_sdk::logging::{FileSinkConfig, LogOutputMode, LoggerConfig, LOG_SIZE_2_MIB};
14use appcore_sdk::prelude::*;
15
16fn main() -> AppResult<()> {
17    let logger = LoggerConfig {
18        output: LogOutputMode::CrashOnly,
19        file: Some(FileSinkConfig {
20            path: std::env::temp_dir().join("example-application-crash.jsonl"),
21            max_bytes: LOG_SIZE_2_MIB,
22            sync_each_write: true,
23            retention: 1,
24            archive: None,
25        }),
26        crash_events: 128,
27        crash_bytes: 512 * 1024,
28        ..LoggerConfig::default()
29    };
30
31    App::new("configured-logging")?.logging(logger)?.run(|app| {
32        let log = app.logger().component("startup");
33
34        log.info("application initialized");
35
36        // A real application calls this from its crash boundary.
37        let _written = app.dump_crash_log()?;
38
39        Ok(())
40    })
41}