#android #logging #logger #log #debugging-logging #logcat #adb

android-logd-logger

A logging implementation for log which directly writes to the Android logd daemon

14 releases

0.4.4 Oct 11, 2024
0.4.3 Mar 8, 2024
0.4.2 Jul 20, 2023
0.3.3 Feb 15, 2023
0.1.3 Mar 2, 2021

#129 in Debugging

Download history 720/week @ 2024-07-20 824/week @ 2024-07-27 892/week @ 2024-08-03 730/week @ 2024-08-10 933/week @ 2024-08-17 883/week @ 2024-08-24 899/week @ 2024-08-31 857/week @ 2024-09-07 756/week @ 2024-09-14 625/week @ 2024-09-21 710/week @ 2024-09-28 779/week @ 2024-10-05 819/week @ 2024-10-12 659/week @ 2024-10-19 540/week @ 2024-10-26 657/week @ 2024-11-02

2,948 downloads per month
Used in northstar

MIT/Apache

49KB
858 lines

android-logd-logger

Crates.io Build Status Docs

This logger writes logs to the Android logd, a system service with multiple ringbuffers for logs and evens. This is normally done via liblog (a native Android lib). Instead of using liblog, this crate writes directly to the logd socket with the trivial protocol below. This logger is written in pure Rust without any need for ffi.

On non Android system the log output is printed to stdout in the default format of logcat.

Usage

Add this to your Cargo.toml

[dependencies]
android-logd-logger = "0.4.3"

Initialize the logger with a fixed tag and the module path included in the log payload.


fn main() {
    android_logd_logger::builder()
        .parse_filters("debug")
        .tag(TagMode::TargetStrip)
        .prepend_module(true)
        .init();

    trace!("trace message: is not logged");
    debug!("debug message");
    info!("info message");
    warn!("warn message");
    error!("error message");
}

To write android logd "events" use event or event_now, e.g:

android_logd_logger::write_event_now(1, "test").unwrap();

Configuration

Writing to the logd socket is a single point of synchronization for threads. The android-logd-logger can be configured with the tls feature to maintain one socket per thread or use a single socket for the whole process. Use the features tls if you want less interference between threads but pay for one connection per thread.

License

Licensed under either of

Dependencies

~4–11MB
~114K SLoC