java tomcat打印日志级别,在运行时更改Tomcat中的日志记录级别?

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... ;-)

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值