krysalis-version/src/java/org/krysalis/version/util/logging/eclipse EclipseLogHandleFactory.java,NONE,1.1 EclipseLogHandle.java,NONE,1.1
[email protected] Thu, 27 Mar 2003 15:17:51 -0800
| Newsgroups | gmane.comp.krysalis.sandbox |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/util/logging/eclipse In directory sc8-pr-cvs1:/tmp/cvs-serv31680/src/java/org/krysalis/version/util/logging/eclipse Added Files: EclipseLogHandleFactory.java EclipseLogHandle.java Log Message: Tryign to log into the Eclipse plugin log -- when inside Eclipse... --- NEW FILE: EclipseLogHandleFactory.java --- /* 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 APACHE SOFTWARE FOUNDATION 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. ==================================================================== */ package org.krysalis.version.util.logging.eclipse; import org.eclipse.core.resources.ResourcesPlugin; import org.krysalis.version.exception.VersionException; import org.krysalis.version.util.logging.LogHandle; import org.krysalis.version.util.logging.LogHandleFactory; /** * @author ajack */ public class EclipseLogHandleFactory extends LogHandleFactory { public EclipseLogHandleFactory() throws VersionException { if (null == ResourcesPlugin.getPlugin()) throw new VersionException("Not in eclipse, me thinks..."); } public LogHandle getSpecializedLogHandle(String key, Object context) { //:TODO: Hack. if (null == context) context = ResourcesPlugin.getPlugin(); return new EclipseLogHandle(context); } } --- NEW FILE: EclipseLogHandle.java --- /* The Krysalis Patchy Software License, Version 1.1_01 Copyright (c) 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 APACHE SOFTWARE FOUNDATION 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. ==================================================================== */ package org.krysalis.version.util.logging.eclipse; 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; import org.krysalis.version.util.logging.LogHandle; /** * @author ajack */ public class EclipseLogHandle extends LogHandle { private Plugin m_plugin = null; private ILog m_log = null; private String m_pluginId = null; private boolean m_debug = false; EclipseLogHandle(Object context) { m_plugin = (Plugin) context; m_log = m_plugin.getLog(); m_pluginId = m_plugin.getDescriptor().getUniqueIdentifier(); m_debug = m_plugin.isDebugging(); } // // Debug // public boolean isDebugEnabled() { return m_debug; } public void debug(Object message) { if (m_debug) log(IStatus.OK, message.toString()); } public void debug(Object message, Throwable thrower) { if (m_debug) log(IStatus.OK, message.toString(), thrower); } public boolean isWarnEnabled() { return true; } public void warn(Object message) { log(IStatus.WARNING, message.toString()); } public void warn(Object message, Throwable thrower) { log(IStatus.WARNING, message.toString(), thrower); } public boolean isInfoEnabled() { return true; } public void info(Object message) { log(IStatus.INFO, message.toString()); } public void info(Object message, Throwable thrower) { log(IStatus.INFO, message.toString(), thrower); } public void error(Object message) { log(IStatus.ERROR, message.toString()); } public void error(Object message, Throwable thrower) { log(IStatus.ERROR, message.toString(), thrower); } /** * Logs an exception * * @param e The exception * @param msg The message to display */ public void log(int severity, String addOnMessage) { log(severity, addOnMessage, null); } public void log(int severity, String addOnMessage, Throwable t) { m_log.log(createStatus(severity, addOnMessage, t)); } private IStatus createStatus(int severity, String addOnMsg, Throwable t) { IStatus status = null; String msg = null; if (t != null) { if (t instanceof CoreException) { status = ((CoreException) t).getStatus(); } else msg = t.getMessage(); } if (null == status) { if (msg == null) msg = new String(""); //$NON-NLS-1$ status = new Status(severity, m_pluginId, IStatus.OK, addOnMsg + msg, t); } return status; } } ------------------------------------------------------- This SF.net email is sponsored by: The Definitive IT and Networking Event. Be There! NetWorld+Interop Las Vegas 2003 -- Register today! http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en