-
Notifications
You must be signed in to change notification settings - Fork 3k
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 logger filtering on process level #2384
base: master
Are you sure you want to change the base?
Conversation
If you do this:
or possibly a variant that uses the process dictionary you can achieve the same result as this PR. It is also possible to raise the log level in a filter, though the primary filters are run after the primary level check so the level filtering then needs to be done in the handler. Is this good enough or is using pid as a filter common enough that it would be a good thing to add a standardized way to do it for all users of |
It came out as a proposal for core while working on elixir-lang/elixir#9333 which supports per-process disable of logging (which with this change can be achieved by
I cannot say anything about popularity of that functionality in Elixir community, I was just porting it to merge loggers of both worlds. |
The thing with adding this check into the logger API and not as a primary filter is that then we have to check the process dictionary for each log call done everywhere which is not free. So unless many people find this a very useful feature I'm going to reject this PR. |
77246b9
to
4215f41
Compare
@garazdawi I understand, it was just a proposal. Alternative solution could be to merge process metadata and that new entry into one, but that will still require lookup into process dictionary on each request. I will try to bench it to see if there is any noticeable impact. |
I think it's very useful to be able to do this, and I think the process dictionary solution is good (because you can choose to silence a specific part of a process execution, like a noisy shutdown) but also not so good (can't always enable it easily from outside the process) so I do not think it should be in the API as it currently stands. For the feature to be truly useful I would need something equivalent to |
Silencing something is achievable with a primary filter. What I'm wondering about is the use-case of making a process more verbose. It is not possible to do with today without building multiple filters and using the module logger level. |
To clarify, this means we will read from the process dictionary one time (instead of zero) whenever there is a filter that skips but the number of reads whenever you log would remain the same.
Oh, I haven't thought about this and it would actually be really nice. Yesterday I was having a discussion with someone who wanted SASL reports during shutdown for a specific supervisor, but those require debug level or similar, which meant you had to enable them for the whole system. If we have something like But the issue is that I don't know how to implement
Thoughts? |
Sorry, lack of sleep. I should have written I suppose there's overlap with |
There is one more possible option - additional server that would watch over the filtered-out processes and would update filter argument accordingly. Unfortunately that still has disadvantage of not being able to increase verbosity over primary/module level, as these will always have precedence. |
df2e6f0
to
853e61a
Compare
One of the big thing I have in mind when working on a larger system with multiple containerized nodes is really about how to turn all of these options about what to log and what not to log in a way that is long term maintainable and versioned. To me, the weakness of approaches that are global and remote such as So to me the only safe logical and tractable approach is something that is set locally by the process executing: have the process put a value in its local logging context or within the process dictionary. Then I can audit it with the code, and if the worker restarts, its logging level is configured consistently. The weakness of this approach is obviously when you want to silence a process for which you do not own the code, but I feel that if we had a structured approach to logging, then adding semantic filters would make sense (i.e. "filter out the logs related to the But then again maybe I'm debugging things an entirely different way than folks asking for this feature are. I pretty much never increase the logging level at run-time (I'll usually use tracing or add a temporary My gut feeling here is that adding pid-based filtering at a distance and sticking it in the |
@ferd my concern is that whatever we have today doesn't address libraries which provide you a behaviour that you end-up running. Those are things like poolboy, cowboy, etc. I can have many poolboy pools in the system and I want to debug one of them. How to do that? I can do it per module but they all have the same module. The same applies to supervisors. I don't want to So unless I am missing something, I really don't buy we are addressing design issues at the wrong place, given the issue happens with a built-in component such as supervisor. I agree though we don't need to be able to do it at a distance. A combination of pdict + sys:set_logger_level I mentioned earlier would also do the trick. |
This adds possibility to filter logger messages on process basis. This feature is mostly useful for disabling logging in some processes or to increase logging verbosity during debugging.
853e61a
to
0cea267
Compare
There's two types of uses, yours (@ferd) is controlling what logs will be printed on a per app/process basis, and general debugging (not necessarily in production). Obviously in the latter case it doesn't matter if the level gets reset when the process restarts, it's no longer the same process or state that you were looking into and may not display the behavior you were investigating anymore. Let's say I have a customer connected with a session process named I see this as a great alternative to That said as long as processes handle |
That is why this proposal uses pdict. Alternatively, if we decide that there should be "filtered out" list, then there should be process that will monitor all processes that have altered logging level (as this is meant mostly as a debugging and testing tool there should not be many of such processes) and would remove these pids from list when the process dies. This will prevent your second scenario.
It is possible nowadays via
It is almost possible to do what is requested by just using filters. Only thing not possible right now is to increase logging level for a process over primary/module level. So while the "original" intent, which was implementing Elixir |
Also I have started Twitter poll to check how many people used that functionality (or were aware of it). So far it shows that it wasn't commonly known or used (at least directly). I know that this isn't representative sample of the community, but it is something. |
I usually just use the pid in the metadata as part of what the formatter does by default, and then I can filter based off that, either from the text logs, or if doing point-in-time debugging, by adding a handler to do just that. The one thing this does not address is what @hauleth referred in allowing to increase the perceived level of a process, but this is the kind of stuff I never do in prod, just because I tend to assume that the data that goes in Now that's probably a question of preferences and we're unlikely to get an agreement. If I had to do it though despite all of that, I would probably set per-handler log levels (i.e. default and disk are set to But usually I never make it there; by the time I reach that point, I usually had the time to trace something and figure it out without going through logs. |
Hello all! I'm putting this PR on hold for now as we need to figure out what direction we want to take |
@ferd @garazdawi what about another approach that will not allow to increase verbosity of the system, but only to reduce verbosity for given process? So user could silence noisy processes if needed, but not increase the level. |
This adds possibility to filter logger messages on process basis. This feature is mostly useful for disabling logging in some processes or to increase logging verbosity during debugging.