Discussion:
How to echo date-time to log file?
Patrick Surry
2004-09-14 13:09:43 UTC
Permalink
This seems like a stupid question (and probably is!) but I can't seem to find
what I'm looking for anywhere obvious. I have a build that takes a long time,
and would like to be able to record the current date/time at various points
throughout the build. Just like you get when you run in 'verbose' mode but
without all the extra verbosity. Ideally I'd want something like a 'timestamp'
attribute in the echo task, so I could do things like:

<echo timestamp="true" message="Starting job..."/>
...
<echo timestamp="true" message="Finished job."/>

Are there any obvious solutions to this - running an exec with a 'time' command
seems like a hack, <tstamp/> doesn't really do what I want; the ant-contrib
<stopwatch/> doesn't give absolute times, just differences; the <record/> task
probably could change log verbosity to force ant-generated timestamps at
different points but again seems roundabout/overkill.

Patrick
Ankita Kapadia
2004-09-14 13:21:24 UTC
Permalink
<target name="dobuild" depends="settings">
<tstamp>
<format property="start" pattern="yyyy MMMM dd HH:mm:ss" locale="en"/>
</tstamp>

<echo message="Current time and date: ${start}" />
<property name="starttime" value="${start}"/>
.......
</target>

<target name="buildsuccess" depends="dobuild">
<tstamp>
<format property="NOW" pattern="yyyy MMMM dd HH:mm:ss" locale="en"/>
</tstamp>

<mail failonerror="false" ......" >
<from name="***@persistent.co.in" address="***@persistent.co.in"/>
<message>
...build status etc.......
Build Start Time : ${starttime}
Build End Time : ${NOW}
</message>
</target>



-----Original Message-----
From: Patrick Surry [mailto:***@quadstone.com]
Sent: Tuesday, September 14, 2004 6:40 PM
To: Ant Users List
Subject: How to echo date-time to log file?


This seems like a stupid question (and probably is!) but I can't seem to
find
what I'm looking for anywhere obvious. I have a build that takes a long
time,
and would like to be able to record the current date/time at various points
throughout the build. Just like you get when you run in 'verbose' mode but
without all the extra verbosity. Ideally I'd want something like a
'timestamp'
attribute in the echo task, so I could do things like:

<echo timestamp="true" message="Starting job..."/>
...
<echo timestamp="true" message="Finished job."/>

Are there any obvious solutions to this - running an exec with a 'time'
command
seems like a hack, <tstamp/> doesn't really do what I want; the ant-contrib
<stopwatch/> doesn't give absolute times, just differences; the <record/>
task
probably could change log verbosity to force ant-generated timestamps at
different points but again seems roundabout/overkill.

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Ankita Kapadia
2004-09-14 13:23:49 UTC
Permalink
Oops ! But this would echo only on the screen!

-----Original Message-----
From: Ankita Kapadia [mailto:***@persistent.co.in]
Sent: Tuesday, September 14, 2004 6:51 PM
To: Ant Users List
Subject: RE: How to echo date-time to log file?


<target name="dobuild" depends="settings">
<tstamp>
<format property="start" pattern="yyyy MMMM dd HH:mm:ss" locale="en"/>
</tstamp>

<echo message="Current time and date: ${start}" />
<property name="starttime" value="${start}"/>
.......
</target>

<target name="buildsuccess" depends="dobuild">
<tstamp>
<format property="NOW" pattern="yyyy MMMM dd HH:mm:ss" locale="en"/>
</tstamp>

<mail failonerror="false" ......" >
<from name="***@persistent.co.in" address="***@persistent.co.in"/>
<message>
...build status etc.......
Build Start Time : ${starttime}
Build End Time : ${NOW}
</message>
</target>



-----Original Message-----
From: Patrick Surry [mailto:***@quadstone.com]
Sent: Tuesday, September 14, 2004 6:40 PM
To: Ant Users List
Subject: How to echo date-time to log file?


This seems like a stupid question (and probably is!) but I can't seem to
find
what I'm looking for anywhere obvious. I have a build that takes a long
time,
and would like to be able to record the current date/time at various points
throughout the build. Just like you get when you run in 'verbose' mode but
without all the extra verbosity. Ideally I'd want something like a
'timestamp'
attribute in the echo task, so I could do things like:

<echo timestamp="true" message="Starting job..."/>
...
<echo timestamp="true" message="Finished job."/>

Are there any obvious solutions to this - running an exec with a 'time'
command
seems like a hack, <tstamp/> doesn't really do what I want; the ant-contrib
<stopwatch/> doesn't give absolute times, just differences; the <record/>
task
probably could change log verbosity to force ant-generated timestamps at
different points but again seems roundabout/overkill.

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Angeshwar Deepak
2004-09-14 13:33:52 UTC
Permalink
Hi,

