ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joern Engmann <J.Engm...@intershop.de>
Subject Unexpected behaviour of Ant task logging
Date Fri, 28 Mar 2003 11:13:54 GMT
Hi!
 
I found an unexpected behavior of the Ant task. When I use a special logger
in the parent process, normally I want to use the same logger type for the
sub process. At this time the Ant task uses DefaultLogger in any way.
Additionally its not possible to set a special Logger in the Ant task.
 
The following code should solve the Problem. It would be nice if it could be
in the next releases of Ant.
 
    protected void initializeProject() 
    {
        newProject.setInputHandler(getProject().getInputHandler());
 
        Vector listeners = getProject().getBuildListeners();
        final int count = listeners.size();
        for (int i = 0; i < count; i++) {
            newProject.addBuildListener((BuildListener)
listeners.elementAt(i));
        }
 
        if (output != null) {
            File outfile = null;
            if (dir != null) {
                outfile = FileUtils.newFileUtils().resolveFile(dir, output);
            } else {
                outfile = getProject().resolveFile(output);
            }
            //changed Code
            try {
                out = new PrintStream(new FileOutputStream(outfile));
                BuildLogger logger = null;
                if (loggerName!=null)
                {
                 logger =
(BuildLogger)Class.forName(this.loggerName).newInstance();
                } 
                else
                {
                 int i = listeners.size()-1;
                 while ((!(listeners.elementAt(i) instanceof BuildLogger))
&& (i > -1))
                  i--;
                 if(i > -1)
                  logger =
(BuildLogger)listeners.elementAt(i).getClass().newInstance();
                 else
                  logger = new DefaultLogger();
                } 
                logger.setMessageOutputLevel(Project.MSG_INFO);
                logger.setOutputPrintStream(out);
                logger.setErrorPrintStream(out);
                newProject.addBuildListener(logger);
            } catch (Exception ex) {
                log("Ant: Can't set output to " + output);
            }
        }
...    
}

//additional code
 protected String loggerName = null;
    public void setLogger(String logger) 
    {
        this.loggerName = logger;
    }

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message