Expand description
A pure Rust logger for Android’s logd logging system.
This crate provides a logger implementation that writes directly to Android’s logd socket,
bypassing the need for liblog or any other native Android libraries. On non-Android platforms,
logs are printed to stderr in a format similar to logcat.
§Features
- Pure Rust: No FFI or native dependencies required
- Direct socket communication: Writes directly to the
logdsocket - Multiple log buffers: Support for main, radio, events, system, crash, stats, and security buffers
- Event logging: Write structured events to Android’s event log
- Persistent logging: Optional logging to pstore (survives reboots on Android)
- Runtime configuration: Adjust log levels, tags, and filters after initialization
- Cross-platform: Works on Android and falls back to stderr on other platforms
§Quick Start
use log::{debug, error, info, trace, warn};
fn main() {
android_logd_logger::builder()
.parse_filters("debug")
.tag("MyApp")
.prepend_module(true)
.init();
trace!("trace message: is not logged");
debug!("debug message");
info!("info message");
warn!("warn message");
error!("error message");
}§Runtime Configuration
The logger can be reconfigured at runtime using the Logger handle:
use log::LevelFilter;
let logger = android_logd_logger::builder().init();
// Change the tag at runtime
logger.tag("NewTag");
// Adjust log levels
logger.filter_level(LevelFilter::Warn);§Event Logging
Android’s event log can be used for structured logging:
use android_logd_logger::{write_event_now, EventValue};
// Simple event
write_event_now(1, "test").unwrap();
// Complex event with multiple values
let value: Vec<EventValue> = vec![1.into(), "one".into(), 123.3.into()];
write_event_now(2, value).unwrap();Structs§
- Builder
- Builder for initializing the logger.
- Event
- An event log entry.
- Logger
- Logger configuration handle. Logger configuration handle for runtime adjustments.
Enums§
- Buffer
- Android log buffer identifiers.
- Error
- Errors that can occur when logging.
- Event
Value - The value payload of an event.
- Priority
- Log priority levels as defined by Android’s logd.
Functions§
- builder
- Returns a default
Builderfor configuration and initialization of logging. - log
- Construct and send a log entry (non-Android platforms).
- write_
event - Writes an event to the events buffer.
- write_
event_ buffer - Writes an event to a specific buffer.
- write_
event_ buffer_ now - Writes an event with the current timestamp to a specific buffer.
- write_
event_ now - Writes an event with the current timestamp to the events buffer.
Type Aliases§
- Event
Tag - Event tag identifier.