krysalis-version/src/java/org/krysalis/version/eclipse/plugin/log Logger.java,NONE,1.1 PluginLogger.java,NONE,1.1

[email protected] Mon, 17 Mar 2003 08:07:05 -0800
Newsgroups gmane.comp.krysalis.sandbox
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/log
In directory sc8-pr-cvs1:/tmp/cvs-serv20662/src/java/org/krysalis/version/eclipse/plugin/log

Added Files:
	Logger.java PluginLogger.java 
Log Message:


--- NEW FILE: Logger.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/

package org.krysalis.version.eclipse.plugin.log;

/**
 * @author Anou Manavalan
 *
 */
public interface Logger
{
	public void info(String msg);
	public void debug(String msg);
	public void error(String msg);
	public void warn(String msg);
	
	public void info(Throwable exp);
	public void debug(Throwable exp);
	public void error(Throwable exp);
	public void warn(Throwable exp);

	public void log(Throwable exp);
	public void log(int severity, Throwable exp, String addOnMsg);
	public void log(Throwable exp, String addOnMsg);
	
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. 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.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 KRYSALIS PROJECT OR
ITS 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.
====================================================================*/
--- NEW FILE: PluginLogger.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/

package org.krysalis.version.eclipse.plugin.log;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;

/**
 * @author Anou Manavalan
 *
 */
public class PluginLogger implements Logger
{
	private Plugin m_plugin = null;
	private ILog m_log = null;
	private String m_pluginId = null;
	private boolean m_debug = false;
	
	
	/**
	 * Constructor for PluginLogger.
	 */
	public PluginLogger(Plugin plugin)
	{
		super();
		
		m_plugin = plugin;
		m_log = m_plugin.getLog();
		m_pluginId = m_plugin.getDescriptor().getUniqueIdentifier();
		m_debug = m_plugin.isDebugging();
	}

	public void info(String msg)
	{
		if( m_debug )
			log(IStatus.INFO, null, msg);
	}
	
	public void debug(String msg)
	{
		if( m_debug )
			log(IStatus.INFO, null, msg);
	}
	
	public void error(String msg)
	{
		log(IStatus.ERROR, null, msg);
	}
	
	public void warn(String msg)
	{
		log(IStatus.WARNING, null, msg);
	}
	
	
	public void info(Throwable exp)
	{
		if( m_debug )
			log(IStatus.INFO, exp);
	}
	
	public void debug(Throwable exp)
	{
		if( m_debug )
			log(IStatus.INFO, exp);
	}
	
	public void error(Throwable exp)
	{
		log(IStatus.ERROR, exp);
	}
	
	public void warn(Throwable exp)
	{
		log(IStatus.WARNING, exp);
	}
	
	/**
	 * Logs an exception
	 * 
	 * @param e The exception
	 * @param msg The message to display
	 */
	public void log(Throwable exp)
	{
		IStatus status = null;
		
		if (exp instanceof CoreException)
		{
			status = ((CoreException) exp).getStatus();
		}
		else
		{
			status = createStatus(IStatus.ERROR, exp);
		}
		m_log.log(status);
	}
	
	public void log(Throwable exp, String addOnMsg)
	{
		IStatus status = null;
		
		if (exp instanceof CoreException)
		{
			status = ((CoreException) exp).getStatus();
		}
		else
		{
			status = createStatus(IStatus.ERROR, exp, addOnMsg);
		}
		m_log.log(status);
	}
	
	public void log(int severity, Throwable exp)
	{
		IStatus status = createStatus(severity, exp);
		m_log.log(status);
	}
	
	public void log(int severity, Throwable exp, String addOnMsg)
	{
		IStatus status = createStatus(severity, exp, addOnMsg);
		m_log.log(status);
	}
	

	private IStatus createStatus(int severity, Throwable exp)
	{
		String msg = exp.getMessage();

		if (msg == null)
			msg = new String(""); //$NON-NLS-1$

		return new Status(severity, m_pluginId, IStatus.OK, msg, exp);
	}
		
	private IStatus createStatus(int severity, Throwable exp, String addOnMsg)
	{
		String msg = null;
		 
		if(exp != null)
		{
			msg = exp.getMessage();
		}

		if (msg == null)
			msg = new String(""); //$NON-NLS-1$

		return new Status(severity, m_pluginId, IStatus.OK, msg+addOnMsg, exp);
	}
		
	public static void main(String[] args)
	{
		
	}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. 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.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 KRYSALIS PROJECT OR
ITS 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.
====================================================================*/



-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en