I'm using WildFly 11 and I'm trying to set the log level programatically. When I call Logger.getRootLogger I get a LoggerNode and can't access the handlers / appenders, even though when I debug I can see them. You can set the level of the root logger, but this won't do the trick. It is getting frustrating, since I could not find anything of any use into the official documentation. Can anyone help?
Asked
Active
Viewed 617 times
1
-
1Looks like wildfly [supports](https://github.com/wildfly-extras/wildfly-camel/issues/2256) log4j2. Have you tried coding it similar to [this](https://www.baeldung.com/log4j2-programmatic-config)? It shows a step by step guide of configuring appenders and loggers. – Andy Dufresne Jan 21 '19 at 06:14
-
I'm using log4j. I found an workaround, eventually, but this does not answer my question. The workaround is to have a default log level for root logger and have the target handler without any log level property into standalone.xml. This way, when you change the log level of root logger, all handlers without a default log level will inherit from this. But, to mention again, I couldn't find any way to access the handler, and by handlers I mean LoggerNode, and all handlers with a log level will remain unchanged. – user2963757 Jan 21 '19 at 14:00
-
So basically you want to programmatically configure the appender with log4j (version 1), right? – Andy Dufresne Jan 22 '19 at 05:35
-
Yes, that is correct – user2963757 Jan 22 '19 at 07:37
-
1I wouldn't advise trying to use the log manager directory. The management API's are designed to update configurations for server components. – James R. Perkins Jan 24 '19 at 00:41
-
[Looks like](https://stackoverflow.com/a/6103091/537503) it just boils down to 1. creating the appender 2. Getting the root logger & 3. Adding the appender to the logger. Can you give it a try? – Andy Dufresne Jan 25 '19 at 10:54
-
The appender is there already. But there is no way to access it programatically. You can only get the root logger and set the log level of this one. But maybe this is the way it is supposed to behave by default, in the sense that should protect the appenders log level at runtime – user2963757 Jan 26 '19 at 11:18