I'm working on a project that uses Log4J via Commons.
I'm trying to find the path to the log file, but I'm not finding an appropriate method that will return the logfile path from the Logger.
Anyone ever attempted this?
The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.
By default, Log4j logs to standard output and that means you should be able to see log messages on your Eclipse's console view. To log to a file you need to use a FileAppender explicitly by defining it in a log4j. properties file in your classpath.
Apache Log4j is a Java-based logging utility originally written by Ceki Gülcü. It is part of the Apache Logging Services, a project of the Apache Software Foundation. Log4j is one of several Java logging frameworks.
You have to get all appenders from the root logger and then get the name of the log file.
Enumeration e = Logger.getRootLogger().getAllAppenders();
while ( e.hasMoreElements() ){
Appender app = (Appender)e.nextElement();
if ( app instanceof FileAppender ){
System.out.println("File: " + ((FileAppender)app).getFile());
}
}
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