Browse Source

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)

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272478 13f79535-47bb-0310-9956-ffa450edef68
master
Erik Hatcher 23 years ago
parent
commit
244877e68b
1 changed files with 37 additions and 7 deletions
  1. +37
    -7
      src/main/org/apache/tools/ant/XmlLogger.java

+ 37
- 7
src/main/org/apache/tools/ant/XmlLogger.java View File

@@ -54,10 +54,7 @@


package org.apache.tools.ant; 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; import java.util.Hashtable;
@@ -84,7 +81,10 @@ import org.apache.tools.ant.util.StringUtils;
* *
* @see Project#addBuildListener(BuildListener) * @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. */ /** DocumentBuilder to use when creating the document to start with. */
private static final DocumentBuilder builder = getDocumentBuilder(); private static final DocumentBuilder builder = getDocumentBuilder();
@@ -206,8 +206,11 @@ public class XmlLogger implements BuildListener {
try { try {
// specify output in UTF8 otherwise accented characters will blow // specify output in UTF8 otherwise accented characters will blow
// up everything // 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"); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
if (xslUri.length() > 0) { if (xslUri.length() > 0) {
out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" out.write("<?xml-stylesheet type=\"text/xsl\" href=\""
@@ -362,6 +365,10 @@ public class XmlLogger implements BuildListener {
* Will not be <code>null</code>. * Will not be <code>null</code>.
*/ */
public void messageLogged(BuildEvent event) { public void messageLogged(BuildEvent event) {
int priority = event.getPriority();
if (priority > msgOutputLevel) {
return;
}
Element messageElement = doc.createElement(MESSAGE_TAG); Element messageElement = doc.createElement(MESSAGE_TAG);


String name = "debug"; String name = "debug";
@@ -403,4 +410,27 @@ public class XmlLogger implements BuildListener {
buildElement.element.appendChild(messageElement); 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) {}

} }

Loading…
Cancel
Save