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 Erik Price <ep...@ptc.com> on 2003/04/23 21:25:59 UTC

[OT] dynamically setting a logfile location

Hi,

I am using a fairly simply Log4J properties file to configure the 
loggers in my application.  The application itself, when fully built, is 
an executable JAR for which I have written a simple shell script wrapper 
to spare the user from having to remember all of the command line 
parameters for calling a JAR.  (Eventually I will write a batch script 
for Win32.)  This is also a very handy way for me to pass the URI of my 
logfile, my command line is similar to this:

<allOneLine>
$JAVACMD "-Dlog4j.configuration=file:${OATMEAL_BIN}/distlog.properties" 
-jar "${OATMEAL_LIB}/oatmeal.jar" $@
</allOneLine>

This is more a Java question than a Log4J question, but it seems 
relevant since Log4J is a good example of software that doesn't require 
you to hard-code properties into the code:  I am wondering if there is 
some way that I can pass the intended location of the FileAppender using 
my wrapper script, so that instead of this:

log4j.appender.Append1.File=dist.log

I can do something like this:

lo4j.appender.Append1.File=${dist.log}


Any luck?

TIA,


Erik


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


Re: [OT] dynamically setting a logfile location

Posted by Erik Price <ep...@ptc.com>.

Steve Ebersole wrote:
> Yes you can do that.  For example:
> 
> lo4j.appender.Append1.File=${OATMEAL_HOME}/logs/dist.log
> 
> Or:
> export OATMEAL_LOG=${OATMEAL_HOME}/logs/dist.log
> and
> lo4j.appender.Append1.File=${OATMEAL_LOG}

Thanks Steve.  Is this Log4J-specific, or can do this in any properties 
file?  It didn't say anything in the Properties Javadoc.



Erik


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


Re: [OT] dynamically setting a logfile location

Posted by Steve Ebersole <st...@austin.rr.com>.
Yes you can do that.  For example:

lo4j.appender.Append1.File=${OATMEAL_HOME}/logs/dist.log

Or:
export OATMEAL_LOG=${OATMEAL_HOME}/logs/dist.log
and
lo4j.appender.Append1.File=${OATMEAL_LOG}

HTH


----- Original Message ----- 
From: "Erik Price" <ep...@ptc.com>
To: "Log4J Users List" <lo...@jakarta.apache.org>
Sent: Wednesday, April 23, 2003 2:25 PM
Subject: [OT] dynamically setting a logfile location


> Hi,
> 
> I am using a fairly simply Log4J properties file to configure the 
> loggers in my application.  The application itself, when fully built, is 
> an executable JAR for which I have written a simple shell script wrapper 
> to spare the user from having to remember all of the command line 
> parameters for calling a JAR.  (Eventually I will write a batch script 
> for Win32.)  This is also a very handy way for me to pass the URI of my 
> logfile, my command line is similar to this:
> 
> <allOneLine>
> $JAVACMD "-Dlog4j.configuration=file:${OATMEAL_BIN}/distlog.properties" 
> -jar "${OATMEAL_LIB}/oatmeal.jar" $@
> </allOneLine>
> 
> This is more a Java question than a Log4J question, but it seems 
> relevant since Log4J is a good example of software that doesn't require 
> you to hard-code properties into the code:  I am wondering if there is 
> some way that I can pass the intended location of the FileAppender using 
> my wrapper script, so that instead of this:
> 
> log4j.appender.Append1.File=dist.log
> 
> I can do something like this:
> 
> lo4j.appender.Append1.File=${dist.log}
> 
> 
> Any luck?
> 
> TIA,
> 
> 
> Erik
> 
> 
> ---------------------------------------------------------------------
> 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: [OT] dynamically setting a logfile location

Posted by Erik Price <ep...@ptc.com>.

Jacob Kjome wrote:
> 
> It should work fine if you set the "dist.log" system variable.  This 
> should work with property config files.  I know it works with xml config 
> files.  The InitContextListener I wrote actually supports this so that 
> you can just reference a system variable in your log4j.xml file for the 
> FileAppender.  The Javadoc explains how everything works.  See the 
> InitContextListener here...

Excellent, thanks Jacob.


Erik


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


Re: [OT] dynamically setting a logfile location

Posted by Jacob Kjome <ho...@visi.com>.
It should work fine if you set the "dist.log" system variable.  This should 
work with property config files.  I know it works with xml config 
files.  The InitContextListener I wrote actually supports this so that you 
can just reference a system variable in your log4j.xml file for the 
FileAppender.  The Javadoc explains how everything works.  See the 
InitContextListener here...

http://cvs.apache.org/viewcvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/


Jake



At 03:25 PM 4/23/2003 -0400, you wrote:
>Hi,
>
>I am using a fairly simply Log4J properties file to configure the loggers 
>in my application.  The application itself, when fully built, is an 
>executable JAR for which I have written a simple shell script wrapper to 
>spare the user from having to remember all of the command line parameters 
>for calling a JAR.  (Eventually I will write a batch script for 
>Win32.)  This is also a very handy way for me to pass the URI of my 
>logfile, my command line is similar to this:
>
><allOneLine>
>$JAVACMD "-Dlog4j.configuration=file:${OATMEAL_BIN}/distlog.properties" 
>-jar "${OATMEAL_LIB}/oatmeal.jar" $@
></allOneLine>
>
>This is more a Java question than a Log4J question, but it seems relevant 
>since Log4J is a good example of software that doesn't require you to 
>hard-code properties into the code:  I am wondering if there is some way 
>that I can pass the intended location of the FileAppender using my wrapper 
>script, so that instead of this:
>
>log4j.appender.Append1.File=dist.log
>
>I can do something like this:
>
>lo4j.appender.Append1.File=${dist.log}
>
>
>Any luck?
>
>TIA,
>
>
>Erik
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org