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 Jon Hoffman <jh...@irbsearch.com> on 2006/08/28 13:49:36 UTC

Log4j.properties FileNotFound

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

Re: Log4j.properties FileNotFound

Posted by James Stauffer <st...@gmail.com>.
if(new File("/path/to/log4j.properties").exists()) {
PropertyConfigurator.configure("/path/to/log4j.properties");
} else {
BasicConfigurator.configure();
}

On 8/28/06, Jon Hoffman <jh...@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