aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid LeGare <legare@google.com>2022-04-28 17:08:27 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-28 17:08:27 +0000
commit94464a8fc5634bf54a913e59ae7b6c2e5db36ac8 (patch)
tree23605f728d6720a7f4685618635e382fba497575
parent8abb512d6f39476ac833e444c37af80e2e1ca673 (diff)
parent5719d62a2f092e063a2263fcfd453c6a251bca29 (diff)
downloadandroid_logger-94464a8fc5634bf54a913e59ae7b6c2e5db36ac8.tar.gz
Upgrade rust/crates/android_logger to 0.11.0 am: 97855c2480 am: 5719d62a2f
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/android_logger/+/2072330 Change-Id: I37e2e0a60d0e173cc7f88246a2e21650038c9f77 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json7
-rw-r--r--Android.bp12
-rw-r--r--Cargo.toml32
-rw-r--r--Cargo.toml.orig6
-rw-r--r--METADATA8
-rw-r--r--README.md2
-rw-r--r--patches/0001-Support-selecting-target-log-buffer.patch47
-rw-r--r--src/lib.rs60
8 files changed, 78 insertions, 96 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 00435b7..c1be5ef 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,6 @@
{
"git": {
- "sha1": "c20ec25acacf0731583140b230e6ce94e59b054d"
- }
-}
+ "sha1": "596b92d5907f0054884412d2f7137704edae4208"
+ },
+ "path_in_vcs": ""
+} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index 056c310..63736fe 100644
--- a/Android.bp
+++ b/Android.bp
@@ -43,7 +43,7 @@ rust_test {
name: "android_logger_test_src_lib",
crate_name: "android_logger",
cargo_env_compat: true,
- cargo_pkg_version: "0.10.1",
+ cargo_pkg_version: "0.11.0",
srcs: ["src/lib.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -55,8 +55,8 @@ rust_test {
rustlibs: [
"libandroid_log_sys",
"libenv_logger",
- "liblazy_static",
"liblog_rust",
+ "libonce_cell",
],
}
@@ -64,7 +64,7 @@ rust_defaults {
name: "android_logger_test_defaults",
crate_name: "android_logger",
cargo_env_compat: true,
- cargo_pkg_version: "0.10.1",
+ cargo_pkg_version: "0.11.0",
test_suites: ["general-tests"],
auto_gen_config: true,
edition: "2015",
@@ -76,8 +76,8 @@ rust_defaults {
"libandroid_log_sys",
"libandroid_logger",
"libenv_logger",
- "liblazy_static",
"liblog_rust",
+ "libonce_cell",
],
}
@@ -103,7 +103,7 @@ rust_library {
name: "libandroid_logger",
crate_name: "android_logger",
cargo_env_compat: true,
- cargo_pkg_version: "0.10.1",
+ cargo_pkg_version: "0.11.0",
srcs: ["src/lib.rs"],
edition: "2015",
features: [
@@ -113,8 +113,8 @@ rust_library {
rustlibs: [
"libandroid_log_sys",
"libenv_logger",
- "liblazy_static",
"liblog_rust",
+ "libonce_cell",
],
apex_available: [
"//apex_available:platform",
diff --git a/Cargo.toml b/Cargo.toml
index dec0113..02cf115 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,38 +3,46 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
-# to registry (e.g., crates.io) dependencies
+# to registry (e.g., crates.io) dependencies.
#
-# If you believe there's an error in this file please file an
-# issue against the rust-lang/cargo repository. If you're
-# editing this file be aware that the upstream Cargo.toml
-# will likely look very different (and much more reasonable)
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
[package]
name = "android_logger"
-version = "0.10.1"
+version = "0.11.0"
authors = ["The android_logger Developers"]
-description = "A logging implementation for `log` which hooks to android log output.\n"
+description = """
+A logging implementation for `log` which hooks to android log output.
+"""
readme = "README.md"
-keywords = ["android", "bindings", "log", "logger"]
+keywords = [
+ "android",
+ "bindings",
+ "log",
+ "logger",
+]
categories = ["api-bindings"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/Nercury/android_logger-rs"
+
[dependencies.android_log-sys]
version = "0.2"
[dependencies.env_logger]
-version = "0.8"
+version = "0.9"
default-features = false
-[dependencies.lazy_static]
-version = "1.4"
-
[dependencies.log]
version = "0.4"
+[dependencies.once_cell]
+version = "1.9"
+
[features]
default = ["regex"]
regex = ["env_logger/regex"]
+
[badges.travis-ci]
repository = "Nercury/android_logger-rs"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index a9ad77f..f092ceb 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "android_logger"
-version = "0.10.1"
+version = "0.11.0"
authors = ["The android_logger Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
@@ -16,7 +16,7 @@ default = ["regex"]
regex = ["env_logger/regex"]
[dependencies]
-lazy_static = "1.4"
+once_cell = "1.9"
[dependencies.log]
version = "0.4"
@@ -25,7 +25,7 @@ version = "0.4"
version = "0.2"
[dependencies.env_logger]
-version = "0.8"
+version = "0.9"
default-features = false
[badges]
diff --git a/METADATA b/METADATA
index 27e229f..7f7dc13 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/android_logger/android_logger-0.10.1.crate"
+ value: "https://static.crates.io/crates/android_logger/android_logger-0.11.0.crate"
}
- version: "0.10.1"
+ version: "0.11.0"
license_type: NOTICE
last_upgrade_date {
- year: 2021
+ year: 2022
month: 4
- day: 19
+ day: 21
}
}
diff --git a/README.md b/README.md
index c3b88bf..cc408d6 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ this library:
```toml
[target.'cfg(target_os = "android")'.dependencies]
-android_logger = "0.10"
+android_logger = "0.11"
```
Example of initialization on activity creation, with log configuration:
diff --git a/patches/0001-Support-selecting-target-log-buffer.patch b/patches/0001-Support-selecting-target-log-buffer.patch
index e5fc33b..88ab283 100644
--- a/patches/0001-Support-selecting-target-log-buffer.patch
+++ b/patches/0001-Support-selecting-target-log-buffer.patch
@@ -14,10 +14,10 @@ Change-Id: I72779e62bd963586e3dfad431cd82c75daf04d92
1 file changed, 58 insertions(+), 13 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
-index 11a127e..d21be3f 100644
+index c50ce97..e7a62ef 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -87,21 +87,49 @@ pub use env_logger::fmt::Formatter;
+@@ -85,21 +85,49 @@ pub use env_logger::fmt::Formatter;
pub(crate) type FormatFn = Box<dyn Fn(&mut dyn fmt::Write, &Record) -> fmt::Result + Sync + Send>;
@@ -74,7 +74,7 @@ index 11a127e..d21be3f 100644
/// Underlying android logger backend
pub struct AndroidLogger {
-@@ -164,7 +192,7 @@ impl Log for AndroidLogger {
+@@ -160,7 +188,7 @@ impl Log for AndroidLogger {
// message must not exceed LOGGING_MSG_MAX_LEN
// therefore split log message into multiple log calls
@@ -83,23 +83,15 @@ index 11a127e..d21be3f 100644
// If a custom tag is used, add the module path to the message.
// Use PlatformLogWriter to output chunks if they exceed max size.
-@@ -208,6 +236,7 @@ impl AndroidLogger {
- /// Filter for android logger.
+@@ -205,6 +233,7 @@ impl AndroidLogger {
+ #[derive(Default)]
pub struct Config {
log_level: Option<Level>,
+ log_id: Option<LogId>,
filter: Option<env_logger::filter::Filter>,
tag: Option<CString>,
custom_format: Option<FormatFn>,
-@@ -217,6 +246,7 @@ impl Default for Config {
- fn default() -> Self {
- Config {
- log_level: None,
-+ log_id: None,
- filter: None,
- tag: None,
- custom_format: None,
-@@ -234,6 +264,15 @@ impl Config {
+@@ -220,6 +249,15 @@ impl Config {
self
}
@@ -114,8 +106,8 @@ index 11a127e..d21be3f 100644
+
fn filter_matches(&self, record: &Record) -> bool {
if let Some(ref filter) = self.filter {
- filter.matches(&record)
-@@ -273,6 +312,8 @@ impl Config {
+ filter.matches(record)
+@@ -259,6 +297,8 @@ impl Config {
struct PlatformLogWriter<'a> {
#[cfg(target_os = "android")] priority: LogPriority,
#[cfg(not(target_os = "android"))] priority: Level,
@@ -124,7 +116,7 @@ index 11a127e..d21be3f 100644
len: usize,
last_newline_index: usize,
tag: &'a CStr,
-@@ -281,7 +322,7 @@ struct PlatformLogWriter<'a> {
+@@ -267,7 +307,7 @@ struct PlatformLogWriter<'a> {
impl<'a> PlatformLogWriter<'a> {
#[cfg(target_os = "android")]
@@ -133,7 +125,7 @@ index 11a127e..d21be3f 100644
#[allow(deprecated)] // created an issue #35 for this
PlatformLogWriter {
priority: match level {
-@@ -291,6 +332,7 @@ impl<'a> PlatformLogWriter<'a> {
+@@ -277,6 +317,7 @@ impl<'a> PlatformLogWriter<'a> {
Level::Error => LogPriority::ERROR,
Level::Trace => LogPriority::VERBOSE,
},
@@ -141,7 +133,7 @@ index 11a127e..d21be3f 100644
len: 0,
last_newline_index: 0,
tag,
-@@ -299,10 +341,11 @@ impl<'a> PlatformLogWriter<'a> {
+@@ -285,10 +326,11 @@ impl<'a> PlatformLogWriter<'a> {
}
#[cfg(not(target_os = "android"))]
@@ -154,7 +146,7 @@ index 11a127e..d21be3f 100644
len: 0,
last_newline_index: 0,
tag,
-@@ -358,7 +401,7 @@ impl<'a> PlatformLogWriter<'a> {
+@@ -344,7 +386,7 @@ impl<'a> PlatformLogWriter<'a> {
});
let msg: &CStr = unsafe { CStr::from_ptr(mem::transmute(self.buffer.as_ptr())) };
@@ -163,7 +155,7 @@ index 11a127e..d21be3f 100644
*unsafe { self.buffer.get_unchecked_mut(len) } = last_byte;
}
-@@ -458,9 +501,11 @@ mod tests {
+@@ -441,9 +483,11 @@ mod tests {
// Filter is checked in config_filter_match below.
let config = Config::default()
.with_min_level(Level::Trace)
@@ -175,23 +167,22 @@ index 11a127e..d21be3f 100644
assert_eq!(config.tag, Some(CString::new("my_app").unwrap()));
}
-@@ -531,7 +576,7 @@ mod tests {
+@@ -514,7 +558,7 @@ mod tests {
fn platform_log_writer_init_values() {
let tag = CStr::from_bytes_with_nul(b"tag\0").unwrap();
-- let writer = PlatformLogWriter::new(Level::Warn, &tag);
-+ let writer = PlatformLogWriter::new(None, Level::Warn, &tag);
+- let writer = PlatformLogWriter::new(Level::Warn, tag);
++ let writer = PlatformLogWriter::new(None, Level::Warn, tag);
assert_eq!(writer.tag, tag);
// Android uses LogPriority instead, which doesn't implement equality checks
-@@ -630,6 +675,6 @@ mod tests {
+@@ -613,6 +657,6 @@ mod tests {
}
fn get_tag_writer() -> PlatformLogWriter<'static> {
-- PlatformLogWriter::new(Level::Warn, &CStr::from_bytes_with_nul(b"tag\0").unwrap())
-+ PlatformLogWriter::new(None, Level::Warn, &CStr::from_bytes_with_nul(b"tag\0").unwrap())
+- PlatformLogWriter::new(Level::Warn, CStr::from_bytes_with_nul(b"tag\0").unwrap())
++ PlatformLogWriter::new(None, Level::Warn, CStr::from_bytes_with_nul(b"tag\0").unwrap())
}
}
--
2.35.1.265.g69c8d7142f-goog
-
diff --git a/src/lib.rs b/src/lib.rs
index bc4fa61..183559f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -65,15 +65,13 @@
#[cfg(target_os = "android")]
extern crate android_log_sys as log_ffi;
-#[macro_use]
-extern crate lazy_static;
+extern crate once_cell;
+use once_cell::sync::OnceCell;
#[macro_use]
extern crate log;
extern crate env_logger;
-use std::sync::RwLock;
-
#[cfg(target_os = "android")]
use log_ffi::LogPriority;
use log::{Level, Log, Metadata, Record};
@@ -127,21 +125,20 @@ fn android_log(_log_id: Option<LogId>, _priority: Level, _tag: &CStr, _msg: &CSt
/// Underlying android logger backend
pub struct AndroidLogger {
- config: RwLock<Config>,
+ config: OnceCell<Config>,
}
impl AndroidLogger {
/// Create new logger instance from config
pub fn new(config: Config) -> AndroidLogger {
AndroidLogger {
- config: RwLock::new(config),
+ config: OnceCell::from(config),
}
}
}
-lazy_static! {
- static ref ANDROID_LOGGER: AndroidLogger = AndroidLogger::default();
-}
+
+static ANDROID_LOGGER: OnceCell<AndroidLogger> = OnceCell::new();
const LOGGING_TAG_MAX_LEN: usize = 23;
const LOGGING_MSG_MAX_LEN: usize = 4000;
@@ -150,7 +147,7 @@ impl Default for AndroidLogger {
/// Create a new logger with default config
fn default() -> AndroidLogger {
AndroidLogger {
- config: RwLock::new(Config::default()),
+ config: OnceCell::from(Config::default()),
}
}
}
@@ -162,8 +159,7 @@ impl Log for AndroidLogger {
fn log(&self, record: &Record) {
let config = self.config
- .read()
- .expect("failed to acquire android_log filter lock for read");
+ .get_or_init(Config::default);
if !config.filter_matches(record) {
return;
@@ -177,7 +173,7 @@ impl Log for AndroidLogger {
// If no tag was specified, use module name
let custom_tag = &config.tag;
- let tag = custom_tag.as_ref().map(|s| s.as_bytes()).unwrap_or(module_path.as_bytes());
+ let tag = custom_tag.as_ref().map(|s| s.as_bytes()).unwrap_or_else(|| module_path.as_bytes());
// truncate the tag here to fit into LOGGING_TAG_MAX_LEN
self.fill_tag_bytes(&mut tag_bytes, tag);
@@ -228,6 +224,7 @@ impl AndroidLogger {
}
/// Filter for android logger.
+#[derive(Default)]
pub struct Config {
log_level: Option<Level>,
log_id: Option<LogId>,
@@ -236,18 +233,6 @@ pub struct Config {
custom_format: Option<FormatFn>,
}
-impl Default for Config {
- fn default() -> Self {
- Config {
- log_level: None,
- log_id: None,
- filter: None,
- tag: None,
- custom_format: None,
- }
- }
-}
-
impl Config {
/// Change the minimum log level.
///
@@ -269,7 +254,7 @@ impl Config {
fn filter_matches(&self, record: &Record) -> bool {
if let Some(ref filter) = self.filter {
- filter.matches(&record)
+ filter.matches(record)
} else {
true
}
@@ -402,7 +387,7 @@ impl<'a> PlatformLogWriter<'a> {
/// Copy `len` bytes from `index` position to starting position.
fn copy_bytes_to_start(&mut self, index: usize, len: usize) {
- let src = unsafe { self.buffer.as_ptr().offset(index as isize) };
+ let src = unsafe { self.buffer.as_ptr().add(index) };
let dst = self.buffer.as_mut_ptr();
unsafe { ptr::copy(src, dst, len) };
}
@@ -460,7 +445,7 @@ impl<'a> fmt::Write for PlatformLogWriter<'a> {
/// This action does not require initialization. However, without initialization it
/// will use the default filter, which allows all logs.
pub fn log(record: &Record) {
- ANDROID_LOGGER.log(record)
+ ANDROID_LOGGER.get_or_init(AndroidLogger::default).log(record)
}
/// Initializes the global logger with an android logger.
@@ -471,16 +456,13 @@ pub fn log(record: &Record) {
/// It is ok to call this at the activity creation, and it will be
/// repeatedly called on every lifecycle restart (i.e. screen rotation).
pub fn init_once(config: Config) {
- if let Err(err) = log::set_logger(&*ANDROID_LOGGER) {
+ let log_level = config.log_level;
+ let logger = ANDROID_LOGGER.get_or_init(|| AndroidLogger::new(config));
+
+ if let Err(err) = log::set_logger(logger) {
debug!("android_logger: log::set_logger failed: {}", err);
- } else {
- if let Some(level) = config.log_level {
- log::set_max_level(level.to_level_filter());
- }
- *ANDROID_LOGGER
- .config
- .write()
- .expect("failed to acquire android_log filter lock for write") = config;
+ } else if let Some(level) = log_level {
+ log::set_max_level(level.to_level_filter());
}
}
@@ -570,7 +552,7 @@ mod tests {
fn platform_log_writer_init_values() {
let tag = CStr::from_bytes_with_nul(b"tag\0").unwrap();
- let writer = PlatformLogWriter::new(None, Level::Warn, &tag);
+ let writer = PlatformLogWriter::new(None, Level::Warn, tag);
assert_eq!(writer.tag, tag);
// Android uses LogPriority instead, which doesn't implement equality checks
@@ -669,6 +651,6 @@ mod tests {
}
fn get_tag_writer() -> PlatformLogWriter<'static> {
- PlatformLogWriter::new(None, Level::Warn, &CStr::from_bytes_with_nul(b"tag\0").unwrap())
+ PlatformLogWriter::new(None, Level::Warn, CStr::from_bytes_with_nul(b"tag\0").unwrap())
}
}