Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,20 @@ object Capture {
}

/**
* Usage: adb shell setprop debug.bitdrift.internal_log_level debug
* Sets up the internal logging level for the rust library. This is done by reading a system
* Usage: adb shell setprop debug.bitdrift.internal_rust_log debug
* Sets up the internal logging filter for the rust library. This is done by reading a system
* property and propagating it as an environment variable within the same process.
* It swallows any failures and sets default to "info".
*
* This supports normal rust log filters, so for example so look at trace logs for only bd
* crates to:
* adb shell setprop debug.bitdrift.internal_rust_log info,bd=trace
*/
@Suppress("SpreadOperator")
@SuppressLint("PrivateApi")
private fun setUpInternalLogging(context: Context) {
if (BuildTypeChecker.isDebuggable(context)) {
val defaultLevel = "info"
val defaultRustLog = "info"
runCatching {
// TODO(murki): Alternatively we could use JVM -D arg to pass properties
// that can be read via System.getProperty() but that's less Android-idiomatic
Expand All @@ -545,11 +549,11 @@ object Capture {
Class
.forName("android.os.SystemProperties")
.getMethod("get", *arrayOf(String::class.java, String::class.java))
.invoke(null, *arrayOf("debug.bitdrift.internal_log_level", defaultLevel)) as? String
.invoke(null, *arrayOf("debug.bitdrift.internal_rust_log", defaultRustLog)) as? String
}.getOrNull().let {
val internalLogLevel = it ?: defaultLevel
val internalRustLog = it ?: defaultRustLog
runCatching {
Os.setenv("RUST_LOG", internalLogLevel, true)
Os.setenv("RUST_LOG", internalRustLog, true)
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions platform/jvm/src/jni.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use time::{Duration, OffsetDateTime};
// Android to avoid setting this up in JVM tests where we want to log to stderr.
#[cfg(target_os = "android")]
fn initialize_logging() {
use android_logger::Config;
use android_logger::{Config, FilterBuilder};
use log::LevelFilter;
use std::sync::Once;

Expand All @@ -73,13 +73,14 @@ fn initialize_logging() {
// TODO(snowp): Ideally we use a tracing subscriber which embeds the span information like we
// do everywhere else, as that would let us use trace spans to provide context for the logs.
// Look into forking `tracing-android`.
let level = std::env::var("RUST_LOG")
.unwrap_or_else(|_| "info".to_string())
.parse::<LevelFilter>()
.unwrap_or(LevelFilter::Info);
let rust_log = std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string());

// This can be called only once.
android_logger::init_once(Config::default().with_max_level(level));
android_logger::init_once(
Config::default()
.with_max_level(LevelFilter::Trace)
.with_filter(FilterBuilder::new().parse(&rust_log).build()),
);
});
}

Expand Down
Loading