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

Conversation

carl-wallace
Copy link

Append requires Debug here.

src/lib.rs Outdated
@@ -160,7 +163,10 @@ fn android_log(
fn android_log(_buf_id: Option<LogId>, _priority: Level, _tag: &CStr, _msg: &CStr) {}

/// Underlying android logger backend
#[cfg_attr(feature = "log4rs", derive(Derivative))]
Copy link
Collaborator

@Dushistov Dushistov Sep 5, 2024

Choose a reason for hiding this comment

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

derivative is not supported.
But even if supported, why use extract crate, when you can write just
5 lines of code?

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.

How about unconditionally (i.e. remove feature = "log4rs" - that's irrelevant) implementing Debug on Config? It looks like all fields except the function can be formatted, so if we take some inspiration from the ndk crate you end up with a much simpler change.

Copy link
Author

Choose a reason for hiding this comment

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

Pushed changes so this is no longer feature gated and is simpler. Thanks for the suggestions. I was trying to leave the default builds as they were, but that's probably overkill here.

@@ -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 😇

@carl-wallace
Copy link
Author

Closing in favor of #81, which adds deeper Debug support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants