I have some legacy code where there are lot of e.printStackTrace()
, those are not printed in log4j file for obvious reasons. The latest code does have log.error("Exception occured in class::method",e);
. Is there a standard way of logging those legacy e.printStackTrace()
in log4j?
Here is my log4j.properties. I am setting up the property file/log file name within the code
PropertyConfigurator.configure("log4j.properties");
setLog4jFile("log.txt");
private static void setLog4jFile(String logFileName) {
try {
Logger rootLogger = Logger.getRootLogger();
RollingFileAppender appender = new RollingFileAppender(new PatternLayout("%p %t %c - %m%n"), logFileName, false);
appender.setMaxFileSize("10000KB");
appender.setMaxBackupIndex(10);
rootLogger.addAppender(appender);
}catch (Exception e) {
e.printStackTrace();
}
}
log4j.properties
log4j.rootCategory=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F%L) - %m%n