Consistent Rust logger initialization for host and device
Implement a universal logger interface that allows logging both
on-device (using android_logger) and on-host (using env_logger).
Uses a configuration struct similar to the one used by android_logger.
Allows using the same logging initialization code for on-device
code and host-side tests.
Bug: 162454083
Test: atest system/logging/rust
+ For device tests: confirm logging happens in logcat
+ For host tests: confirm logging happens to stdout (for failing test)
Change-Id: If80685033d2b39c660fab881405456f629fb1f8b
diff --git a/rust/tests/config_log_level.rs b/rust/tests/config_log_level.rs
new file mode 100644
index 0000000..7a9a241
--- /dev/null
+++ b/rust/tests/config_log_level.rs
@@ -0,0 +1,17 @@
+use std::env;
+
+#[test]
+fn config_log_level() {
+ // Environment variables should be overwritten by config values.
+ env::set_var("RUST_LOG", "debug");
+
+ let init_result = logger::init(
+ logger::Config::default()
+ .with_min_level(log::Level::Trace));
+
+ assert_eq!(init_result, true);
+ // Setting the level through the Config struct should impact both host and device
+ assert_eq!(log::max_level(), log::LevelFilter::Trace);
+
+ env::remove_var("RUST_LOG");
+}
\ No newline at end of file