I am not sure what you want, but you can echo something to a file using this method

<echo file="${site}"><![CDATA[<?xml version="1.0"?>
<site label="ForrestArticle" href="" xmlns="http://apache.org/forrest/linkmap/1.0" tab="">
<about label="Juna">
<!--WHAT EVER U WANT TO BE PUT INTO THE FILE-->
]]></echo>

.....some build content....

<echo file="${site}" append="true"> <![CDATA[
<level2 label="@{sitecomponent}" href="@{sitecomponent}/"> ]]></echo>

Where ${site} is the location and name of the log file. All the content in-between <![CDATA[ and ]]></echo> will be written to the ${file}.

Using this I was able to generate a seperate build file at 'run time', the same can be done for creating a log file.

bye,
with regards,
Deepak.


Oops ! But this would echo only on the screen!

Ankita Kapadia <***@persistent.co.in> wrote:Oops ! But this would echo only on the screen!

-----Original Message-----
From: Ankita Kapadia [mailto:***@persistent.co.in]
Sent: Tuesday, September 14, 2004 6:51 PM
To: Ant Users List
Subject: RE: How to echo date-time to log file?











.......










...build status etc.......
Build Start Time : ${starttime}
Build End Time : ${NOW}





-----Original Message-----
From: Patrick Surry [mailto:***@quadstone.com]
Sent: Tuesday, September 14, 2004 6:40 PM
To: Ant Users List
Subject: How to echo date-time to log file?


This seems like a stupid question (and probably is!) but I can't seem to
find
what I'm looking for anywhere obvious. I have a build that takes a long
time,
and would like to be able to record the current date/time at various points
throughout the build. Just like you get when you run in 'verbose' mode but
without all the extra verbosity. Ideally I'd want something like a
'timestamp'
attribute in the echo task, so I could do things like:


...


Are there any obvious solutions to this - running an exec with a 'time'
command
seems like a hack, doesn't really do what I want; the ant-contrib
doesn't give absolute times, just differences; the
task
probably could change log verbosity to force ant-generated timestamps at
different points but again seems roundabout/overkill.

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org




---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
Mike Popescu
2004-09-14 14:01:25 UTC
Permalink
Hi!

This is my first question in this mailinglist, so be clement with me. ;)

I try to replace a multiline-token with a multiline-value, but the token
is not recognised, so nothing is replaced.
But why?
If I give only a singleline-token, it is replaced by the multiline-value.

Could someone be so kind telling me where the fault is?

Thanky in advance!
Mike

