-
Notifications
You must be signed in to change notification settings - Fork 1.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 support for JPMS layer/module filter for log events #3357
Comments
Filtering by module nameTo filter by module name you can use the existing <ScriptFilter>
<Script language="groovy"><![CDATA[
return "foo.bar.baz".equals(logEvent.getSource()?.moduleName)
]]></Script>
</ScriptFilter> Most of the out-of-the-box filters contained in Log4j Core 2 are inherited from Log4j 1. New filters are unlikely to be added to the collection unless:
Could you explain more, why do you need to filter by module name? Filtering by module layerCould you explain the purpose of filtering by module layer? My guess is that you have a multi-application runtime and you want to separate the logs from different applications. In this case you probably don't need filters, but something similar to the Jakarta EE log separation features:
|
Thank you very much for your help. I've understood how to get module name. About layers. I have a multi layer program where every layer is a subsystem. And often I need to get events only for concrete subsystem. As these subsystems can be added/removed dynamically I need a solution to separate them using java code. I've checked the link you provided (thanks again), but still can' find a way to get a layer from Or I should implement my own selector, using classloader:
|
@ranger2025, I don't know about module layers, but if what you're describing (i.e., having your hands on a I recently rewrote the extended exception pattern converter (i.e.,
@ranger2025, the sophistication needed in your use case makes me question if there is a better alternative to your approach. Would you mind telling us a little bit more about your use case, please? Can you point us some other multi-layered (F/OSS?) applications we can investigate? Can you show us applications where the problem you describe (i.e., only allow logging from the concrete subsystem) exists? |
@vy, thank you very much for sharing this information. I understand what you are talking about performance, but we plan to use it only for testing and debugging purposes. At least, now. However, it is necessary to find a solution for this problem, because module name without specifying the layer doesn't give a lot. I want to underline it, because it is very important. We have an application with plugins where plugin are added/removed dynamically. For for this plugins we use
As you see, in this configuration the same module is used by both plugins. So, when we want to get messages of the If it is not possible to get layer instance, I can try to get it from |
I figured out the problem. It's not about log4j2. It is about JPMS. I've just opened an issue about adding name property to |
This is the link to the issue - https://bugs.openjdk.org/browse/JDK-8347336 |
I suggest to add possibility to filter log events by ModuleLayer and Module.
Every module (automatic and explicit) has a name, so, there shouldn't be any problems. But with layers situation is more difficult, as layers don't have names and there is DAG of layers. The only way to solve this problem is to create map layer -> name. I mean that log4j2 user must create this map and fill it with values.
It is important to note, that module with same name can exist in different layers, that's why specifying only module is not enough, if it is not boot layer.
The text was updated successfully, but these errors were encountered: