-
Notifications
You must be signed in to change notification settings - Fork 425
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
How to disable the logging of a controller action for a given controller/action? #568
Comments
I don't think you can disable the logging on a per controller/action basis. But I think you should anyway either debounce the invocation of the controller action or debounce the emitting of the custom event itself so that the action doesn't even get triggered so many times. Usually you don't have to react to every single event if you have so many invocations in such a short time. There would be a few ways to achieve that: For debouncing the emitting of the event:
Listen to a debounced version of your emitted event:
<div data-action="debounced:scroll:progress@window->class-mutator#update" ...> Debounce the Controller Action itself:
I hope this helps! I'm not sure if it's worth having an API for disabling the debug logging on a per controller or even action basis. I'd be interested to hear what others think, maybe we could look into disabling it via a data-attribute. |
Hi @marcoroth yeah I know. Was a borderline example for sure, but there are many cases where this actual feature would be useful. For example, listening to mouse movements and triggering actions. Or, like in my example but much more simple: do something when the user scroll "up", "down", "top" or "bottom" like hide/show a navigation bar. When you are just scrolling the site for developing purposes, having a lot of messages logged doesn't help. EDIT: even debouncing scroll for a 200ms wait will cause a lot lot of messages 😄 |
A potential way forward here. Stimulus adds logging levels to the existing logging system. Currently the debugLogger can be quite noisy as it logs all non-error activities. stimulus/src/core/application.ts Line 95 in a2a030f
Maybe method calls could be a lower debug level compared to controller connection/disconnection? Then you could be backwards compatible with Alternatively logging can be tagged and you pass an array Examples
Note - I think that debug as it's built is useful for an intentionally noisy output of everything. This is probably not something that should be on by default but only turned on when you need to dig into something more complex. An idea I have had for some projects is to add an event listener that will enable debug easier when needed but not always have it on. Note - this assumes you don't want to add the Stimulus application to a global.
|
I'm listening to the
scroll:progress
event (emitted by me) and invokingclass-mutator#update
. The action gets logged when debug is enabled, and this is fine in many cases.But in this case the console is flooded with a lot of messages (depending on the monitor refresh rate). How can I disable the logging for this particular action?
The text was updated successfully, but these errors were encountered: