1 unstable release
0.1.0 | Jul 7, 2024 |
---|
#661 in Debugging
235 downloads per month
13KB
208 lines
tracing-logcat
tracing-logcat is a library that provides an Android logcat output for the tracing
library. It directly communicates with Android's logd
process instead of using liblog.so
, making it suitable for use with statically linked executables.
See examples/
for examples of how to use this library.
License
tracing-logcat is licensed under Apache 2.0. Please see LICENSE
for the full license text.
lib.rs
:
tracing
writer for logging into Android's logcat. Instead of linking
liblog, which isn't available as a static library in the NDK, this library
directly connects to logd and sends messages via the documented protocol.
There are a few behavioral differences compared to liblog:
- In the very unlikely event that Android's logd crashes, logging will stop working because tracing-logcat does not attempt to reconnect to the logd socket.
- Only Android 5 and newer are supported. Previous versions of Android did not use logd and implemented logcat without a userspace daemon.
- Log messages longer than
4068 - <tag length> - 2
bytes are split into multiple messages instead of being truncated. If the original message is valid UTF-8, then the message is split at a code point boundary (not at a grapheme cluster boundary). Otherwise, the message is split exactly at the length limit.
Examples
Using a fixed tag
use tracing::Level;
use tracing_logcat::{LogcatMakeWriter, LogcatTag};
use tracing_subscriber::fmt::format::Format;
let tag = LogcatTag::Fixed(env!("CARGO_PKG_NAME").to_owned());
let writer = LogcatMakeWriter::new(tag)
.expect("Failed to initialize logcat writer");
tracing_subscriber::fmt()
.event_format(Format::default().with_level(false).without_time())
.with_writer(writer)
.with_ansi(false)
.with_max_level(Level::TRACE)
.init();
Using the tracing target as the tag
use tracing::Level;
use tracing_logcat::{LogcatMakeWriter, LogcatTag};
use tracing_subscriber::fmt::format::Format;
let writer = LogcatMakeWriter::new(LogcatTag::Target)
.expect("Failed to initialize logcat writer");
tracing_subscriber::fmt()
.event_format(Format::default().with_level(false).with_target(false).without_time())
.with_writer(writer)
.with_ansi(false)
.with_max_level(Level::TRACE)
.init();
Dependencies
~3–11MB
~133K SLoC