-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 helper macro's for logging only once #10808
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
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.
Nice! I like the simplicity of this rather than more explicit options (like a Local<bool>
or some other method of tracking).
Me too @MrGVSV, and thanks for the review! What do you think of this latest change, in which the |
Some remaining questions:
|
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.
Really simple and clean. Nice stuff!
I'm content with where it is for now. I don't particularly want to promote this as a general-purpose tool, or add things to
https://github.com/rust-lang/rust/issues/77839suggests that Rust can't access WASM atomic primitives, but I'm not sure if that's the same as A quick test before merging would be great. |
Seems to work just fine! |
Objective
Fixes #10291
This adds a way to easily log messages once within system which are called every frame.
Solution
Opted for a macro-based approach. The fact that the 'once' call is tracked per call site makes the
log_once!()
macro very versatile and easy-to-use. I suspect it will be very handy for all of us, but especially beginners, to get some initial feedback from systems without spamming up the place!I've made the macro's return its internal
has_fired
state, for situations in which that might be useful to know (trigger something else alongside the log, for example).Please let me know if I placed the macro's in the right location, and if you would like me to do something more clever with the macro's themselves, since its looking quite copy-pastey at the moment. I've tried ways to replace 5 with 1 macro's, but no success yet.
One downside of this approach is: Say you wish to warn the user if a resource is invalid. In this situation, the
resource.is_valid()
check would still be performed every frame:If you want to prevent that, you would still need to introduce a local boolean. I don't think this is a very big deal, as expensive checks shouldn't be called every frame in any case.
Changelog
Added:
trace_once!()
,debug_once!()
,info_once!()
,warn_once!()
, anderror_once!()
log macros which fire only once per call site.