------------------------------------------
Here the NOT WORKING multi-line version:
------------------------------------------
<target name="edit-grinder.scriptfile" description="Replaces the standard
values with the uservalues from runtest.properties"
depends="backup-grinder.propertiestemplate">
<replace file="${grinder.script.dir}/${grinder.propertiesfile}.bak">
<replacetoken><![CDATA[#
# This is grinder.properties.tmpl
# Do not edit anything here!
# Make your changes in your runtest.properties
#]]></replacetoken>
<replacevalue><![CDATA[#
# ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
ATTENTION!
#
# This file is changed automagically by ant
#
# If you change this file manually without knowing exactly what you
# are doing, chances are very good that your changes will not survive
# the next start of ant ;-)
#
# ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
ATTENTION!
#]]></replacevalue>
</replace>
<move file="${grinder.script.dir}/${grinder.propertiesfile}.bak"
tofile="${grinder.script.dir}/${grinder.propertiesfile}"/>
</target>
------------------------------------------
------------------------------------------
INPUT ("${grinder.script.dir}/${grinder.propertiesfile}.bak"):
------------------------------------------
#
# This is grinder.properties.tmpl
# Do not edit anything here!
# Make your changes in your runtest.properties
#


# grinder.processes=1
grinder.processes=[<grinder.processes>]
------------------------------------------
------------------------------------------
OUTPUT without any change
("${grinder.script.dir}/${grinder.propertiesfile}"):
------------------------------------------
#
# This is grinder.properties.tmpl
# Do not edit anything here!
# Make your changes in your runtest.properties
#


# grinder.processes=1
grinder.processes=[<grinder.processes>]
------------------------------------------
------------------------------------------
------------------------------------------
------------------------------------------
------------------------------------------
------------------------------------------
Here the working single-line version:
------------------------------------------
<target name="edit-grinder.scriptfile" description="Replaces the
standard values with the uservalues from runtest.properties"
depends="backup-grinder.propertiestemplate">
<replace file="${grinder.script.dir}/${grinder.propertiesfile}.bak">
<replacetoken><![CDATA[# This is
grinder.properties.tmpl]]></replacetoken>
<replacevalue><![CDATA[#
# ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
ATTENTION!
#
# This file is changed automagically by ant
#
# If you change this file manually without knowing exactly what you
# are doing, chances are very good that your changes will not survive
# the next start of ant ;-)
#
# ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
ATTENTION!
#]]></replacevalue>
</replace>
<move file="${grinder.script.dir}/${grinder.propertiesfile}.bak"
tofile="${grinder.script.dir}/${grinder.propertiesfile}"/>
</target>
------------------------------------------
------------------------------------------
OUTPUT ("${grinder.script.dir}/${grinder.propertiesfile}"):
------------------------------------------
#
#
# ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
ATTENTION!
#
# This file is changed automagically by ant
#
# If you change this file manually without knowing exactly what you
# are doing, chances are very good that your changes will not survive
# the next start of ant ;-)
#
# ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
ATTENTION!
#
# Do not edit anything here!
# Make your changes in your runtest.properties
#


# grinder.processes=1
grinder.processes=[<grinder.processerocesses>]
Daniels, Doug
2004-09-14 14:24:07 UTC
Permalink
Here's an idea:

You create a target in your build file called TimeStamp. Then to use this task you make <antcall..>'s to it and pass in the LogFile, and the Message properties to it. This allows you to have a generic logging timestamp task that can log messages to files with a timestamp.

Maybe someone has an idea of extending this, using macrodef, or whatever, I haven't really looked at that part of ant yet. Here is an example build file to give you an idea of how it can be used:

<project default="buildPartX">


<target name="timestamp">


<tstamp>

<format property="logtime" pattern="yyyy.MM.dd ':' HH:mm:ss z" />

</tstamp>

<echo file="${LogFile}" message="${logtime} :: ${Message}" append="true" />

</target>


<target name="buildPartX">

<!-- Define various log files to log to -->
<property name="BuildLog" value="build.log"/>
<property name="OtherLog" value="other.log"/>

<!--Do some work then print message with time -->

<antcall target="timestamp">
<param name="LogFile" value="${BuildLog}"/>
<param name="Message" value="I just finished this part of the build" />
</antcall>


<!-- Do some more work and print another message to a different log -->
<sleep seconds="2"/>

<antcall target="timestamp">
<param name="LogFile" value="${OtherLog}"/>
<param name="Message" value="I just finished another part of the build" />
</antcall>

</target>

</project>



-----Original Message-----
From: Patrick Surry [mailto:***@quadstone.com]
Sent: Tuesday, September 14, 2004 9:10 AM
To: Ant Users List
Subject: How to echo date-time to log file?


""

This seems like a stupid question (and probably is!) but I can't seem to find
what I'm looking for anywhere obvious. I have a build that takes a long time,
and would like to be able to record the current date/time at various points
throughout the build. Just like you get when you run in 'verbose' mode but
without all the extra verbosity. Ideally I'd want something like a 'timestamp'
attribute in the echo task, so I could do things like:

<echo timestamp="true" message="Starting job..."/>
...
<echo timestamp="true" message="Finished job."/>

Are there any obvious solutions to this - running an exec with a 'time' command
seems like a hack, <tstamp/> doesn't really do what I want; the ant-contrib
<stopwatch/> doesn't give absolute times, just differences; the <record/> task
probably could change log verbosity to force ant-generated timestamps at
different points but again seems roundabout/overkill.

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Vadim Kazakov
2004-09-14 14:44:34 UTC
Permalink
You could use the new macrodef task to create a macro instead of using
antcall

-----Original Message-----
From: Daniels, Doug [mailto:***@gdc4s.com]
Sent: September 14, 2004 8:24 AM
To: Ant Users List
Subject: RE: How to echo date-time to log file?

Here's an idea:

You create a target in your build file called TimeStamp. Then to use
this task you make <antcall..>'s to it and pass in the LogFile, and the
Message properties to it. This allows you to have a generic logging
timestamp task that can log messages to files with a timestamp.

Maybe someone has an idea of extending this, using macrodef, or
whatever, I haven't really looked at that part of ant yet. Here is an
example build file to give you an idea of how it can be used:

<project default="buildPartX">


<target name="timestamp">


<tstamp>

<format property="logtime" pattern="yyyy.MM.dd
':' HH:mm:ss z" />

</tstamp>

<echo file="${LogFile}" message="${logtime} ::
${Message}" append="true" />

</target>


<target name="buildPartX">

<!-- Define various log files to log to -->
<property name="BuildLog" value="build.log"/>
<property name="OtherLog" value="other.log"/>

<!--Do some work then print message with time -->

<antcall target="timestamp">
<param name="LogFile" value="${BuildLog}"/>
<param name="Message" value="I just finished
this part of the build" />
</antcall>


<!-- Do some more work and print another message to a
different log -->
<sleep seconds="2"/>

<antcall target="timestamp">
<param name="LogFile" value="${OtherLog}"/>
<param name="Message" value="I just finished
another part of the build" />
</antcall>

</target>

</project>



-----Original Message-----
From: Patrick Surry [mailto:***@quadstone.com]
Sent: Tuesday, September 14, 2004 9:10 AM
To: Ant Users List
Subject: How to echo date-time to log file?


""

This seems like a stupid question (and probably is!) but I can't seem to
find
what I'm looking for anywhere obvious. I have a build that takes a long
time,
and would like to be able to record the current date/time at various
points
throughout the build. Just like you get when you run in 'verbose' mode
but
without all the extra verbosity. Ideally I'd want something like a
'timestamp'
attribute in the echo task, so I could do things like:

<echo timestamp="true" message="Starting job..."/>
...
<echo timestamp="true" message="Finished job."/>

Are there any obvious solutions to this - running an exec with a 'time'
command
seems like a hack, <tstamp/> doesn't really do what I want; the
ant-contrib
<stopwatch/> doesn't give absolute times, just differences; the
<record/> task
probably could change log verbosity to force ant-generated timestamps at

different points but again seems roundabout/overkill.

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Stefan Bodewig
2004-09-14 14:56:02 UTC
Permalink
Post by Vadim Kazakov
You could use the new macrodef task to create a macro instead of
using antcall
Yes, but keep in mind that you'll have to use a different property
name in each invocation that way since the first invocation will set
the property "logtime" and subsequent invocations won't override it.

<antcall> gets around this by using a separate property context with
the new subbuild.

<macrodef name="logWithTimestamp">
<attribute name=logFile"/>
<attribute name=message"/>
<sequential>
<tstamp>
<format property="logtime.@{logFile}.@{message}"
pattern="yyyy.MM.dd ':' HH:mm:ss z"/>
</tstamp>
<echo file="${logFile}" append="true">${logtime.@{logFile}.@{message}} :: ${message}</echo>
</sequential>
</macrodef>

will work if you never try to log the same message to the same file
twice inside the same build. Otherwise you'll have to come up with a
smarter property name generation algorithm.

Stefan
--
http://stefanbodewig.blogger.de/
Peter Reilly
2004-09-14 15:03:21 UTC
Permalink
Using macrodef instead of antcall will not work here due to the
immutablity of properties.

If one assumes that all the messages are different one could write a macro
like:

<macrodef name="timestamp">
<attribute name="file"/>
<attribute name="message"/>
<sequential>
<tstamp>
<format property="logtime-@{message}" pattern="yyyy.MM.dd :
HH:mm:ss z"/>
</tstamp>
<echo file="@{logfile}" message="${logtime-@{message}} ::
@{message}" append="yes"/>
</sequential>
</macrodef>

but it would be more clear and correct to use a local property:
(see http://issues.apache.org/bugzilla/show_bug.cgi?id=23942)

<macrodef name="timestamp">
<attribute name="file"/>
<attribute name="message"/>
<sequential>
<local name="logtime"/>
<tstamp>
<format property="logtime" pattern="yyyy.MM.dd : HH:mm:ss z"/>
</tstamp>
<echo file="@{logfile}" message="${logtime} :: @{message}"
append="yes"/>
</sequential>
</macrodef>

Peter
Post by Vadim Kazakov
You could use the new macrodef task to create a macro instead of using
antcall
-----Original Message-----
Sent: September 14, 2004 8:24 AM
To: Ant Users List
Subject: RE: How to echo date-time to log file?
You create a target in your build file called TimeStamp. Then to use
this task you make <antcall..>'s to it and pass in the LogFile, and the
Message properties to it. This allows you to have a generic logging
timestamp task that can log messages to files with a timestamp.
Maybe someone has an idea of extending this, using macrodef, or
whatever, I haven't really looked at that part of ant yet. Here is an
<project default="buildPartX">
<target name="timestamp">
<tstamp>
<format property="logtime" pattern="yyyy.MM.dd
':' HH:mm:ss z" />
</tstamp>
${Message}" append="true" />
</target>
<target name="buildPartX">
<!-- Define various log files to log to -->
<property name="BuildLog" value="build.log"/>
<property name="OtherLog" value="other.log"/>
<!--Do some work then print message with time -->
<antcall target="timestamp">
<param name="LogFile" value="${BuildLog}"/>
<param name="Message" value="I just finished
this part of the build" />
</antcall>
<!-- Do some more work and print another message to a
different log -->
<sleep seconds="2"/>
<antcall target="timestamp">
<param name="LogFile" value="${OtherLog}"/>
<param name="Message" value="I just finished
another part of the build" />
</antcall>
</target>
</project>
-----Original Message-----
Sent: Tuesday, September 14, 2004 9:10 AM
To: Ant Users List
Subject: How to echo date-time to log file?
""
This seems like a stupid question (and probably is!) but I can't seem to
find
what I'm looking for anywhere obvious. I have a build that takes a long
time,
and would like to be able to record the current date/time at various
points
throughout the build. Just like you get when you run in 'verbose' mode
but
without all the extra verbosity. Ideally I'd want something like a
'timestamp'
<echo timestamp="true" message="Starting job..."/>
...
<echo timestamp="true" message="Finished job."/>
Are there any obvious solutions to this - running an exec with a 'time'
command
seems like a hack, <tstamp/> doesn't really do what I want; the
ant-contrib
<stopwatch/> doesn't give absolute times, just differences; the
<record/> task
probably could change log verbosity to force ant-generated timestamps at
different points but again seems roundabout/overkill.
Patrick
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
Vadim Kazakov
2004-09-14 15:02:51 UTC
Permalink
Ah true, I forgot about that part.

-----Original Message-----
From: Stefan Bodewig [mailto:***@apache.org]
Sent: September 14, 2004 8:56 AM
To: ***@ant.apache.org
Subject: Re: How to echo date-time to log file?
Post by Vadim Kazakov
You could use the new macrodef task to create a macro instead of
using antcall
Yes, but keep in mind that you'll have to use a different property
name in each invocation that way since the first invocation will set
the property "logtime" and subsequent invocations won't override it.

<antcall> gets around this by using a separate property context with
the new subbuild.

<macrodef name="logWithTimestamp">
<attribute name=logFile"/>
<attribute name=message"/>
<sequential>
<tstamp>
<format property="logtime.@{logFile}.@{message}"
pattern="yyyy.MM.dd ':' HH:mm:ss z"/>
</tstamp>
<echo file="${logFile}"
append="true">${logtime.@{logFile}.@{message}} :: ${message}</echo>
</sequential>
</macrodef>

will work if you never try to log the same message to the same file
twice inside the same build. Otherwise you'll have to come up with a
smarter property name generation algorithm.

Stefan
--
http://stefanbodewig.blogger.de/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Daniels, Doug
2004-09-14 15:32:10 UTC
Permalink
It's looking like defining timestamp as a target, and using <antcall..> to get local timestamp properties seems to be the easiest most straight forward approach. Because using <antcall...> with parameters is basically as simple as using the defined macrodef.

You could put the timestamp target into a commontargets.xml and use <import file="commontargets.xml"/> in your various build.xml's so you can re-use this functionality.

-----Original Message-----
From: Vadim Kazakov [mailto:***@quadrus.com]
Sent: Tuesday, September 14, 2004 11:03 AM
To: Ant Users List
Subject: RE: How to echo date-time to log file?


""

Ah true, I forgot about that part.

-----Original Message-----
From: Stefan Bodewig [mailto:***@apache.org]
Sent: September 14, 2004 8:56 AM
To: ***@ant.apache.org
Subject: Re: How to echo date-time to log file?
Post by Vadim Kazakov
You could use the new macrodef task to create a macro instead of
using antcall
Yes, but keep in mind that you'll have to use a different property
name in each invocation that way since the first invocation will set
the property "logtime" and subsequent invocations won't override it.

<antcall> gets around this by using a separate property context with
the new subbuild.

<macrodef name="logWithTimestamp">
<attribute name=logFile"/>
<attribute name=message"/>
<sequential>
<tstamp>
<format property="logtime.@{logFile}.@{message}"
pattern="yyyy.MM.dd ':' HH:mm:ss z"/>
</tstamp>
<echo file="${logFile}"
append="true">${logtime.@{logFile}.@{message}} :: ${message}</echo>
</sequential>
</macrodef>

will work if you never try to log the same message to the same file
twice inside the same build. Otherwise you'll have to come up with a
smarter property name generation algorithm.

Stefan
--
http://stefanbodewig.blogger.de/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@ant.apache.org
For additional commands, e-mail: user-***@ant.apache.org
Loading...