Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 69867 invoked from network); 30 Jan 2002 19:39:16 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 30 Jan 2002 19:39:16 -0000 Received: (qmail 12817 invoked by uid 97); 30 Jan 2002 19:39:13 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 12800 invoked by uid 97); 30 Jan 2002 19:39:12 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 12779 invoked from network); 30 Jan 2002 19:39:11 -0000 Message-ID: <014201c1a9c5$c97d5450$270610ac@manu.com> From: "Magesh Umasankar" To: "Ant Developers List" Subject: [SUBMIT] AnsiColorLogger Date: Wed, 30 Jan 2002 14:39:05 -0500 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_013F_01C1A99B.DE37D2F0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: localhost.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_013F_01C1A99B.DE37D2F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, AnsiColorLogger uses ANSI color code sequences to display output to the console in color. Different colors are used to classify messages based on message level. This submission is to provide you an opportunity to take a look at the implementation before I commit it (planning to do it same time tomorrow). Please send your comments, if any, my way. NOTE: The defaults.properties file must go into the org/apache/tools/ant/listener directory. Cheers, Magesh ************************************************* * Politician: One who shakes your hand before * * elections and your confidence after. * ************************************************* ------=_NextPart_000_013F_01C1A99B.DE37D2F0 Content-Type: application/octet-stream; name="defaults.properties" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="defaults.properties" ####################################################=0A= #=0A= # ANSI COLOR LOGGER CONFIGURATION=0A= #=0A= # Format for AnsiColorLogger.*=3D=0A= # Attribute;Foreground;Background=0A= #=0A= # Attribute is one of the following:=0A= # 0 -> Reset All Attributes (return to normal mode)=0A= # 1 -> Bright (Usually turns on BOLD)=0A= # 2 -> Dim=0A= # 3 -> Underline=0A= # 5 -> link=0A= # 7 -> Reverse=0A= # 8 -> Hidden=0A= # =0A= # Foreground is one of the following:=0A= # 30 -> Black=0A= # 31 -> Red=0A= # 32 -> Green=0A= # 33 -> Yellow=0A= # 34 -> Blue=0A= # 35 -> Magenta=0A= # 36 -> Cyan=0A= # 37 -> White=0A= #=0A= # Background is one of the following:=0A= # 40 -> Black=0A= # 41 -> Red=0A= # 42 -> Green=0A= # 43 -> Yellow=0A= # 44 -> Blue=0A= # 45 -> Magenta=0A= # 46 -> Cyan=0A= # 47 -> White=0A= #=0A= ####################################################=0A= =0A= AnsiColorLogger.ERROR_COLOR=3D2;31=0A= AnsiColorLogger.WARNING_COLOR=3D2;35=0A= AnsiColorLogger.INFO_COLOR=3D2;36=0A= AnsiColorLogger.VERBOSE_COLOR=3D2;32=0A= AnsiColorLogger.DEBUG_COLOR=3D2;34=0A= ------=_NextPart_000_013F_01C1A99B.DE37D2F0 Content-Type: application/octet-stream; name="AnsiColorLogger.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="AnsiColorLogger.java" /*=0A= * The Apache Software License, Version 1.1=0A= *=0A= * Copyright (c) 2002 The Apache Software Foundation. All rights=0A= * reserved.=0A= *=0A= * Redistribution and use in source and binary forms, with or without=0A= * modification, are permitted provided that the following conditions=0A= * are met:=0A= *=0A= * 1. Redistributions of source code must retain the above copyright=0A= * notice, this list of conditions and the following disclaimer.=0A= *=0A= * 2. Redistributions in binary form must reproduce the above copyright=0A= * notice, this list of conditions and the following disclaimer in=0A= * the documentation and/or other materials provided with the=0A= * distribution.=0A= *=0A= * 3. The end-user documentation included with the redistribution, if=0A= * any, must include the following acknowlegement:=0A= * "This product includes software developed by the=0A= * Apache Software Foundation (http://www.apache.org/)."=0A= * Alternately, this acknowlegement may appear in the software itself,=0A= * if and wherever such third-party acknowlegements normally appear.=0A= *=0A= * 4. The names "The Jakarta Project", "Ant", and "Apache Software=0A= * Foundation" must not be used to endorse or promote products derived=0A= * from this software without prior written permission. For written=0A= * permission, please contact apache@apache.org.=0A= *=0A= * 5. Products derived from this software may not be called "Apache"=0A= * nor may "Apache" appear in their names without prior written=0A= * permission of the Apache Group.=0A= *=0A= * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED=0A= * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES=0A= * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE=0A= * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR=0A= * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,=0A= * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT=0A= * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF=0A= * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND=0A= * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,=0A= * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT=0A= * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF=0A= * SUCH DAMAGE.=0A= * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= *=0A= * This software consists of voluntary contributions made by many=0A= * individuals on behalf of the Apache Software Foundation. For more=0A= * information on the Apache Software Foundation, please see=0A= * .=0A= */=0A= package org.apache.tools.ant.listener;=0A= =0A= import java.io.InputStream;=0A= import java.io.IOException;=0A= import java.io.PrintStream;=0A= import java.util.Properties;=0A= =0A= import org.apache.tools.ant.DefaultLogger;=0A= import org.apache.tools.ant.Project;=0A= =0A= /**=0A= * Uses ANSI Color Code Sequences to colorize messages=0A= * sent to the console.=0A= *=0A= * If used with the -logfile option, the output file=0A= * will contain all the necessary escape codes to=0A= * display the text in colorized mode when displayed=0A= * in the console using applications like cat, more,=0A= * etc.=0A= *=0A= * This is designed to work on terminals that support ANSI=0A= * color codes. It works on XTerm, ETerm, Mindterm, etc.=0A= * It also works on Win9x (with ANSI.SYS loaded.)=0A= *=0A= * NOTE:=0A= * It doesn't work on WinNT's COMMAND.COM even with=0A= * ANSI.SYS loaded.=0A= *=0A= * The default colors used for differentiating=0A= * the message levels can be changed by editing the=0A= * /org/apache/tools/ant/listener/defaults.properties=0A= * file.=0A= * This file contains 5 key/value pairs:=0A= * AnsiColorLogger.ERROR_COLOR=3D2;31=0A= * AnsiColorLogger.WARNING_COLOR=3D2;35=0A= * AnsiColorLogger.INFO_COLOR=3D2;36=0A= * AnsiColorLogger.VERBOSE_COLOR=3D2;32=0A= * AnsiColorLogger.DEBUG_COLOR=3D2;34=0A= *=0A= * To change these colors use the following chart:=0A= *=0A= * ANSI COLOR LOGGER CONFIGURATION=0A= *=0A= * Format for AnsiColorLogger.*=3D=0A= * Attribute;Foreground;Background=0A= *=0A= * Attribute is one of the following:=0A= * 0 -> Reset All Attributes (return to normal mode)=0A= * 1 -> Bright (Usually turns on BOLD)=0A= * 2 -> Dim=0A= * 3 -> Underline=0A= * 5 -> link=0A= * 7 -> Reverse=0A= * 8 -> Hidden=0A= *=0A= * Foreground is one of the following:=0A= * 30 -> Black=0A= * 31 -> Red=0A= * 32 -> Green=0A= * 33 -> Yellow=0A= * 34 -> Blue=0A= * 35 -> Magenta=0A= * 36 -> Cyan=0A= * 37 -> White=0A= *=0A= * Background is one of the following:=0A= * 40 -> Black=0A= * 41 -> Red=0A= * 42 -> Green=0A= * 43 -> Yellow=0A= * 44 -> Blue=0A= * 45 -> Magenta=0A= * 46 -> Cyan=0A= * 47 -> White=0A= *=0A= * @author Magesh Umasankar=0A= */=0A= public final class AnsiColorLogger extends DefaultLogger {=0A= =0A= private static final int ATTR_NORMAL =3D 0;=0A= private static final int ATTR_BRIGHT =3D 1;=0A= private static final int ATTR_DIM =3D 2;=0A= private static final int ATTR_UNDERLINE =3D 3;=0A= private static final int ATTR_BLINK =3D 5;=0A= private static final int ATTR_REVERSE =3D 7;=0A= private static final int ATTR_HIDDEN =3D 8;=0A= =0A= private static final int FG_BLACK =3D 30;=0A= private static final int FG_RED =3D 31;=0A= private static final int FG_GREEN =3D 32;=0A= private static final int FG_YELLOW =3D 33;=0A= private static final int FG_BLUE =3D 34;=0A= private static final int FG_MAGENTA =3D 35;=0A= private static final int FG_CYAN =3D 36;=0A= private static final int FG_WHITE =3D 37;=0A= =0A= private static final int BG_BLACK =3D 40;=0A= private static final int BG_RED =3D 41;=0A= private static final int BG_GREEN =3D 42;=0A= private static final int BG_YELLOW =3D 44;=0A= private static final int BG_BLUE =3D 44;=0A= private static final int BG_MAGENTA =3D 45;=0A= private static final int BG_CYAN =3D 46;=0A= private static final int BG_WHITE =3D 47;=0A= =0A= private static final String PREFIX =3D "\u001b[";=0A= private static final String SUFFIX =3D "m";=0A= private static final char SEPARATOR =3D ';';=0A= private static final String END_COLOR =3D PREFIX + SUFFIX;=0A= =0A= private String errColor =3D PREFIX + ATTR_DIM + SEPARATOR + FG_RED + = SUFFIX;=0A= private String warnColor =3D PREFIX + ATTR_DIM + SEPARATOR + = FG_MAGENTA + SUFFIX;=0A= private String infoColor =3D PREFIX + ATTR_DIM + SEPARATOR + FG_CYAN = + SUFFIX;=0A= private String verboseColor =3D PREFIX + ATTR_DIM + SEPARATOR + = FG_GREEN + SUFFIX;=0A= private String debugColor =3D PREFIX + ATTR_DIM + SEPARATOR + = FG_BLUE + SUFFIX;=0A= =0A= private boolean colorsSet =3D false;=0A= =0A= private final void setColors() {=0A= String colorFile =3D = "/org/apache/tools/ant/listener/defaults.properties";=0A= InputStream in =3D null;=0A= =0A= try {=0A= Properties prop =3D new Properties();=0A= in =3D this.getClass().getResourceAsStream(colorFile);=0A= if (in !=3D null) {=0A= prop.load(in);=0A= }=0A= =0A= String err =3D = prop.getProperty("AnsiColorLogger.ERROR_COLOR");=0A= String warn =3D = prop.getProperty("AnsiColorLogger.WARNING_COLOR");=0A= String info =3D = prop.getProperty("AnsiColorLogger.INFO_COLOR");=0A= String verbose =3D = prop.getProperty("AnsiColorLogger.VERBOSE_COLOR");=0A= String debug =3D = prop.getProperty("AnsiColorLogger.DEBUG_COLOR");=0A= if (err !=3D null) {=0A= errColor =3D PREFIX + err + SUFFIX;=0A= }=0A= if (warn !=3D null) {=0A= warnColor =3D PREFIX + warn + SUFFIX;=0A= }=0A= if (info !=3D null) {=0A= infoColor =3D PREFIX + info + SUFFIX;=0A= }=0A= if (verbose !=3D null) {=0A= verboseColor =3D PREFIX + verbose + SUFFIX;=0A= }=0A= if (debug !=3D null) {=0A= debugColor =3D PREFIX + debug + SUFFIX;=0A= }=0A= } catch (IOException ioe) {=0A= //Ignore=0A= } finally {=0A= if (in !=3D null) {=0A= try {=0A= in.close();=0A= } catch (IOException e) {=0A= //ignore=0A= }=0A= }=0A= }=0A= }=0A= =0A= protected final void printMessage(final String message,=0A= final PrintStream stream,=0A= final int priority) {=0A= if (!colorsSet) {=0A= setColors();=0A= colorsSet =3D true;=0A= }=0A= =0A= final StringBuffer msg =3D new StringBuffer(message);=0A= switch (priority) {=0A= case Project.MSG_ERR:=0A= msg.insert(0, errColor);=0A= msg.append(END_COLOR);=0A= break;=0A= case Project.MSG_WARN:=0A= msg.insert(0, warnColor);=0A= msg.append(END_COLOR);=0A= break;=0A= case Project.MSG_INFO:=0A= msg.insert(0, infoColor);=0A= msg.append(END_COLOR);=0A= break;=0A= case Project.MSG_VERBOSE:=0A= msg.insert(0, verboseColor);=0A= msg.append(END_COLOR);=0A= break;=0A= case Project.MSG_DEBUG:=0A= msg.insert(0, debugColor);=0A= msg.append(END_COLOR);=0A= break;=0A= }=0A= final String strmessage =3D msg.toString();=0A= stream.println(strmessage);=0A= }=0A= }=0A= ------=_NextPart_000_013F_01C1A99B.DE37D2F0 Content-Type: application/octet-stream; name="defaultlogger.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="defaultlogger.patch" Index: DefaultLogger.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/DefaultLogger.java,v retrieving revision 1.26 diff -u -r1.26 DefaultLogger.java --- DefaultLogger.java 20 Jan 2002 20:45:56 -0000 1.26 +++ DefaultLogger.java 30 Jan 2002 19:35:35 -0000 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -164,9 +164,9 @@ =20 String msg =3D message.toString(); if (error =3D=3D null) { - out.println(msg); + printMessage(msg, out, Project.MSG_VERBOSE); } else { - err.println(msg); + printMessage(msg, err, Project.MSG_ERR); } log(msg); } @@ -174,7 +174,7 @@ public void targetStarted(BuildEvent event) { if (Project.MSG_INFO <=3D msgOutputLevel) { String msg =3D StringUtils.LINE_SEP + = event.getTarget().getName() + ":"; - out.println(msg); + printMessage(msg, out, event.getPriority()); log(msg); } } @@ -186,8 +186,9 @@ public void taskFinished(BuildEvent event) {} =20 public void messageLogged(BuildEvent event) { + int priority =3D event.getPriority(); // Filter out messages based on priority - if (event.getPriority() <=3D msgOutputLevel) { + if (priority <=3D msgOutputLevel) { =20 StringBuffer message =3D new StringBuffer(); // Print out the name of the task if we're in one @@ -205,10 +206,10 @@ =20 message.append(event.getMessage()); String msg =3D message.toString(); - if (event.getPriority() !=3D Project.MSG_ERR) { - out.println(msg); + if (priority !=3D Project.MSG_ERR) { + printMessage(msg, out, priority); } else { - err.println(msg); + printMessage(msg, err, priority); } log(msg); } @@ -232,10 +233,15 @@ =20 } =20 + protected void printMessage(final String message, + final PrintStream stream, + final int priority) { + stream.println(message); + } + /** * Empty implementation which allows subclasses to receive the * same output that is generated here. */ protected void log(String message) {} - } ------=_NextPart_000_013F_01C1A99B.DE37D2F0 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------=_NextPart_000_013F_01C1A99B.DE37D2F0--