logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Stauffer" <stauffer.ja...@gmail.com>
Subject Re: Log4j.properties FileNotFound
Date Mon, 28 Aug 2006 11:54:45 GMT
if(new File("/path/to/log4j.properties").exists()) {
PropertyConfigurator.configure("/path/to/log4j.properties");
} else {
BasicConfigurator.configure();
}

On 8/28/06, Jon Hoffman <jhoffman@irbsearch.com> wrote:
> Hi,
> I am new to log4j and trying to use it for a project I am currently
> working on.  The problem is I would like to specify the location of the
> log4j.properties file:
>
> PropertyConfigurator.configure("/path/to/log4j.properties");
>
> But if the file is not found, I would like to use the Basic
> configuration:
>
> BasicConfigurator.configure();
>
> I figured I could catch the FileNotFoundException and call the basic
> configurator:
>
> try{
>     PropertyConfigurator.configure("/path/to/log4j.properties");
> } catch (FileNotFoundException e) {
>     BasicConfigurator.configure();
> }
> But I discovered that the PropertyConfigurator.configure does not throw
> a FileNotFoundException, it handles the exception and throws the error
> to the console.  Is there another way to do this?  I have searched the
> archive and the internet and could not find an answer, maybe I am not
> putting in the proper search terms because it seems like there should be
> an easy way to default to a Basic configuration if the properties file
> is not present.
> Thanks for any help you can provide.
>
> Jon Hoffman
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Mime
View raw message