Skip to main content

il2cpp_bridge_rs/
logger.rs

1//! Logging via platform-appropriate logging backend.
2//!
3//! On Apple platforms (macOS/iOS) the Apple Unified Logging System is used via
4//! `oslog`. On all other platforms `env_logger` is used, which writes to
5//! stderr and respects the `RUST_LOG` environment variable.
6
7use std::sync::Once;
8
9static INIT: Once = Once::new();
10
11#[cfg(any(target_os = "macos", target_os = "ios"))]
12fn ensure_initialized() {
13    INIT.call_once(|| {
14        use log::LevelFilter;
15        use oslog::OsLogger;
16        OsLogger::new("com.batch.il2cpp-bridge")
17            .level_filter(LevelFilter::Debug)
18            .init()
19            .ok();
20    });
21}
22
23#[cfg(not(any(target_os = "macos", target_os = "ios")))]
24fn ensure_initialized() {
25    INIT.call_once(|| {
26        let _ = env_logger::builder()
27            .filter_level(log::LevelFilter::Debug)
28            .try_init();
29    });
30}
31
32pub fn info(msg: &str) {
33    ensure_initialized();
34    log::info!("{}", msg);
35}
36
37pub fn warning(msg: &str) {
38    ensure_initialized();
39    log::warn!("{}", msg);
40}
41
42pub fn error(msg: &str) {
43    ensure_initialized();
44    log::error!("{}", msg);
45}