aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-19 09:35:00 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-19 09:35:00 +0000
commitd4f200ffbad08fb36b9025ebe8a1427689a62ed7 (patch)
tree4019cb444e37278d214a01b01267563207edc982
parent04dd98ed57154a706acbb6117a66185b176f215e (diff)
parent7cf0228c70e705857d8c40196300ce07c0bb6f8c (diff)
downloadandroid_logger-main-16k.tar.gz
Upgrade android_logger to 0.13.3 am: 7cf0228c70HEADmastermain-16kmain
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/android_logger/+/2939999 Change-Id: I7bc4fed563477da076239afdc32d315b2605f1c9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml25
-rw-r--r--Android.bp10
-rw-r--r--CHANGELOG.md36
-rw-r--r--Cargo.toml9
-rw-r--r--Cargo.toml.orig9
-rw-r--r--METADATA26
-rw-r--r--README.md4
-rw-r--r--patches/0001-Support-selecting-target-log-buffer.patch198
-rw-r--r--patches/0002-Use-older-API-to-avoid-requiring-API-v30.patch41
-rw-r--r--src/lib.rs138
11 files changed, 157 insertions, 341 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index c1be5ef..dd7220b 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "596b92d5907f0054884412d2f7137704edae4208"
+ "sha1": "cf2684e88f7cf6702c89a2fbebe0b8cb0fa77c31"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 674617d..0e7abee 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,26 +28,15 @@ jobs:
- i686-linux-android
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- - name: Install Rust ${{ matrix.toolchain }}
- uses: actions-rs/toolchain@v1
+ - uses: dtolnay/rust-toolchain@master
with:
- profile: minimal
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.target }}
- - name: Build
- uses: actions-rs/cargo@v1
- with:
- command: build
-
- - name: Generate docs
- uses: actions-rs/cargo@v1
- with:
- command: doc
-
- - name: Run tests
- uses: actions-rs/cargo@v1
- with:
- command: test
+ - run: cargo build --target=${{ matrix.target }}
+ - run: cargo doc --target=${{ matrix.target }}
+ # Temporary test non-target only.
+ # TODO: Test in emulator or something.
+ - run: cargo test
diff --git a/Android.bp b/Android.bp
index f3fad9b..86e8275 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.12.0",
+ cargo_pkg_version: "0.13.3",
srcs: ["src/lib.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -64,7 +64,7 @@ rust_test {
name: "android_logger_test_tests_config_log_level",
crate_name: "config_log_level",
cargo_env_compat: true,
- cargo_pkg_version: "0.12.0",
+ cargo_pkg_version: "0.13.3",
srcs: ["tests/config_log_level.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -86,7 +86,7 @@ rust_test {
name: "android_logger_test_tests_default_init",
crate_name: "default_init",
cargo_env_compat: true,
- cargo_pkg_version: "0.12.0",
+ cargo_pkg_version: "0.13.3",
srcs: ["tests/default_init.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -108,7 +108,7 @@ rust_test {
name: "android_logger_test_tests_multiple_init",
crate_name: "multiple_init",
cargo_env_compat: true,
- cargo_pkg_version: "0.12.0",
+ cargo_pkg_version: "0.13.3",
srcs: ["tests/multiple_init.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -130,7 +130,7 @@ rust_library {
name: "libandroid_logger",
crate_name: "android_logger",
cargo_env_compat: true,
- cargo_pkg_version: "0.12.0",
+ cargo_pkg_version: "0.13.3",
srcs: ["src/lib.rs"],
edition: "2015",
features: [
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4952ca1..5a75dac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,42 @@ All user visible changes to this project will be documented in this file. This p
+## [0.13.1] · 2023-03-07
+[0.13.1]: /../../tree/v0.13.1
+
+[Diff](/../../compare/v0.13.0...v0.13.1)
+
+### Fixed
+
+- Missing logs on [Android] API 26 and earlier. ([#66], [#67])
+
+[#66]: /../../issues/66
+[#67]: /../../pull/67
+
+
+
+
+## [0.13.0] · 2023-02-14
+[0.13.0]: /../../tree/v0.13.0
+
+[Diff](/../../compare/v0.12.0...v0.13.0)
+
+### BC Breaks
+
+- Added `buf_id` argument to `PlatformLogWriter::new()` method allowing to specify concrete Android logging system buffer. ([#50], [#64])
+- Removed deprecated `Config::with_min_level()` method accepting `log::Level`. ([#65])
+
+### Added
+
+- `Config::with_log_buffer()` method to specify concrete Android logging system buffer. ([#50], [#64])
+
+[#50]: /../../pull/50
+[#64]: /../../pull/64
+[#65]: /../../pull/65
+
+
+
+
## [0.12.0] · 2023-01-19
[0.12.0]: /../../tree/v0.12.0
diff --git a/Cargo.toml b/Cargo.toml
index a9fd573..1a68abd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,7 +11,7 @@
[package]
name = "android_logger"
-version = "0.12.0"
+version = "0.13.3"
authors = ["The android_logger Developers"]
description = """
A logging implementation for `log` which hooks to android log output.
@@ -25,10 +25,10 @@ keywords = [
]
categories = ["api-bindings"]
license = "MIT OR Apache-2.0"
-repository = "https://github.com/Nercury/android_logger-rs"
+repository = "https://github.com/rust-mobile/android_logger-rs"
[dependencies.android_log-sys]
-version = "0.2"
+version = "0.3"
[dependencies.env_logger]
version = "0.10"
@@ -43,6 +43,3 @@ 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 ca1b723..b0ba596 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,10 +1,10 @@
[package]
name = "android_logger"
-version = "0.12.0"
+version = "0.13.3"
authors = ["The android_logger Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
-repository = "https://github.com/Nercury/android_logger-rs"
+repository = "https://github.com/rust-mobile/android_logger-rs"
description = """
A logging implementation for `log` which hooks to android log output.
"""
@@ -22,11 +22,8 @@ once_cell = "1.9"
version = "0.4"
[dependencies.android_log-sys]
-version = "0.2"
+version = "0.3"
[dependencies.env_logger]
version = "0.10"
default-features = false
-
-[badges]
-travis-ci = { repository = "Nercury/android_logger-rs" }
diff --git a/METADATA b/METADATA
index df2996f..e259b87 100644
--- a/METADATA
+++ b/METADATA
@@ -1,20 +1,20 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/android_logger
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "android_logger"
description: "()"
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/android_logger"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/android_logger/android_logger-0.12.0.crate"
- }
- version: "0.12.0"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 2
- day: 2
+ year: 2024
+ month: 1
+ day: 24
+ }
+ homepage: "https://crates.io/crates/android_logger"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/android_logger/android_logger-0.13.3.crate"
+ version: "0.13.3"
}
}
diff --git a/README.md b/README.md
index eec1eba..0d97778 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
## Send Rust logs to Logcat
[![Version](https://img.shields.io/crates/v/android_logger.svg)](https://crates.io/crates/android_logger)
-[![CI status](https://github.com/Nercury/android_logger-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/Nercury/android_logger-rs/actions/workflows/ci.yml/)
+[![CI status](https://github.com/rust-mobile/android_logger-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-mobile/android_logger-rs/actions/workflows/ci.yml/)
This library is a drop-in replacement for `env_logger`. Instead, it outputs messages to
@@ -13,7 +13,7 @@ this library:
```toml
[target.'cfg(target_os = "android")'.dependencies]
-android_logger = "0.11"
+android_logger = "0.13"
```
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
deleted file mode 100644
index a9e11a4..0000000
--- a/patches/0001-Support-selecting-target-log-buffer.patch
+++ /dev/null
@@ -1,198 +0,0 @@
-From a41a079a81f381f2002917fb1c030690e0798f0c Mon Sep 17 00:00:00 2001
-From: Jeff Vander Stoep <jeffv@google.com>
-Date: Thu, 2 Feb 2023 13:33:47 +0100
-Subject: [PATCH] Support selecting target log buffer
-
-Android has several different log buffers. Previously, this library
-would only support logging to the "Main" log. Now, it logs to the
-default log (which is Main for most processes), with the option to
-override which log buffer you send messages to in the config.
-
-Test: atest
-Change-Id: I3cc393b989b8189675581ba6bf700f95715aa9e9
----
- src/lib.rs | 73 +++++++++++++++++++++++++++++++++++++++++++-----------
- 1 file changed, 59 insertions(+), 14 deletions(-)
-
-diff --git a/src/lib.rs b/src/lib.rs
-index 0446fad..9ec7f0d 100644
---- a/src/lib.rs
-+++ b/src/lib.rs
-@@ -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>;
-
-+#[derive(Copy, Clone, Eq, PartialEq, Debug)]
-+pub enum LogId {
-+ Main,
-+ Radio,
-+ Events,
-+ System,
-+ Crash
-+}
-+
-+impl LogId {
-+ #[cfg(target_os = "android")]
-+ fn to_native(log_id: Option<Self>) -> log_ffi::log_id_t {
-+ match log_id {
-+ Some(LogId::Main) => log_ffi::log_id_t::MAIN,
-+ Some(LogId::Radio) => log_ffi::log_id_t::RADIO,
-+ Some(LogId::Events) => log_ffi::log_id_t::EVENTS,
-+ Some(LogId::System) => log_ffi::log_id_t::SYSTEM,
-+ Some(LogId::Crash) => log_ffi::log_id_t::CRASH,
-+ None => log_ffi::log_id_t::DEFAULT,
-+ }
-+ }
-+}
-+
- /// Output log to android system.
- #[cfg(target_os = "android")]
--fn android_log(prio: log_ffi::LogPriority, tag: &CStr, msg: &CStr) {
-+fn android_log(log_id: log_ffi::log_id_t, prio: log_ffi::LogPriority, tag: &CStr, msg: &CStr) {
-+ let mut message = log_ffi::__android_log_message {
-+ struct_size: std::mem::size_of::<log_ffi::__android_log_message>(),
-+ buffer_id: log_id as i32,
-+ priority: prio as i32,
-+ tag: tag.as_ptr() as *const log_ffi::c_char,
-+ file: ptr::null(),
-+ line: 0,
-+ message: msg.as_ptr() as *const log_ffi::c_char,
-+ };
- unsafe {
-- log_ffi::__android_log_write(
-- prio as log_ffi::c_int,
-- tag.as_ptr() as *const log_ffi::c_char,
-- msg.as_ptr() as *const log_ffi::c_char,
-- )
-+ log_ffi::__android_log_write_log_message(&mut message as *mut _);
- };
- }
-
- /// Dummy output placeholder for tests.
- #[cfg(not(target_os = "android"))]
--fn android_log(_priority: Level, _tag: &CStr, _msg: &CStr) {}
-+fn android_log(_log_id: Option<LogId>, _priority: Level, _tag: &CStr, _msg: &CStr) {}
-
- /// Underlying android logger backend
- pub struct AndroidLogger {
-@@ -172,7 +200,7 @@ impl Log for AndroidLogger {
-
- // message must not exceed LOGGING_MSG_MAX_LEN
- // therefore split log message into multiple log calls
-- let mut writer = PlatformLogWriter::new(record.level(), tag);
-+ let mut writer = PlatformLogWriter::new(config.log_id, record.level(), tag);
-
- // If a custom tag is used, add the module path to the message.
- // Use PlatformLogWriter to output chunks if they exceed max size.
-@@ -215,6 +243,7 @@ impl AndroidLogger {
- #[derive(Default)]
- pub struct Config {
- log_level: Option<LevelFilter>,
-+ log_id: Option<LogId>,
- filter: Option<env_logger::filter::Filter>,
- tag: Option<CString>,
- custom_format: Option<FormatFn>,
-@@ -241,6 +270,15 @@ impl Config {
- self
- }
-
-+ /// Change which log buffer is used
-+ ///
-+ /// By default, logs are sent to the `Main` log. Other logging buffers may only be accessible
-+ /// to certain processes.
-+ pub fn with_log_id(mut self, log_id: LogId) -> Self {
-+ self.log_id = Some(log_id);
-+ self
-+ }
-+
- fn filter_matches(&self, record: &Record) -> bool {
- if let Some(ref filter) = self.filter {
- filter.matches(record)
-@@ -282,6 +320,8 @@ pub struct PlatformLogWriter<'a> {
- priority: LogPriority,
- #[cfg(not(target_os = "android"))]
- priority: Level,
-+ #[cfg(target_os = "android")] log_id: log_ffi::log_id_t,
-+ #[cfg(not(target_os = "android"))] log_id: Option<LogId>,
- len: usize,
- last_newline_index: usize,
- tag: &'a CStr,
-@@ -290,10 +330,11 @@ pub struct PlatformLogWriter<'a> {
-
- impl<'a> PlatformLogWriter<'a> {
- #[cfg(target_os = "android")]
-- pub fn new_with_priority(priority: log_ffi::LogPriority, tag: &CStr) -> PlatformLogWriter {
-+ pub fn new_with_priority(log_id: Option<LogId>, priority: log_ffi::LogPriority, tag: &CStr) -> PlatformLogWriter {
- #[allow(deprecated)] // created an issue #35 for this
- PlatformLogWriter {
- priority,
-+ log_id: LogId::to_native(log_id),
- len: 0,
- last_newline_index: 0,
- tag,
-@@ -302,8 +343,9 @@ impl<'a> PlatformLogWriter<'a> {
- }
-
- #[cfg(target_os = "android")]
-- pub fn new(level: Level, tag: &CStr) -> PlatformLogWriter {
-+ pub fn new(log_id: Option<LogId>, level: Level, tag: &CStr) -> PlatformLogWriter {
- Self::new_with_priority(
-+ log_id,
- match level {
- Level::Warn => LogPriority::WARN,
- Level::Info => LogPriority::INFO,
-@@ -316,10 +358,11 @@ impl<'a> PlatformLogWriter<'a> {
- }
-
- #[cfg(not(target_os = "android"))]
-- pub fn new(level: Level, tag: &CStr) -> PlatformLogWriter {
-+ pub fn new(log_id: Option<LogId>, level: Level, tag: &CStr) -> PlatformLogWriter {
- #[allow(deprecated)] // created an issue #35 for this
- PlatformLogWriter {
- priority: level,
-+ log_id,
- len: 0,
- last_newline_index: 0,
- tag,
-@@ -376,7 +419,7 @@ impl<'a> PlatformLogWriter<'a> {
- });
-
- let msg: &CStr = unsafe { CStr::from_ptr(self.buffer.as_ptr().cast()) };
-- android_log(self.priority, self.tag, msg);
-+ android_log(self.log_id, self.priority, self.tag, msg);
-
- unsafe { *self.buffer.get_unchecked_mut(len) = last_byte };
- }
-@@ -481,9 +524,11 @@ mod tests {
- // Filter is checked in config_filter_match below.
- let config = Config::default()
- .with_max_level(LevelFilter::Trace)
-+ .with_log_id(LogId::System)
- .with_tag("my_app");
-
- assert_eq!(config.log_level, Some(LevelFilter::Trace));
-+ assert_eq!(config.log_id, Some(LogId::System));
- assert_eq!(config.tag, Some(CString::new("my_app").unwrap()));
- }
-
-@@ -556,7 +601,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);
-
- assert_eq!(writer.tag, tag);
- // Android uses LogPriority instead, which doesn't implement equality checks
-@@ -661,7 +706,7 @@ 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())
- }
-
- unsafe fn assume_init_slice<T>(slice: &[MaybeUninit<T>]) -> &[T] {
---
-2.39.1.456.gfc5497dd1b-goog
-
diff --git a/patches/0002-Use-older-API-to-avoid-requiring-API-v30.patch b/patches/0002-Use-older-API-to-avoid-requiring-API-v30.patch
deleted file mode 100644
index 44f08fb..0000000
--- a/patches/0002-Use-older-API-to-avoid-requiring-API-v30.patch
+++ /dev/null
@@ -1,41 +0,0 @@
-From b5ee33076e1868c5946345b2cfb15a519b8c2577 Mon Sep 17 00:00:00 2001
-From: Jeff Vander Stoep <jeffv@google.com>
-Date: Mon, 5 Dec 2022 12:42:22 +0100
-Subject: [PATCH 2/2] Use older API to avoid requiring API v30
-
-Test: Check that keystore still outputs logs to system
-Bug: 221185310
-Change-Id: If81d66cb145cbb41b4338fd64ac024d77243482e
----
- src/lib.rs | 14 ++++----------
- 1 file changed, 4 insertions(+), 10 deletions(-)
-
-diff --git a/src/lib.rs b/src/lib.rs
-index 4bcce0c..59f942b 100644
---- a/src/lib.rs
-+++ b/src/lib.rs
-@@ -111,17 +111,11 @@ impl LogId {
- /// Output log to android system.
- #[cfg(target_os = "android")]
- fn android_log(log_id: log_ffi::log_id_t, prio: log_ffi::LogPriority, tag: &CStr, msg: &CStr) {
-- let mut message = log_ffi::__android_log_message {
-- struct_size: std::mem::size_of::<log_ffi::__android_log_message>(),
-- buffer_id: log_id as i32,
-- priority: prio as i32,
-- tag: tag.as_ptr() as *const log_ffi::c_char,
-- file: ptr::null(),
-- line: 0,
-- message: msg.as_ptr() as *const log_ffi::c_char,
-- };
- unsafe {
-- log_ffi::__android_log_write_log_message(&mut message as *mut _);
-+ log_ffi::__android_log_buf_write(log_id as i32,
-+ prio as i32,
-+ tag.as_ptr() as *const log_ffi::c_char,
-+ msg.as_ptr() as *const log_ffi::c_char);
- };
- }
-
---
-2.39.0.rc0.267.gcb52ba06e7-goog
-
diff --git a/src/lib.rs b/src/lib.rs
index b35db3f..cfd2bb9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -100,43 +100,85 @@ pub use env_logger::fmt::Formatter;
pub(crate) type FormatFn = Box<dyn Fn(&mut dyn fmt::Write, &Record) -> fmt::Result + Sync + Send>;
-#[derive(Copy, Clone, Eq, PartialEq, Debug)]
+/// Possible identifiers of a specific buffer of Android logging system for
+/// logging a message.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum LogId {
+ /// Main log buffer.
+ ///
+ /// This is the only log buffer available to apps.
Main,
+
+ /// Radio log buffer.
Radio,
+
+ /// Event log buffer.
Events,
+
+ /// System log buffer.
System,
- Crash
+
+ /// Crash log buffer.
+ Crash,
+
+ /// Kernel log buffer.
+ Kernel,
+
+ /// Security log buffer.
+ Security,
+
+ /// Statistics log buffer.
+ Stats,
}
+#[cfg(target_os = "android")]
impl LogId {
- #[cfg(target_os = "android")]
- fn to_native(log_id: Option<Self>) -> log_ffi::log_id_t {
+ const fn to_native(log_id: Option<Self>) -> Option<log_ffi::log_id_t> {
match log_id {
- Some(LogId::Main) => log_ffi::log_id_t::MAIN,
- Some(LogId::Radio) => log_ffi::log_id_t::RADIO,
- Some(LogId::Events) => log_ffi::log_id_t::EVENTS,
- Some(LogId::System) => log_ffi::log_id_t::SYSTEM,
- Some(LogId::Crash) => log_ffi::log_id_t::CRASH,
- None => log_ffi::log_id_t::DEFAULT,
+ Some(Self::Main) => Some(log_ffi::log_id_t::MAIN),
+ Some(Self::Radio) => Some(log_ffi::log_id_t::RADIO),
+ Some(Self::Events) => Some(log_ffi::log_id_t::EVENTS),
+ Some(Self::System) => Some(log_ffi::log_id_t::SYSTEM),
+ Some(Self::Crash) => Some(log_ffi::log_id_t::CRASH),
+ Some(Self::Kernel) => Some(log_ffi::log_id_t::KERNEL),
+ Some(Self::Security) => Some(log_ffi::log_id_t::SECURITY),
+ Some(Self::Stats) => Some(log_ffi::log_id_t::STATS),
+ None => None,
}
}
}
-/// Output log to android system.
+/// Outputs log to Android system.
#[cfg(target_os = "android")]
-fn android_log(log_id: log_ffi::log_id_t, prio: log_ffi::LogPriority, tag: &CStr, msg: &CStr) {
- unsafe {
- log_ffi::__android_log_buf_write(log_id as i32,
- prio as i32,
- tag.as_ptr() as *const log_ffi::c_char,
- msg.as_ptr() as *const log_ffi::c_char);
- };
+fn android_log(
+ buf_id: Option<log_ffi::log_id_t>,
+ prio: log_ffi::LogPriority,
+ tag: &CStr,
+ msg: &CStr,
+) {
+ if let Some(buf_id) = buf_id {
+ unsafe {
+ log_ffi::__android_log_buf_write(
+ buf_id as log_ffi::c_int,
+ prio as log_ffi::c_int,
+ tag.as_ptr() as *const log_ffi::c_char,
+ msg.as_ptr() as *const log_ffi::c_char,
+ );
+ };
+ } else {
+ unsafe {
+ log_ffi::__android_log_write(
+ prio as log_ffi::c_int,
+ tag.as_ptr() as *const log_ffi::c_char,
+ msg.as_ptr() as *const log_ffi::c_char,
+ );
+ };
+ }
}
/// Dummy output placeholder for tests.
#[cfg(not(target_os = "android"))]
-fn android_log(_log_id: Option<LogId>, _priority: Level, _tag: &CStr, _msg: &CStr) {}
+fn android_log(_buf_id: Option<LogId>, _priority: Level, _tag: &CStr, _msg: &CStr) {}
/// Underlying android logger backend
pub struct AndroidLogger {
@@ -209,7 +251,7 @@ impl Log for AndroidLogger {
// message must not exceed LOGGING_MSG_MAX_LEN
// therefore split log message into multiple log calls
- let mut writer = PlatformLogWriter::new(config.log_id, record.level(), tag);
+ let mut writer = PlatformLogWriter::new(config.buf_id, record.level(), tag);
// If a custom tag is used, add the module path to the message.
// Use PlatformLogWriter to output chunks if they exceed max size.
@@ -252,20 +294,13 @@ impl AndroidLogger {
#[derive(Default)]
pub struct Config {
log_level: Option<LevelFilter>,
- log_id: Option<LogId>,
+ buf_id: Option<LogId>,
filter: Option<env_logger::filter::Filter>,
tag: Option<CString>,
custom_format: Option<FormatFn>,
}
impl Config {
- // TODO: Remove on 0.13 version release.
- /// **DEPRECATED**, use [`Config::with_max_level()`] instead.
- #[deprecated(note = "use `.with_max_level()` instead")]
- pub fn with_min_level(self, level: Level) -> Self {
- self.with_max_level(level.to_level_filter())
- }
-
/// Changes the maximum log level.
///
/// Note, that `Trace` is the maximum level, because it provides the
@@ -279,15 +314,6 @@ impl Config {
self
}
- /// Change which log buffer is used
- ///
- /// By default, logs are sent to the `Main` log. Other logging buffers may only be accessible
- /// to certain processes.
- pub fn with_log_id(mut self, log_id: LogId) -> Self {
- self.log_id = Some(log_id);
- self
- }
-
/// Changes the Android logging system buffer to be used.
///
/// By default, logs are sent to the [`Main`] log. Other logging buffers may
@@ -295,7 +321,7 @@ impl Config {
///
/// [`Main`]: LogId::Main
pub fn with_log_buffer(mut self, buf_id: LogId) -> Self {
- self.log_id = Some(buf_id);
+ self.buf_id = Some(buf_id);
self
}
@@ -340,8 +366,10 @@ pub struct PlatformLogWriter<'a> {
priority: LogPriority,
#[cfg(not(target_os = "android"))]
priority: Level,
- #[cfg(target_os = "android")] log_id: log_ffi::log_id_t,
- #[cfg(not(target_os = "android"))] log_id: Option<LogId>,
+ #[cfg(target_os = "android")]
+ buf_id: Option<log_ffi::log_id_t>,
+ #[cfg(not(target_os = "android"))]
+ buf_id: Option<LogId>,
len: usize,
last_newline_index: usize,
tag: &'a CStr,
@@ -350,11 +378,15 @@ pub struct PlatformLogWriter<'a> {
impl<'a> PlatformLogWriter<'a> {
#[cfg(target_os = "android")]
- pub fn new_with_priority(log_id: Option<LogId>, priority: log_ffi::LogPriority, tag: &CStr) -> PlatformLogWriter {
+ pub fn new_with_priority(
+ buf_id: Option<LogId>,
+ priority: log_ffi::LogPriority,
+ tag: &CStr,
+ ) -> PlatformLogWriter<'_> {
#[allow(deprecated)] // created an issue #35 for this
PlatformLogWriter {
priority,
- log_id: LogId::to_native(log_id),
+ buf_id: LogId::to_native(buf_id),
len: 0,
last_newline_index: 0,
tag,
@@ -363,9 +395,9 @@ impl<'a> PlatformLogWriter<'a> {
}
#[cfg(target_os = "android")]
- pub fn new(log_id: Option<LogId>, level: Level, tag: &CStr) -> PlatformLogWriter {
- Self::new_with_priority(
- log_id,
+ pub fn new(buf_id: Option<LogId>, level: Level, tag: &CStr) -> PlatformLogWriter<'_> {
+ PlatformLogWriter::new_with_priority(
+ buf_id,
match level {
Level::Warn => LogPriority::WARN,
Level::Info => LogPriority::INFO,
@@ -378,11 +410,11 @@ impl<'a> PlatformLogWriter<'a> {
}
#[cfg(not(target_os = "android"))]
- pub fn new(log_id: Option<LogId>, level: Level, tag: &CStr) -> PlatformLogWriter {
+ pub fn new(buf_id: Option<LogId>, level: Level, tag: &CStr) -> PlatformLogWriter<'_> {
#[allow(deprecated)] // created an issue #35 for this
PlatformLogWriter {
priority: level,
- log_id,
+ buf_id,
len: 0,
last_newline_index: 0,
tag,
@@ -439,7 +471,7 @@ impl<'a> PlatformLogWriter<'a> {
});
let msg: &CStr = unsafe { CStr::from_ptr(self.buffer.as_ptr().cast()) };
- android_log(self.log_id, self.priority, self.tag, msg);
+ android_log(self.buf_id, self.priority, self.tag, msg);
unsafe { *self.buffer.get_unchecked_mut(len) = last_byte };
}
@@ -550,11 +582,11 @@ mod tests {
// Filter is checked in config_filter_match below.
let config = Config::default()
.with_max_level(LevelFilter::Trace)
- .with_log_id(LogId::System)
+ .with_log_buffer(LogId::System)
.with_tag("my_app");
assert_eq!(config.log_level, Some(LevelFilter::Trace));
- assert_eq!(config.log_id, Some(LogId::System));
+ assert_eq!(config.buf_id, Some(LogId::System));
assert_eq!(config.tag, Some(CString::new("my_app").unwrap()));
}
@@ -733,7 +765,11 @@ 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(),
+ )
}
unsafe fn assume_init_slice<T>(slice: &[MaybeUninit<T>]) -> &[T] {