You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Henrik Vendelbo <hv...@bluprints.com> on 2003/09/28 03:31:29 UTC

getConfigurationFileName()

Is there a way that I can get the filename and absolute path for the file
used to configure log4j. Once I am up and running, I would like to be able
to check that I am indeed using the right configuration file.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: getConfigurationFileName()

Posted by Scott Morgan <sc...@adligo.com>.
I agree that this would be a helpful way to determine what log4j config
file log4j uses (.properties or .xml).  However I have found my problem in
figuring out which config file to be even a bit more complex than which
file since I am usually loading log4j.xml form jar files it is always in
the root directory
/log4j.xml

This can be a time consuming process when you have 20 some odd jars that
you are loading.  I have resorted to simply printing all of the
significant loggers at startup;

public static void printLogLevels(String source) {
    Enumeration e = LogManager.getCurrentLoggers();
    while (e.hasMoreElements()) {
      Logger logger = (Logger) e.nextElement();
      if (logger.getLevel() != null ) {
        if (!logger.getLevel().equals("null")) {
          System.out.println(source + " " + logger.getName() + " is set to
level " +
                  logger.getLevel());
        }
      }
    }
    System.out.println("Finishing PrintLogLevels RootLogger is set to
level " + LogManager.getRootLogger().getLevel());
  }

It would be nice to also have a way to determine which jar loaded the
log4j config file.
-- 
Scott Morgan
President Adligo Inc.
Ph:  773-758-8735
Fax: 773-632-0568
http://www.adligo.com


> Is there a way that I can get the filename and absolute path for the
> file used to configure log4j. Once I am up and running, I would like to
> be able to check that I am indeed using the right configuration file.
>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: getConfigurationFileName()

Posted by Scott Morgan <sc...@adligo.com>.
Hi Henrik,

  Try;

   DOMConfigurator.configureAndWatch(YourClass.class.getResource("xml/log4j.xml"));
for log4j.xml
Or
   PropertyConfigurator.configureAndWatch("YourPropertyFile");
for log4j.properties


> Is there a way that I can get the filename and absolute path for the
> file used to configure log4j. Once I am up and running, I would like to
> be able to check that I am indeed using the right configuration file.
>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


-- 
Scott Morgan
President Adligo Inc.
Ph:  773-758-8735
Fax: 773-632-0568
http://www.adligo.com



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org