android-logd-logger

Crates.ioandroid-logd-logger
lib.rsandroid-logd-logger
version0.4.4
sourcesrc
created_at2021-03-02 14:32:16.167376
updated_at2024-10-11 11:23:01.920965
descriptionA logging implementation for `log` which directly writes to the Android logd daemon
homepagehttps://github.com/flxo/android-logd-logger
repositoryhttps://github.com/flxo/android-logd-logger
max_upload_size
id362708
size66,160
Felix Obenhuber (flxo)

documentation

https://docs.rs/android-logd-logger

README

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

Commit count: 113

cargo fmt