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 Chris Kimball <ma...@cvkimball.com> on 2008/10/22 13:43:04 UTC

Start-up configuration

I'm using a DOMConfigurator successfully in a jar-bundled, cross platform
app.

But the configuration file is currently a resource within the bundle,
unmodifiable by a user.

I'd like to copy the configuration file out once the app gets started and
the app knows where to place files, so that the user can set his own warning
levels, etc.

1. How do I start the app then have the app take it's configuration file
from an internally calculated area?

2. How do I specify an output file on a cross platform basis?  If I define
the output log file as "log.txt", what directory does it turn up in under
various systems?

Chris Kimball
-- 
View this message in context: http://www.nabble.com/Start-up-configuration-tp20108988p20108988.html
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Start-up configuration

Posted by Jacob Kjome <ho...@visi.com>.
On Wed, 22 Oct 2008 04:43:04 -0700 (PDT)
  Chris Kimball <ma...@cvkimball.com> wrote:
> 
> I'm using a DOMConfigurator successfully in a jar-bundled, cross platform
> app.
> 
> But the configuration file is currently a resource within the bundle,
> unmodifiable by a user.
> 
> I'd like to copy the configuration file out once the app gets started and
> the app knows where to place files, so that the user can set his own warning
> levels, etc.
> 
> 1. How do I start the app then have the app take it's configuration file
> from an internally calculated area?
> 

What do you mean by "Internally calculated area".  Internally calculated by 
the application?  Internally calculated by the user?  Other?

Users can specify the config file by setting...

-Dlog4j.configuration=file:/path/to/log4j.xml

There is really no need to manually configure log4j.  And I really discourage 
placing the log4j config file in your application and any manual configuration 
facility should be user-specified, not library specified.  Logging is a 
user-concern, not a library writer concern.  If users want logging, they can 
always place a log4j.properties or log4j.xml file in the classpath and they'll 
get their logging.  You can provide a suggested config file separately, but 
don't load it yourself.  That's the user's domain.

> 2. How do I specify an output file on a cross platform basis?  If I define
> the output log file as "log.txt", what directory does it turn up in under
> various systems?
> 

You can specify a Java system property, such as "log.home" and reference it 
as...

log4j.appender.MYAppender.File=${log.home}/logs/log.txt

The user can set this value by adding -Dlog.home=/path/to/logdir


Jake

> Chris Kimball
> -- 
> View this message in context: 
>http://www.nabble.com/Start-up-configuration-tp20108988p20108988.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: Start-up configuration

Posted by Curt Arnold <ca...@apache.org>.
On Oct 22, 2008, at 6:43 AM, Chris Kimball wrote:

>
> I'm using a DOMConfigurator successfully in a jar-bundled, cross  
> platform
> app.
>
> But the configuration file is currently a resource within the bundle,
> unmodifiable by a user.
>
> I'd like to copy the configuration file out once the app gets  
> started and
> the app knows where to place files, so that the user can set his own  
> warning
> levels, etc.
>
> 1. How do I start the app then have the app take it's configuration  
> file
> from an internally calculated area?

Call DOMConfigurator.configure() before any logging request (which  
would trigger default configuration) or call LogManager.reset() and  
then DOMConfigurator.configure().

>
>
> 2. How do I specify an output file on a cross platform basis?  If I  
> define
> the output log file as "log.txt", what directory does it turn up in  
> under
> various systems?

Relative paths would be interpreted relative to the current working  
directory.  You can use property expressions (see Javadoc for  
System.getProperties() for list of predefined properties) like "$ 
{java.io.tmpdir}/log.txt" if you want to place the log in the  
temporary directory or "${user.home}/log.txt" if you want to place in  
the user's home directory.

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