0

Many answers around with option of .setlevel() option,which isn't working in my case because of the below .

Scenario:

  • log4j.xml file under resources is kept with ERROR mode while jetty startup.

Code:

private static Logger logger = Logger.getLogger(test.class);
private static final boolean DEBUG = logger.isDebugEnabled();


if(DEBUG){ //DEBUG will be false as the logging level is set to ERROR
logger.debug("This should print,but it will not print as DEBUG will be set as false during startup"); 
}

Thanks in advance for your suggestions .

sarav
  • 47
  • 9

1 Answers1

0

2 solutions:

1. Correct one

Change your mode to the desired one. You should not change the logging level at runtime like that. On test platforms, your log level should be DEBUG. On production, INFO.

2. Dirty one

see Dynamically add appender with slf4j and log4j2. It should be your latest solution.

Max
  • 511
  • 8
  • 18