ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pascal_Laf...@cwb.ca
Subject Re: setErrorPrintStream on DefaultLogger not working
Date Thu, 14 Oct 2004 20:08:04 GMT

This solution may not be what you are looking for but I used a kornshell to
capture ant output. The kornshell sets up the logging to a file and sends
me an email. This will only work on a Unix/Linux system.

I know Ant provides other methods but after consideration I decided on
this.

Here is sample code:
This probably does more then what you want but may give you some ideas.
What I do is pipe the ant console output to the tee command and place the
return parameter from ant in a tmp file so I don't lose it and send emails
according to the result. This solution gives the log output to the console,
log file and email.

...

    mail_text=/tmp/${invokinguser}_sde_check.mail

logfileprefix=/data/${environment}/batchsupp/${application}_ant_deploy.log.
    logfile=$logfileprefix$(date +%y%j)
    mail_address=/sys/appldeploy/${application}_email.idlist

    # Display the parameter list
    print "Application = $application" 2>&1 | tee -a $mail_text $logfile
    print "Environment = $environment" 2>&1 | tee -a $mail_text $logfile
    print "Deploying User = $invokinguser" 2>&1 | tee -a $mail_text
$logfile
    print "Requested Revision = $requested_revision" 2>&1 | tee -a
$mail_text $logfile

...

    print "***************************" 2>&1 | tee -a $mail_text $logfile
    print "Ant Deployment" 2>&1 | tee -a $mail_text $logfile
    print "Script start time $(date)" 2>&1 | tee -a $mail_text $logfile
    print "***************************\n" 2>&1 | tee -a $mail_text $logfile

    # This syntax permits us to preserve the return code of the and call so
it is not overwriten by the tee return code.
    (ant $* -Drevision_tag=$revision_tag -f /appl/run/script/appldeploy.xml
2>&1; echo $? >/tmp/antreturn.tmp) | tee -a $mail_text $log
file
    antreturn=$(cat /tmp/antreturn.tmp)
    rm /tmp/antreturn.tmp

    print "***************************" 2>&1 | tee -a $mail_text $logfile
    print "Ant Deployment" 2>&1 | tee -a $mail_text $logfile
    print "Script stop time $(date)" 2>&1 | tee -a $mail_text $logfile
    print "***************************\n" 2>&1 | tee -a $mail_text $logfile

...

    if((antreturn==0))
    then
      mail_title="Ant deployment successfull | app = $application | env
= $environment | user = $invokinguser"
      mail_list=$(<$mail_address)
      print "Ant script was successful" 2>&1 | tee -a $mail_text $logfile
    else
      mail_title="Failed ant deployment | app = $application | env
= $environment | user = $invokinguser"
      mail_list=$(<$mail_address)
      print "Ant script fail with $antReturn return code" 2>&1 | tee -a
$mail_text $logfile
    fi

    /appl/run/script/mail.ksh "$mail_list" "$mail_title" $mail_text 2>&1 |
tee -a $logfile

    oldlog=5
    . /appl/run/script/purgefile.ksh $oldlog $logfileprefix 2>&1 | tee -a
$logfile

...

rm $mail_text



                                                                                         
                                         
                      "Kelly Davis"                                                      
                                         
                      <kdavis@pobox.com        To:       "Ant Users List" <user@ant.apache.org>
                                   
                      >                        cc:                                    
                                            
                                               Subject:  Re: setErrorPrintStream on DefaultLogger
not working                      
                      10/14/2004 10:31                                                   
                                         
                      AM                                                                 
                                         
                      Please respond to                                                  
                                         
                      "Ant Users List"                                                   
                                         
                                                                                         
                                         
                                                                                         
                                         




perhaps I should re-state the question a little bit.

The problem that I am trying to solve is to be able to get compile
errors to a log file. When I run a build script using the ant task, and
set output= to a file, and the build script has compile errors, these
errors do not show up in the file specified in output, though I see them
on the console. The script will be running unattended using the api, so
it is important to be able to send the build error output somewhere
other than System.err. I would prefer this happen within the build
script and not in my code, but if necessary I will use the api.

Kelly Davis wrote:

> I am using ant 1.6.2 doing a build through the api.
> I am creating an instance of DefaultLogger. When I call
> setErrorPrintStream to a file for output, and then have a build with a
> compile error in it, the error output doesn't go to the file, but to
> my console. Any ideas on why this may be happening?
>
> Kelly




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









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


Mime
View raw message