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

Pass global logger by value, supplied logger by ref #673

Merged
merged 6 commits into from
Mar 23, 2025

Conversation

KodrAus
Copy link
Contributor

@KodrAus KodrAus commented Mar 23, 2025

Follow-up to #664

cc @EFanZh @tisonkun @Thomasdezeeuw

This PR ensures we pass loggers by-ref when they're user-supplied, and by-value when it's the built-in global logger. I'll add a few tests to ensure we don't take ownership of the logger in log! or log_enabled!.

KodrAus added 3 commits March 23, 2025 14:22
Copy link
Contributor

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

This looks good.

While I wonder if we can somehow inline the log_impl in the caller so that all the zero-size logger can benefit? Just like write!'s

macro_rules! write {
    ($dst:expr, $($arg:tt)*) => {
        $dst.write_fmt($crate::format_args!($($arg)*)) // <- directly call on the pass-in obj
    };
}

Maybe by a private LogExt?

@KodrAus
Copy link
Contributor Author

KodrAus commented Mar 23, 2025

Yeh I think we could basically make __private_api::log into a trait method that we’d implement for L: Log and call that at the callsite.

KodrAus added 3 commits March 24, 2025 05:45
@KodrAus
Copy link
Contributor Author

KodrAus commented Mar 23, 2025

I've added some more tests around the logger argument, just to make sure we're more likely to catch regressions in the future.

@KodrAus KodrAus merged commit ea6f54d into master Mar 23, 2025
28 checks passed
@KodrAus KodrAus deleted the feat/logger-by-ref branch March 23, 2025 20:19
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.

None yet

3 participants