I have a Java app while parses input from a spreadsheet. I've added the ability to run just the parser part standalone from an ant task. However the normal log4j pattern I'm using can make the output hard to read, I'd like to set a simple pattern at runtime.
So something like log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %m%n
parseDebug = new Boolean(System.getProperty("ptpunit.parseDebug")).booleanValue();
if(parseDebug){
// SET CONVERSION PATTERN HERE
log.setLevel((Level) Level.DEBUG);
}
I think you could do something like this:
ConsoleAppender a = (ConsoleAppender) Logger.getRootLogger().getAppender("stdout");
a.setLayout(new PatternLayout("%d{HH:mm:ss} %-5.5p %t %m%n"));
Of course you have to change the Appender type according to the one you are using and you may have to replace "Logger.getRootLogger()" by the a call to fetch the logger your appender is actually attached to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With