-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
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))] |
There was a problem hiding this comment.
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()
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😇
Closing in favor of #81, which adds deeper Debug support. |
Append requires Debug here.