Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable any log for a thread

Tags:

log4j

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 FATAL just for a few milliseconds?

like image 778
Llistes Sugra Avatar asked Nov 02 '10 16:11

Llistes Sugra


People also ask

How do I disable Logback log?

Logback does not allow logging to be disabled from the command line. However, if the configuration file allows it, you can set the level of loggers on the command line via a Java system property.


1 Answers

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.
like image 62
Ari Gesher Avatar answered Nov 10 '22 00:11

Ari Gesher