incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 20447 - in incubator/depot/trunk/common/src/java/org/apache/depot/common/util/ant: . util
Date Tue, 25 May 2004 22:18:40 GMT
Author: ajack
Date: Tue May 25 15:18:39 2004
New Revision: 20447

Added:
   incubator/depot/trunk/common/src/java/org/apache/depot/common/util/ant/
   incubator/depot/trunk/common/src/java/org/apache/depot/common/util/ant/util/
   incubator/depot/trunk/common/src/java/org/apache/depot/common/util/ant/util/AntLogListener.java
Log:
Then add.


Added: incubator/depot/trunk/common/src/java/org/apache/depot/common/util/ant/util/AntLogListener.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/common/src/java/org/apache/depot/common/util/ant/util/AntLogListener.java
Tue May 25 15:18:39 2004
@@ -0,0 +1,108 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.depot.common.ant.util;
+
+import org.apache.depot.common.log.ILogger;
+import org.apache.depot.common.log.LogConstants;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.ProjectComponent;
+
+/**
+ * @author arb_jack
+ */
+public class AntLogListener implements ILogger {
+
+	private ProjectComponent m_component = null;
+
+	public AntLogListener(ProjectComponent component) {
+		m_component = component;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.version.log.LogListener#log(int, java.lang.Object,
+	 *      java.lang.Throwable)
+	 */
+	public void log(int severity, Object message, Throwable thrower) {
+		int antSeverity = Project.MSG_ERR;
+
+		try {
+
+			switch (severity) {
+				case LogConstants.DEBUG :
+					{
+						antSeverity = Project.MSG_DEBUG;
+						break;
+					}
+				case LogConstants.INFO :
+					{
+						antSeverity = Project.MSG_INFO;
+						break;
+					}
+				case LogConstants.VERBOSE :
+					{
+						antSeverity = Project.MSG_VERBOSE;
+						break;
+					}
+				case LogConstants.WARN :
+					{
+						antSeverity = Project.MSG_WARN;
+						break;
+					}
+				default :
+				case LogConstants.ERROR :
+					{
+						antSeverity = Project.MSG_ERR;
+						break;
+					}
+			}
+
+			StringBuffer messageStr = new StringBuffer(message.toString());
+
+			if (null != thrower) {
+				appendThrower(messageStr, thrower);
+			}
+
+			m_component.log(messageStr.toString(), antSeverity);
+
+		} catch (Throwable t) {
+			m_component.log("Failed to log message : " + t.toString());
+			t.printStackTrace(System.err);
+		}
+	}
+
+	private void appendThrower(StringBuffer messageStr, Throwable thrower) {
+
+		messageStr.append(thrower.getLocalizedMessage());
+
+		StackTraceElement stacks[] = thrower.getStackTrace();
+
+		if (null != stacks)
+			for (int i = 0; i < stacks.length; ++i) {
+				messageStr.append("\n");
+				messageStr.append(stacks[i].toString());
+			}
+
+		// Note: not JDK 1.3, but I don't think we care
+		Throwable cause = thrower.getCause();
+		if (null != cause) {
+			messageStr.append("Cause: \n");
+			appendThrower(messageStr, cause);
+		}
+	}
+}

Mime
View raw message