/******************************************************************************** * CruiseControl, a Continuous Integration Toolkit * Copyright (c) 2003, ThoughtWorks, Inc. * 200 E. Randolph, 25th Floor * Chicago, IL 60601 USA * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * + Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * + Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the * names of its contributors may be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ package net.sourceforge.cruisecontrol.builders; import java.io.File; import java.io.PrintStream; import java.io.FileOutputStream; import java.io.FileNotFoundException; import org.apache.tools.ant.DefaultLogger; import org.apache.tools.ant.Project; /** * Understands writing all messages to a file. * * Date: Aug 22, 2007 * Time: 5:44:00 PM */ public class AntOutputLogger extends DefaultLogger { public static final String DEFAULT_OUTFILE_NAME = "antBuilderOutput.log"; private final File outfile = new File(DEFAULT_OUTFILE_NAME); public AntOutputLogger() { outfile.delete(); setMessageOutputLevel(Project.MSG_INFO); } protected void printMessage(final String message, final PrintStream stream, final int priority) { PrintStream mystream = null; try { mystream = new PrintStream(new FileOutputStream(outfile, true)); super.printMessage(message, mystream, priority); } catch (FileNotFoundException e) { if (stream != null) { super.printMessage("Error (" + e.getMessage() + "): " + message, stream, priority); } } finally { if (mystream != null) { mystream.close(); } } } }