Setting log4j log level programmatically


private static void setupLog4j() {
System.out.println("setupLog4j");
BasicConfigurator.resetConfiguration();
// Start clean.
Logger.getRootLogger().removeAllAppenders();
// Create appender
ConsoleAppender console = new ConsoleAppender();
// Configure the appender
String PATTERN = "%d --[ %p ] %l: %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.activateOptions();
console.setName("stdout");
Logger.getRootLogger().setLevel(Level.DEBUG);
BasicConfigurator.configure(console);
LOG = Logger.getLogger(MinerTest.class);
}

Knowing you exception class name

To know what is your exception class name, in case you want to have a more specific catch.

} catch (Exception e){
LOG.error("SQL error when processing " + requestId+". Exception class:"+ e.getClass().getCanonicalName());
throw(e);
}