#adb #android #log #logcat #logger

android-logd-logger

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

8 releases

0.3.2 May 25, 2022
0.3.1 May 5, 2022
0.3.0 Apr 6, 2022
0.2.2 Jun 2, 2021
0.1.3 Mar 2, 2021

#108 in Debugging

Download history 396/week @ 2022-06-02 613/week @ 2022-06-09 142/week @ 2022-06-16 204/week @ 2022-06-23 644/week @ 2022-06-30 323/week @ 2022-07-07 615/week @ 2022-07-14 303/week @ 2022-07-21 129/week @ 2022-07-28 359/week @ 2022-08-04 402/week @ 2022-08-11 269/week @ 2022-08-18 386/week @ 2022-08-25 359/week @ 2022-09-01 272/week @ 2022-09-08 436/week @ 2022-09-15

1,485 downloads per month
Used in northstar

MIT/Apache

30KB
475 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.2.1"

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

~2.5–8MB
~158K SLoC