Skip to content

Commit b4f7783

Browse files
authored
Merge pull request #81 from rust-mobile/marijn/unconditionally-derive-debug
Derive/implement `Debug` for `Config` and `AndroidLogger`
2 parents 401a08d + cac592f commit b4f7783

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/lib.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn android_log(
160160
fn android_log(_buf_id: Option<LogId>, _priority: Level, _tag: &CStr, _msg: &CStr) {}
161161

162162
/// Underlying android logger backend
163+
#[derive(Debug, Default)]
163164
pub struct AndroidLogger {
164165
config: OnceLock<Config>,
165166
}
@@ -183,15 +184,6 @@ static ANDROID_LOGGER: OnceLock<AndroidLogger> = OnceLock::new();
183184
const LOGGING_TAG_MAX_LEN: usize = 127;
184185
const LOGGING_MSG_MAX_LEN: usize = 4000;
185186

186-
impl Default for AndroidLogger {
187-
/// Create a new logger with default config
188-
fn default() -> AndroidLogger {
189-
AndroidLogger {
190-
config: OnceLock::from(Config::default()),
191-
}
192-
}
193-
}
194-
195187
impl Log for AndroidLogger {
196188
fn enabled(&self, metadata: &Metadata) -> bool {
197189
let config = self.config();
@@ -226,7 +218,7 @@ impl Log for AndroidLogger {
226218

227219
// In case we end up allocating, keep the CString alive.
228220
let _owned_tag;
229-
let tag: &CStr = if tag.len() < tag_bytes.len() {
221+
let tag = if tag.len() < tag_bytes.len() {
230222
// truncate the tag here to fit into LOGGING_TAG_MAX_LEN
231223
fill_tag_bytes(&mut tag_bytes, tag)
232224
} else {
@@ -306,6 +298,24 @@ pub struct Config {
306298
custom_format: Option<FormatFn>,
307299
}
308300

301+
impl fmt::Debug for Config {
302+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
303+
f.debug_struct("Config")
304+
.field("log_level", &self.log_level)
305+
.field("buf_id", &self.buf_id)
306+
.field("filter", &self.filter)
307+
.field("tag", &self.tag)
308+
.field(
309+
"custom_format",
310+
match &self.custom_format {
311+
Some(_) => &"Some(_)",
312+
None => &"None",
313+
},
314+
)
315+
.finish()
316+
}
317+
}
318+
309319
impl Config {
310320
/// Changes the maximum log level.
311321
///

0 commit comments

Comments
 (0)