ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant XmlLogger.java
Date Wed, 17 Apr 2002 01:25:46 GMT
ehatcher    02/04/16 18:25:46

  Modified:    src/main/org/apache/tools/ant XmlLogger.java
  Log:
  Make XmlLogger finally a real BuildLogger. When used as a logger it will utilize Ant's logging
level (-verbose, -quiet, etc), but remember to use -logfile, otherwise the output will be
written to the console. Its previous BuildListener functionality, of course, still works as
it did, writing to log.xml (or the XmlLogger.file property value)
  
  Revision  Changes    Path
  1.28      +37 -7     jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java
  
  Index: XmlLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/XmlLogger.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- XmlLogger.java	9 Apr 2002 15:27:08 -0000	1.27
  +++ XmlLogger.java	17 Apr 2002 01:25:46 -0000	1.28
  @@ -54,10 +54,7 @@
   
   package org.apache.tools.ant;
   
  -import java.io.Writer;
  -import java.io.OutputStreamWriter;
  -import java.io.FileOutputStream;
  -import java.io.IOException;
  +import java.io.*;
   
   
   import java.util.Hashtable;
  @@ -84,7 +81,10 @@
    *
    * @see Project#addBuildListener(BuildListener)
    */
  -public class XmlLogger implements BuildListener {
  +public class XmlLogger implements BuildLogger {
  +
  +    private int msgOutputLevel = Project.MSG_DEBUG;
  +    private PrintStream outStream;
   
       /** DocumentBuilder to use when creating the document to start with. */
       private static final DocumentBuilder builder = getDocumentBuilder();
  @@ -206,8 +206,11 @@
           try {
               // specify output in UTF8 otherwise accented characters will blow
               // up everything
  -            FileOutputStream fos = new FileOutputStream(outFilename);
  -            out = new OutputStreamWriter(fos, "UTF8");
  +            OutputStream stream = outStream;
  +            if (stream == null) {
  +                stream = new FileOutputStream(outFilename);
  +            }
  +            out = new OutputStreamWriter(stream, "UTF8");
               out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
               if (xslUri.length() > 0) {
                   out.write("<?xml-stylesheet type=\"text/xsl\" href=\""
  @@ -362,6 +365,10 @@
        *              Will not be <code>null</code>.
        */
       public void messageLogged(BuildEvent event) {
  +        int priority = event.getPriority();
  +        if (priority > msgOutputLevel) {
  +            return;
  +        }
           Element messageElement = doc.createElement(MESSAGE_TAG);
   
           String name = "debug";
  @@ -403,4 +410,27 @@
               buildElement.element.appendChild(messageElement);
           }
       }
  +
  +    // -------------------------------------------------- BuildLogger interface
  +
  +    public void setMessageOutputLevel(int level) {
  +        msgOutputLevel = level;
  +    }
  +    
  +    public void setOutputPrintStream(PrintStream output) {
  +        this.outStream = new PrintStream(output, true);
  +    }
  +
  +    /**
  +     * Ignore emacs mode, as it has no meaning in XML format
  +     */
  +    public void setEmacsMode(boolean emacsMode) {}
  +
  +    /**
  +     * Ignore error print stream. All output will be written to
  +     * either the XML log file or the PrintStream provided to
  +     * setOutputPrintStream
  +     */
  +    public void setErrorPrintStream(PrintStream err) {}
  +
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message