开发者

How to disable any log for a thread

开发者 https://www.devze.com 2023-01-22 22:33 出处:网络
I am using org.apache.log4j.Logger for logging and I am developing a jsp just for monitoring purposes.

I am using org.apache.log4j.Logger for logging and I am developing a jsp just for monitoring purposes. This jsp is using classes that write logs (INFO level) not interesting for this monitoring, but annoying, as long as I want to execute this jsp very often.

So, my question is the next: Is there any way to disable these INFO logs just for the thread where my jsp is running?

If there is not, maybe this approach might pay the bill: Is there any way to tell log4j level for one given class is FATA开发者_高级运维L just for a few milliseconds?


There's no easy way to do this using simple log4j config.

However, you can have your code install a custom filter on the appropriate logger. See the interface reference here:

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/spi/Filter.html

  1. Construct an object that implements the filter you want.
  2. Find the logger using LogManager.getLogger("loggername")
  3. Insert the filter.


Is the thread-id being logged? If so, can't you just use grep -v to remove the annoying lines that are for that thread and INFO level?

0

精彩评论

暂无评论...
验证码 换一张
取 消