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 AcidDragon <ac...@gmail.com> on 2010/03/19 15:05:26 UTC

dailyrollingfileappender file location

I use an xml file to configure my logger, how can I change the
dailyrollingfileappender file path from my java program?

The reason I want to change it is that the program may be installed in
various paths for different deployments, so I do not want to hardcode the
location of the log file in my log4j.xml, I want to change it to the start
path of my java class file. I already get the start path so I just need to
understand how to reconfigure the file path.

Thanks

Hendry

Re: dailyrollingfileappender file location

Posted by AcidDragon <ac...@gmail.com>.
I know I need to use *DOMConfigurator.

setParameter(Element
<http://www.docjar.com/docs/api/org/w3c/dom/Element.html> elem,

PropertySetter <http://www.docjar.com/docs/api/org/apache/log4j/config/PropertySetter.html>
propSetter,

Properties <http://www.docjar.com/docs/api/java/util/Properties.html> props)

*
*
*
*But I have not been able to figure out what the 3 parms would equate to.*
*
*
*The PrpoertySetter I guess would be something like
propSetter.setProperty(name,
value)*
*
*
*and in my case the name would be "File" and the value the path and file
name.*
*
*
*But what must the Element and Properties values be.*
*
*
*Regards*
*
*
*Hendry*
*
*
On 20 March 2010 02:11, Curt Arnold <ca...@apache.org> wrote:

> Not sure exactly what you mean by start path, but you use do
>
> <param name="file" value="${user.dir}/filename.log"/>
>
> which would evaluate to the current working directory when the
> configuration is read or you could use your own property (set on command
> line or using System.setProperty() before configuration) instead of
> user.dir.
>
> Otherwise, you would need to find the appender, likely by getting a known
> logger and then querying its attached appenders, cast the appender to a
> specific appender class, call the setFile() and activateOptions method.
>  Would be a lot messier.
>
>
> On Mar 19, 2010, at 9:05 AM, AcidDragon wrote:
>
> > I use an xml file to configure my logger, how can I change the
> > dailyrollingfileappender file path from my java program?
> >
> > The reason I want to change it is that the program may be installed in
> > various paths for different deployments, so I do not want to hardcode the
> > location of the log file in my log4j.xml, I want to change it to the
> start
> > path of my java class file. I already get the start path so I just need
> to
> > understand how to reconfigure the file path.
> >
> > Thanks
> >
> > Hendry
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: dailyrollingfileappender file location

Posted by Curt Arnold <ca...@apache.org>.
Not sure exactly what you mean by start path, but you use do

<param name="file" value="${user.dir}/filename.log"/>

which would evaluate to the current working directory when the configuration is read or you could use your own property (set on command line or using System.setProperty() before configuration) instead of user.dir.

Otherwise, you would need to find the appender, likely by getting a known logger and then querying its attached appenders, cast the appender to a specific appender class, call the setFile() and activateOptions method.  Would be a lot messier.


On Mar 19, 2010, at 9:05 AM, AcidDragon wrote:

> I use an xml file to configure my logger, how can I change the
> dailyrollingfileappender file path from my java program?
> 
> The reason I want to change it is that the program may be installed in
> various paths for different deployments, so I do not want to hardcode the
> location of the log file in my log4j.xml, I want to change it to the start
> path of my java class file. I already get the start path so I just need to
> understand how to reconfigure the file path.
> 
> Thanks
> 
> Hendry


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