๋ก๊น
log
ํฌ๋ ์ดํธ๋ฅผ ์ฌ์ฉํ๋ฉด ์๋๋ก์ด๋ ๋๋ฐ์ด์ค ์์์ ์ํ๋ ๋์๋ logcat
์ผ๋ก, ํธ์คํธ์์ ์ํ๋ ๋์๋ stdout
์ผ๋ก ๋ก๊ทธ๊ฐ ์๋์ผ๋ก ์ถ๋ ฅ์ด ๋๋๋ก ํ ์ ์์ต๋๋ค:
hello_rust_logs/Android.bp:
rust_binary {
name: "hello_rust_logs",
crate_name: "hello_rust_logs",
srcs: ["src/main.rs"],
rustlibs: [
"liblog_rust",
"liblogger",
],
prefer_rlib: true,
host_supported: true,
}
hello_rust_logs/src/main.rs:
//! Rust logging demo.
use log::{debug, error, info};
/// Logs a greeting.
fn main() {
logger::init(
logger::Config::default()
.with_tag_on_device("rust")
.with_min_level(log::Level::Trace),
);
debug!("Starting program.");
info!("Things are going fine.");
error!("Something went wrong!");
}
๋น๋ํ๊ณ , ๊ฐ์ ๋๋ฐ์ด์ค์ ๋ฃ๊ณ , ์คํํฉ๋๋ค:
m hello_rust_logs
adb push "$ANDROID_PRODUCT_OUT/system/bin/hello_rust_logs /data/local/tmp"
adb shell /data/local/tmp/hello_rust_logs
adb logcat
์ปค๋งจ๋๋ก ๋ก๊ทธ๋ฅผ ํ์ธํฉ๋๋ค:
adb logcat -s rust
09-08 08:38:32.454 2420 2420 D rust: hello_rust_logs: Starting program.
09-08 08:38:32.454 2420 2420 I rust: hello_rust_logs: Things are going fine.
09-08 08:38:32.454 2420 2420 E rust: hello_rust_logs: Something went wrong!