Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Logging while building with Apache ANT

Posted on 2007-12-04
17
Medium Priority
?
592 Views
Last Modified: 2008-03-06
I am using Apache ANT 1.7 for building my projects.

I need logging during build using ant script (logging information like, build started, target started, target ended,build stopped).

Thanks
Sandeep
<project name="Test" default="all" basedir=".">
 
<property name="src.dir" value="${basedir}/src"/>
<property name="dest.dir" value="${basedir}/classes"/>
<property name="jar.dir" value="${basedir}/jar"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="jar.name" value="${ant.project.name}.jar"/>
 
<target name="all" depends="clean,comp,mkjar"/>
 
<path id="class.path">
	<fileset dir="${lib.dir}" includes="**/*.jar"/>
	<pathelement location="${dest.dir}"/>
</path>
 
<target name="clean">
 <delete dir="${dest.dir}"/>
 <delete file="${jar.dir}/${jar.name}"/>
 </target>
 
<target name="init" depends="clean">
  <mkdir dir="${dest.dir}"/>
  <mkdir dir="${dest.dir}/res"/>
  <mkdir dir="${jar.dir}"/>
</target>
 
<target name="comp" depends="clean,init">
 <javac srcdir="${src.dir}" destdir="${dest.dir}" debug="on" verbose="false">
    <classpath refid="class.path"/>
  </javac>
  <copy todir="${dest.dir}/res">
    <fileset dir="${basedir}/res"/>
  </copy>
</target>
 
<target name="mkjar" depends="comp">
 
  <jar jarfile="${jar.dir}/${jar.name}" 
       basedir="${dest.dir}">
  <manifest>
   <attribute name="Main-Class" value="${main.class}"/>
   <attribute name="Created-By" value="Sandeep"/>
   <attribute name="Class-Path" value="./lib/commons-httpclient-3.1.jar ./lib/commons-codec-1.3.jar ./lib/commons-logging-1.1.jar" />
  </manifest>
 </jar>
 
</target>
 
</project>

Open in new window

0
Comment
Question by:sandeep1984
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
17 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 20402118
use echo!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20402121
You could make it simple and use

<echo message="Build started" />
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20402124
For very verbose output you can do

ant -d
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:ksivananth
ID: 20402133
See http://ant.apache.org/manual/index.html for the log4j config!
0
 
LVL 2

Author Comment

by:sandeep1984
ID: 20402138
How to display the time?
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 20402144
you will have to specify the pattern in log4j config!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20402162
0
 
LVL 2

Author Comment

by:sandeep1984
ID: 20402165
How can I specify the patterns?
any example?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20402176
I've never run Ant with log4j logging, but i'd guess that would be even more verbose than the debug option - probably overkill
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 20402185
try this,
log4j.appender.stdout.layout.ConversionPattern=[%t] - %m%n

>>I've never run Ant with log4j logging

Actually, Ant uses log4j for printing messages even in console!
0
 
LVL 2

Author Comment

by:sandeep1984
ID: 20402237
Thanks for your efforts
I used log4j and got this output in build.log file

I am running ant as
ant -listener org.apache.tools.ant.listener.Log4jListener -lib .

My pog4j.properties configuration code snippet and the output file is here

How can I specify the time.

log4j.rootLogger=ERROR, LogFile
log4j.logger.org.apache.tools.ant.Project=INFO
log4j.logger.org.apache.tools.ant.Target=INFO
log4j.logger.org.apache.tools.ant.taskdefs=INFO
log4j.logger.org.apache.tools.ant.taskdefs.Echo=WARN
 
log4j.appender.LogFile=org.apache.log4j.FileAppender
log4j.appender.LogFile.layout=org.apache.log4j.PatternLayout
log4j.appender.LogFile.layout.ConversionPattern=[%6r] %8c{1} : %m%n
log4j.appender.LogFile.file=build.log
 
 
Output 
 
[     0]  Project : Build started.
[   422]   Target : Target "clean" started.
[   437]   Delete : Deleting directory C:\Projects\Code\SMSAPI\classes
[   578]   Delete : Deleting: C:\Projects\Code\SMSAPI\jar\SMSAPI.jar
[   578]   Target : Target "clean" finished.
[   578]   Target : Target "init" started.
[   593]    Mkdir : Created dir: C:\Projects\Code\SMSAPI\classes
[   593]    Mkdir : Created dir: C:\Projects\Code\SMSAPI\classes\res
[   593]   Target : Target "init" finished.
[   593]   Target : Target "comp" started.
[   640]    Javac : Compiling 1 source file to C:\Projects\Code\SMSAPI\classes
[  1936]    Javac : Note: C:\Projects\Code\SMSAPI\src\com\geneva\e2c\SendMessage.java uses or overrides a deprecated API.
[  1936]    Javac : Note: Recompile with -Xlint:deprecation for details.
[  1967]     Copy : Copying 1 file to C:\Projects\Code\SMSAPI\classes\res
[  1967]   Target : Target "comp" finished.
[  1967]   Target : Target "mkjar" started.
[  2014]      Jar : Building jar: C:\Projects\Code\SMSAPI\jar\SMSAPI.jar
[  2061]   Target : Target "mkjar" finished.
[  2061]   Target : Target "all" started.
[  2061]   Target : Target "all" finished.
[  2061]  Project : Build finished.

Open in new window

0
 
LVL 26

Expert Comment

by:ksivananth
ID: 20402252
try this,

log4j.appender.LogFile.layout.ConversionPattern=[%t]-[%6r] %8c{1} : %m%n
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 20402268
sorry t is to print the name of the thread, try the below rather...
{DATE_TIME};
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 800 total points
ID: 20402269
The field in the pattern should be something like

%d{dd MMM yyyy HH:mm:ss,SSS}
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 1200 total points
ID: 20402275
try either of the below,

%d{ISO8601} or %d{ABSOLUTE}.
0
 
LVL 2

Author Comment

by:sandeep1984
ID: 20402344
Thanks all.
Its working fine.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 20402363
:-)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question