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 Friedbert Widmann <Fr...@hoerbiger.com> on 2008/04/30 09:37:38 UTC

Ant, log4j: Defining log file path with ant properties

Is it possible, to overwrite the path of the logfile with properties set within
the project build file.

Example: I want to define a target like the following:
	<target name="init">
		<mkdir dir="${dir}/log" />
		<property key="log.file" value="${dir}/log/build.log" />
		<magic> reopen log4j logfiles </magic>
	</target>
It defines a project specific directory for the logfiles and should overwrite
the definitions in log4j.properties.
The log4j.properties should look like:
	log4j.rootLogger=INFO, LogFile
	log4j.appender.LogFile.File=${log.file}

Mit freundlichen Grüßen, / With best regards,
Friedbert Widmann


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


Re: Antwort: Re: Ant, log4j: Defining log file path with ant properties

Posted by Jacob Kjome <ho...@visi.com>.
ant -Ddir=/path/to/dir someAntTarget


Jake


On Mon, 5 May 2008 09:33:59 +0200
  friedbert.widmann@hoerbiger.com wrote:
> Thank you, Jake,
> 
> but your suggestion is not what I am looking for.
> 
> Jacob Kjome <ho...@visi.com> schrieb am 01.05.2008 08:09:46:
>> Sure, are you wanting logs for unit tests or something?  Then just
>> define a system property to set inside the junit task....
>> <junit ....>
>> <sysproperty key="log.file"
>>              value="${dir}/log/build.log"/>
>> </junit>
> 
> The element sysproperty is usable only in the junit task. I am looking for
> a solution, which works for any tasks.
> My scenario: I have to implement an installation job and try to use ant. So
> the different installation steps are done by ant targets. The first step is
> to copy the whole directory structure from the installation medium (CD/DVD)
> to hard disk. During this first step the logging should go to a
> site-specific directory on the hard disk (e.g. D:/appl/log/build.log). The
> subsequent steps are called from the site-specific directory
> (cwd==D:/appl), so the log file can be specified relative (e.g.
> ./log/build.log).
> I tried to specify the log directory with a property in log4j.properties
>   dir=.
>   log4j.appender.LogFile.File=${dir}/log/build.log
> and to override this directory by a property definition within an ant
> target.
> But it doesn´t work. I believe, the file log4j.properties is read and
> interpreted before the ant targets are executed. Therefore the overwritten
> property has never priority before the default value in log4j.properties.
> 
> Thanks
>      Widmann
> 
>>
>> Friedbert Widmann wrote:
>> > Is it possible, to overwrite the path of the logfile with
>> properties set within
>> > the project build file.
>> >
>> > Example: I want to define a target like the following:
>> >    <target name="init">
>> >       <mkdir dir="${dir}/log" />
>> >       <property key="log.file" value="${dir}/log/build.log" />
>> >       <magic> reopen log4j logfiles </magic>
>> >    </target>
>> > It defines a project specific directory for the logfiles and
>> should overwrite
>> > the definitions in log4j.properties.
>> > The log4j.properties should look like:
>> >    log4j.rootLogger=INFO, LogFile
>> >    log4j.appender.LogFile.File=${log.file}
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 


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


Antwort: Re: Ant, log4j: Defining log file path with ant properties

Posted by fr...@hoerbiger.com.
Thank you, Jake,

but your suggestion is not what I am looking for.

Jacob Kjome <ho...@visi.com> schrieb am 01.05.2008 08:09:46:
> Sure, are you wanting logs for unit tests or something?  Then just
> define a system property to set inside the junit task....
> <junit ....>
> <sysproperty key="log.file"
>              value="${dir}/log/build.log"/>
> </junit>

The element sysproperty is usable only in the junit task. I am looking for
a solution, which works for any tasks.
My scenario: I have to implement an installation job and try to use ant. So
the different installation steps are done by ant targets. The first step is
to copy the whole directory structure from the installation medium (CD/DVD)
to hard disk. During this first step the logging should go to a
site-specific directory on the hard disk (e.g. D:/appl/log/build.log). The
subsequent steps are called from the site-specific directory
(cwd==D:/appl), so the log file can be specified relative (e.g.
./log/build.log).
I tried to specify the log directory with a property in log4j.properties
   dir=.
   log4j.appender.LogFile.File=${dir}/log/build.log
and to override this directory by a property definition within an ant
target.
But it doesn´t work. I believe, the file log4j.properties is read and
interpreted before the ant targets are executed. Therefore the overwritten
property has never priority before the default value in log4j.properties.

Thanks
      Widmann

>
> Friedbert Widmann wrote:
> > Is it possible, to overwrite the path of the logfile with
> properties set within
> > the project build file.
> >
> > Example: I want to define a target like the following:
> >    <target name="init">
> >       <mkdir dir="${dir}/log" />
> >       <property key="log.file" value="${dir}/log/build.log" />
> >       <magic> reopen log4j logfiles </magic>
> >    </target>
> > It defines a project specific directory for the logfiles and
> should overwrite
> > the definitions in log4j.properties.
> > The log4j.properties should look like:
> >    log4j.rootLogger=INFO, LogFile
> >    log4j.appender.LogFile.File=${log.file}


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


Re: Ant, log4j: Defining log file path with ant properties

Posted by Jacob Kjome <ho...@visi.com>.
Sure, are you wanting logs for unit tests or something?  Then just define a system
property to set inside the junit task....

<junit ....>
<sysproperty key="log.file"
             value="${dir}/log/build.log"/>
</junit>


Jake

Friedbert Widmann wrote:
> Is it possible, to overwrite the path of the logfile with properties set within
> the project build file.
> 
> Example: I want to define a target like the following:
> 	<target name="init">
> 		<mkdir dir="${dir}/log" />
> 		<property key="log.file" value="${dir}/log/build.log" />
> 		<magic> reopen log4j logfiles </magic>
> 	</target>
> It defines a project specific directory for the logfiles and should overwrite
> the definitions in log4j.properties.
> The log4j.properties should look like:
> 	log4j.rootLogger=INFO, LogFile
> 	log4j.appender.LogFile.File=${log.file}
> 
> Mit freundlichen Grüßen, / With best regards,
> Friedbert Widmann
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> 
> 

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