I want to add some log.debug statements to a class I\'m working on, and I\'d like to see that in output when running the test. I\'d like to override the log4j properties on
With Log4j2, this can be achieved using the following utility method added to your code.
private static void setLogLevel() {
if (Boolean.getBoolean("log4j.debug")) {
Configurator.setLevel(System.getProperty("log4j.logger"), Level.DEBUG);
}
}
You need these imports
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
Now invoke the setLogLevel
method in your main() or whereever appropriate and pass command line params -Dlog4j.logger=com.mypackage.Thingie
and -Dlog4j.debug=true
.