From: http://www.gunith.com/2010/11/how-to-get-the-file-path-of-a-log4j-log-file/
Suppose the log4j.properties file is shown below:
log4j.logger.migrationlog = INFO, migration log4j.appender.migration = org.apache.log4j.RollingFileAppender log4j.appender.migration.File = C:/work/log/migration.log log4j.appender.migration.MaxFileSize=20MB log4j.appender.migration.MaxBackupIndex=1 log4j.appender.migration.layout = org.apache.log4j.PatternLayout log4j.appender.migration.layout.conversionPattern = %d %-5p %c - %m%n
In this case, your Java code should be as follows:
Logger logger = Logger.getLogger("migrationlog"); //Defining the Logger FileAppender appender = (FileAppender)logger.getAppender("migration"); return new File(appender.getFile());
Note that miglog was used to create the log object in the first line. And migration is used to get the FileAppender file, which in turn calls getFile () to get the log file.
Basil musa
source share