android-logcat
A simple Rust library for Android logcat. This library provides a simple interface to the Android logging system.
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Basic Usage
You can use the Log struct to log messages with different priorities.
use Log;
info;
error;
Global Logger
For convenience, you can initialize a global logger with a default tag.
use Log;
// In your app's initialization code
init;
// Later in your code
i;
e;
Using macros
use android_logcat;
// In global tag
i!;
d!;
// In custom tag
d!;
Disable control
use Log;
// default status is `enable`.
// diseanble
enabled;
let curr_status = is_enabled;
// reenable
enabled;
let curr_status = is_enabled;
With log crate
This library can be used as a backend for the log crate.
Change this to your Cargo.toml:
[]
= "0.1"
= "0.4"
use Log;
use ;
// In your app's initialization code
// Set the second parameter to true to mix in with the log crate
init;
// Now you can use the macros from the log crate
info!;
error!;
expect_log for Result and Option
The ExpectLogcat trait provides a convenient way to handle Result and Option types. If the value is Err or None, it logs an error message and then panics.
use ExpectLogcat;
This will log an error with the message "Failed to run: something went wrong" and then panic.
It works similarly for Option:
use ExpectLogcat;
let an_option: = None;
let value = an_option.expect_log;
This will log an error with the message "The option was None!" and then panic.
License
This project is licensed under the Apache-2.0 license. See the LICENSE.txt file for details.