Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set the logging level within a Java method using log4j?

Tags:

java

log4j

I've got one method in a class that is very verbose, and this makes the logs hard to read. I'd like to reduce its logging by just changing the level of that one method, leaving other methods in the same class unaltered. Is this possible?

like image 567
alex.collins Avatar asked Nov 12 '12 12:11

alex.collins


People also ask

How do I change log level in Log4j?

Setting Levels using Configuration File log4j provides you configuration file based level setting which sets you free from changing the source code when you want to change the debugging level. Following is an example configuration file which would perform the same task as we did using the log. setLevel(Level.

How do I change the logging level in Java?

Java Util Logging - Log Levels To change a log level we must use Logger#setLevel() and Handler#setLevel() .


1 Answers

You can change the level configuration for that class but not for specific methods in a class. The only way to do what you want would be to use a different logger inside that method and then configure it at a different level.

Hope this helps.

like image 165
cjstehno Avatar answered Sep 17 '22 15:09

cjstehno