Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Log4J log file

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?

like image 906
wadesworld Avatar asked Dec 09 '10 17:12

wadesworld


People also ask

Where is the Log4j log file?

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.

Where does Log4j log by default?

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.

What are Log4j files?

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.


1 Answers

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());
      }
    }
like image 88
dogbane Avatar answered Oct 06 '22 07:10

dogbane