krysalis-update/src/java/org/krysalis/depot/common/ant/util AntLogListener.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:24 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/common/ant/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/common/ant/util

Added Files:
	AntLogListener.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: AntLogListener.java ---
/*
 * 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.krysalis.depot.common.ant.util;

import org.krysalis.depot.common.log.ILogger;
import org.krysalis.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);
		}
	}
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/