1 ## Send Rust logs to Logcat
3 [![Version](https://img.shields.io/crates/v/android_logger.svg)](https://crates.io/crates/android_logger)
4 [![CI status](https://github.com/Nercury/android_logger-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/Nercury/android_logger-rs/actions/workflows/ci.yml/)
7 This library is a drop-in replacement for `env_logger`. Instead, it outputs messages to
10 This only works on Android and requires linking to `log` which
11 is only available under android. With Cargo, it is possible to conditionally require
15 [target.'cfg(target_os = "android")'.dependencies]
16 android_logger = "0.11"
19 Example of initialization on activity creation, with log configuration:
22 #[macro_use] extern crate log;
23 extern crate android_logger;
26 use android_logger::{Config,FilterBuilder};
28 fn native_activity_create() {
29 android_logger::init_once(
31 .with_max_level(LevelFilter::Trace) // limit log level
32 .with_tag("mytag") // logs will show under mytag tag
33 .with_filter( // configure messages for specific crate
35 .parse("debug,hello::crate=error")
39 trace!("this is a verbose {}", "message");
40 error!("this is printed by default");
44 To allow all logs, use the default configuration with min level Trace:
47 #[macro_use] extern crate log;
48 extern crate android_logger;
51 use android_logger::Config;
53 fn native_activity_create() {
54 android_logger::init_once(
55 Config::default().with_max_level(LevelFilter::Trace),
60 There is a caveat that this library can only be initialized once
61 (hence the `init_once` function name). However, Android native activity can be
62 re-created every time the screen is rotated, resulting in multiple initialization calls.
63 Therefore this library will only log a warning for subsequent `init_once` calls.
65 This library ensures that logged messages do not overflow Android log message limits
66 by efficiently splitting messages into chunks.
70 Licensed under either of
72 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
73 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
79 Unless you explicitly state otherwise, any contribution intentionally
80 submitted for inclusion in the work by you, as defined in the Apache-2.0
81 license, shall be dual licensed as above, without any additional terms or