Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug implementation for AndroidLogger to facilitate use with log4rs #79

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ pub struct AndroidLogger {
config: OnceLock<Config>,
}

impl std::fmt::Debug for AndroidLogger {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AndroidLogger").finish()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything this should use finish_non_exhaustive() to indicate that some (in this case all...) members are skipped. But we're better off deferring to #81 which implements Debug logging recursively for all types.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed #81. Closing this. Thanks.

Copy link
Member

@MarijnS95 MarijnS95 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries - I figured I'd open a new PR instead of suggesting a bunch of review/diff comments here. Hope you don't mind for taking over 😇

}
}
impl AndroidLogger {
/// Create new logger instance from config
pub fn new(config: Config) -> AndroidLogger {
Expand Down
12 changes: 12 additions & 0 deletions tests/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use android_logger::AndroidLogger;
use android_logger::Config;
use log::LevelFilter;
use std::sync::OnceLock;

#[test]
fn test_debug() {
static ANDROID_LOGGER: OnceLock<AndroidLogger> = OnceLock::new();
let android_logger = ANDROID_LOGGER
.get_or_init(|| AndroidLogger::new(Config::default().with_max_level(LevelFilter::Trace)));
assert_eq!("AndroidLogger", format!("{:?}", android_logger));
}
Loading