diff options
Diffstat (limited to 'patches/0001-Support-selecting-target-log-buffer.patch')
-rw-r--r-- | patches/0001-Support-selecting-target-log-buffer.patch | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/patches/0001-Support-selecting-target-log-buffer.patch b/patches/0001-Support-selecting-target-log-buffer.patch index 88ab283..6731ea8 100644 --- a/patches/0001-Support-selecting-target-log-buffer.patch +++ b/patches/0001-Support-selecting-target-log-buffer.patch @@ -1,20 +1,21 @@ -From 2bc2650d0a7a11a74670a6583b16aa6714d7c993 Mon Sep 17 00:00:00 2001 -From: Matthew Maurer <mmaurer@google.com> -Date: Thu, 17 Feb 2022 20:23:37 +0000 -Subject: [PATCH] Support selecting target log buffer +From eaa9cff3c99ed9e172c9d9fb369b70f84587f297 Mon Sep 17 00:00:00 2001 +From: Jeff Vander Stoep <jeffv@google.com> +Date: Mon, 5 Dec 2022 12:38:24 +0100 +Subject: [PATCH 1/2] 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. -Change-Id: I72779e62bd963586e3dfad431cd82c75daf04d92 +Test: atest +Change-Id: Id13515bb2cb042d1c31d4095444ae87cdcb13291 --- - src/lib.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++---------- - 1 file changed, 58 insertions(+), 13 deletions(-) + src/lib.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++---------- + 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs -index c50ce97..e7a62ef 100644 +index ef2027a..4bcce0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,21 +85,49 @@ pub use env_logger::fmt::Formatter; @@ -83,7 +84,7 @@ index c50ce97..e7a62ef 100644 // If a custom tag is used, add the module path to the message. // Use PlatformLogWriter to output chunks if they exceed max size. -@@ -205,6 +233,7 @@ impl AndroidLogger { +@@ -203,6 +231,7 @@ impl AndroidLogger { #[derive(Default)] pub struct Config { log_level: Option<Level>, @@ -91,7 +92,7 @@ index c50ce97..e7a62ef 100644 filter: Option<env_logger::filter::Filter>, tag: Option<CString>, custom_format: Option<FormatFn>, -@@ -220,6 +249,15 @@ impl Config { +@@ -218,6 +247,15 @@ impl Config { self } @@ -107,16 +108,16 @@ index c50ce97..e7a62ef 100644 fn filter_matches(&self, record: &Record) -> bool { if let Some(ref filter) = self.filter { 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, +@@ -259,6 +297,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, -@@ -267,7 +307,7 @@ struct PlatformLogWriter<'a> { +@@ -267,7 +307,7 @@ pub struct PlatformLogWriter<'a> { impl<'a> PlatformLogWriter<'a> { #[cfg(target_os = "android")] @@ -146,16 +147,16 @@ index c50ce97..e7a62ef 100644 len: 0, last_newline_index: 0, tag, -@@ -344,7 +386,7 @@ impl<'a> PlatformLogWriter<'a> { +@@ -345,7 +387,7 @@ impl<'a> PlatformLogWriter<'a> { }); - let msg: &CStr = unsafe { CStr::from_ptr(mem::transmute(self.buffer.as_ptr())) }; + 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; + unsafe { *self.buffer.get_unchecked_mut(len) = last_byte }; } -@@ -441,9 +483,11 @@ mod tests { +@@ -450,9 +492,11 @@ mod tests { // Filter is checked in config_filter_match below. let config = Config::default() .with_min_level(Level::Trace) @@ -167,7 +168,7 @@ index c50ce97..e7a62ef 100644 assert_eq!(config.tag, Some(CString::new("my_app").unwrap())); } -@@ -514,7 +558,7 @@ mod tests { +@@ -523,7 +567,7 @@ mod tests { fn platform_log_writer_init_values() { let tag = CStr::from_bytes_with_nul(b"tag\0").unwrap(); @@ -176,13 +177,15 @@ index c50ce97..e7a62ef 100644 assert_eq!(writer.tag, tag); // Android uses LogPriority instead, which doesn't implement equality checks -@@ -613,6 +657,6 @@ mod tests { +@@ -628,7 +672,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.35.1.265.g69c8d7142f-goog +2.39.0.rc0.267.gcb52ba06e7-goog + |