#logging #macos #apple #log

oslog

A minimal safe wrapper around Apple's Logging system

6 releases

0.2.0 Feb 17, 2022
0.1.0 Feb 16, 2021
0.0.4 Feb 16, 2021
0.0.3 Jun 19, 2020
0.0.1 May 14, 2020

#43 in macOS and iOS APIs

Download history 3181/week @ 2023-12-16 1421/week @ 2023-12-23 6597/week @ 2023-12-30 10337/week @ 2024-01-06 15027/week @ 2024-01-13 12586/week @ 2024-01-20 11022/week @ 2024-01-27 13079/week @ 2024-02-03 11604/week @ 2024-02-10 10470/week @ 2024-02-17 9709/week @ 2024-02-24 10678/week @ 2024-03-02 5930/week @ 2024-03-09 6934/week @ 2024-03-16 6546/week @ 2024-03-23 7547/week @ 2024-03-30

27,833 downloads per month
Used in 6 crates (5 directly)

MIT license

16KB
354 lines

Crate

A minimal wrapper around Apple's unified logging system.

By default support for the log crate is provided, but if you would prefer just to use the lower level bindings you can disable the default features.

When making use of targets (info!(target: "t", "m");), you should be aware that a new log is allocated and stored in a map for the lifetime of the program. I expect log allocations are extremely small, but haven't attempted to verify it.

Logging example

This is behind the logger feature flag and is enabled by default.

fn main() {
    OsLogger::new("com.example.test")
        .level_filter(LevelFilter::Debug)
        .category_level_filter("Settings", LevelFilter::Trace)
        .init()
        .unwrap();

    // Maps to OS_LOG_TYPE_DEBUG
    trace!(target: "Settings", "Trace");

    // Maps to OS_LOG_TYPE_INFO
    debug!("Debug");

    // Maps to OS_LOG_TYPE_DEFAULT
    info!(target: "Parsing", "Info");

    // Maps to OS_LOG_TYPE_ERROR
    warn!("Warn");

    // Maps to OS_LOG_TYPE_FAULT
    error!("Error");
}

Missing features

  • Activities
  • Tracing
  • Native support for line numbers and file names.

Dependencies

~0–6.5MB