3
votes

I am using JULI logging framework in current Tomcat 7, providing a webapp specific logging.properties in my WEB-INF/classes folder.

Now I am looking for a way to change the log level of a logger at runtime.

I found several sources saying that changing the level of a logger at runtime might be possible via MBean Server. Unfortunately the appropriate MBean "java.util.logging.Logging" does not list my webapp specific logger, so I cannot execute the method "setLoggerLevel".

Does anyone know how to accomplish this? Thanks for any hints - excluding those suggesting to use log4j, that is... ;-)

1

1 Answers

1
votes

Connecting JConsole to Tomcat and using the MBean tab to change the logger level is the ideal way. One issue is that the logger names don't exist unless the code has triggered the creation of a logger. You can't use the MBean to create a logger ahead of the code running. You should use JConsole to double check that the MBean itself doesn't exist.

Tomcat installs a custom LogManager that filters by the current class loader. JMX would be using the system class loader so it is possible that ClassLoaderLogManager won't return the logger names because the current classloader is not the web app classloader.

You could always create a servlet/jsp form or webservice deployed with the application to get the logger and set the level. You might have to pin each modified logger in memory to keep your logger level active. You can free the logger once the level is set back to null. You'll have to deal with security concerns with including such a page.

I wouldn't do this on a production server but you can configure a WatchedResource in tomcat that points to your logging.properties. Then any time that file is updated the web app is redeployed with the new settings. Watch out for ClassLoader leaks going that route.