diff options
Diffstat (limited to 'plugins/org.eclipse.jem.util/jemutil-nonworkbnech')
5 files changed, 0 insertions, 1642 deletions
diff --git a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/LogEntry.java b/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/LogEntry.java deleted file mode 100644 index f50bae711..000000000 --- a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/LogEntry.java +++ /dev/null @@ -1,329 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.util.logger; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; - -/** - * This class should be used when logging information which should be grouped together. Instead of creating a new instance of this class every time it - * is needed, for performance reasons, create an instance and reuse it. - * <p> - * Currently the only fields that are logged are the {@link #getText()} and {@link #getTargetException()}. - * - * @since 1.0.0 - */ -public class LogEntry { - - private int _executionMap = 0; - - private Throwable _caughtException = null; - - private String _propertiesFileName = null; - - private String localeOfOrigin = null; - - private String sourceIdentifier; - - private String elapsedTime; - - private String text; - - private String messageTypeIdentifier; - - /** - * The file name parameter must be a name which can be used by ResourceBundle to load the string from the .properties file. The parameter must not - * be null or the empty string. - * - * @param propertiesFileName - * - * @since 1.0.0 - */ - public LogEntry(String propertiesFileName) { - setPropertiesFileName(propertiesFileName); - } - - /** - * Default Constructor - */ - public LogEntry() { - } - - /** - * Get execution map - * - * @return execution map - * - * @since 1.0.0 - */ - public int getExecutionMap() { - return _executionMap; - } - - /** - * Get the properties file name - * - * @return properties file name or <code>null</code> if not set. - * - * @since 1.0.0 - */ - public String getPropertiesFileName() { - return _propertiesFileName; - } - - /** - * Get target exception - * - * @return target exception or <code>null</code> if not set. - * - * @since 1.0.0 - */ - public Throwable getTargetException() { - return _caughtException; - } - - /** - * Get locale of origin - * - * @return locale of origin or <code>null</code> if not set. - * - * @since 1.0.0 - */ - public String getLocaleOfOrigin() { - return localeOfOrigin; - } - - /** - * Get source identifier. - * - * @return source identifier or <code>null</code> if not set. - * - * @since 1.0.0 - */ - public String getSourceidentifier() { - return sourceIdentifier; - } - - /** - * Get elapsed time - * - * @return elapsed time - * - * @since 1.0.0 - */ - public String getElapsedTime() { - return elapsedTime; - } - - /** - * Get the message type identifier - * - * @return message type identifier or <code>null</code> if not set. - * - * @since 1.0.0 - */ - public String getMessageTypeIdentifier() { - return messageTypeIdentifier; - } - - /** - * Set execution map - * - * @param map - * - * @since 1.0.0 - */ - public void setExecutionMap(int map) { - _executionMap = map; - } - - /** - * Set properties file name - * - * @param fName - * - * @since 1.0.0 - */ - public void setPropertiesFileName(String fName) { - _propertiesFileName = fName; - } - - /** - * Set target exception - * - * @param exc - * - * @since 1.0.0 - */ - public void setTargetException(Throwable exc) { - _caughtException = exc; - } - - /** - * Append stacktrace of current stack (at the time of call to this method) to the text buffer. - * - * - * @since 1.0.0 - */ - public void appendStackTrace() { - // Grab the stack trace from the Thread ... - ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); - PrintWriter printWriter = new PrintWriter(byteOutput); - // Can't call Thread.dumpStack() because it doesn't take a writer as input. - // Copy its mechanism instead. - new Exception("Stack trace").printStackTrace(printWriter); //$NON-NLS-1$ - printWriter.flush(); - - // and update the text to the LogEntry's text. - StringBuffer buffer = new StringBuffer(); - buffer.append(getText()); - buffer.append("\n"); //$NON-NLS-1$ - buffer.append(byteOutput.toString()); - setText(buffer.toString()); - } - - /** - * Get the text. - * - * @return text or or <code>null</code> if not set. - * - * @since 1.0.0 - */ - public String getText() { - return text; - } - - /** - * Set the text - * - * @param string - * - * @since 1.0.0 - */ - public void setText(String string) { - text = string; - } - - /** - * Set every entry to the default value except the properties file name. - * - * - * @since 1.0.0 - */ - public void reset() { - setExecutionMap(0); - setTargetException(null); - localeOfOrigin = null; - sourceIdentifier = null; - elapsedTime = null; - setText(null); - } - - /** - * Set locale of origin. - * - * @param origin - * - * @since 1.0.0 - */ - public void setLocaleOfOrigin(String origin) { - localeOfOrigin = origin; - } - - /** - * Set source id. - * - * @param id - * - * @since 1.0.0 - */ - public void setSourceID(String id) { - sourceIdentifier = id; - } - - /** - * Set elapsed time. - * - * @param time - * - * @since 1.0.0 - */ - public void setElapsedTime(long time) { - elapsedTime = String.valueOf(time); - } - - /** - * Set source identifier. - * - * @param string - * - * @since 1.0.0 - */ - public void setSourceIdentifier(String string) { - setSourceID(string); - } - - /** - * Set message type identifier. - * - * @param string - * - * @since 1.0.0 - * @deprecated Use {@link #setText(String)} instead and calling it with the result of {@link java.text.MessageFormat#format(java.lang.String, java.lang.Object[])} - */ - public void setMessageTypeIdentifier(String string) { - messageTypeIdentifier = string; - } - - /** - * Set message type id. Same as <code>setMessageTypeIdentifier.</code> - * @param string - * - * @since 1.0.0 - * @deprecated Use {@link #setText(String)} instead and calling it with the result of {@link java.text.MessageFormat#format(java.lang.String, java.lang.Object[])} - */ - public void setMessageTypeID(String string) { - setMessageTypeIdentifier(string); - } - - /** - * Set tokens. (Currently this is ignored). - * - * @param strings - * - * @since 1.0.0 - * @deprecated Use {@link #setText(String)} instead and calling it with the result of {@link java.text.MessageFormat#format(java.lang.String, java.lang.Object[])} - */ - public void setTokens(String[] strings) { - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - public String toString() { - ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); - PrintWriter printWriter = new PrintWriter(byteOutput); - if (text != null) - printWriter.println(text); - if (_caughtException != null) { - _caughtException.printStackTrace(printWriter); - } - printWriter.flush(); - return byteOutput.toString(); - } - -} diff --git a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/ILogRenderer.java b/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/ILogRenderer.java deleted file mode 100644 index 5d1e951f0..000000000 --- a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/ILogRenderer.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.util.logger.proxy; - -/** - * Basic log renderer interface. It is replaced by the extension <code>ILogRenderer2.</code> - * - * @since 1.0.0 - */ -public interface ILogRenderer { - - /** - * Logged to console. - */ - final public static String CONSOLE_DESCRIPTION = "console"; //$NON-NLS-1$ - - /** - * Logged to workbench. - */ - final public static String WORKBENCH_DESCRIPTION = "workbench log"; //$NON-NLS-1$ - - /** - * Not logged. - */ - final public static String NOLOG_DESCRIPTION = ""; //$NON-NLS-1$ - - /** - * Log levels. These are deprecated, use <code>java.util.logging.Level</code> codes instead. - */ - final public static int LOG_ERROR = 0; - - final public static int LOG_TRACE = 1; - - final public static int LOG_WARNING = 2; - - final public static int LOG_INFO = 3; - - final public static String DefaultPluginID = "org.eclipse.jem.util"; //$NON-NLS-1$ - - /** - * Log the string at the specified type. - * - * @param msg - * @param type - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(String msg, int type); - - /** - * Start or stop the tracing. - * - * @param Flag - * <code>true</code> to start the tracing. - * - * @since 1.0.0 - */ - public void setTraceMode(boolean Flag); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/ILogRenderer2.java b/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/ILogRenderer2.java deleted file mode 100644 index f5a670fb5..000000000 --- a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/ILogRenderer2.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.util.logger.proxy; - -import java.util.logging.Level; - -/** - * Log renderer that provides more function. Basically it can handle - * the logging of specific types in a different manner than the default - * conversion to string supplied by Logger. - * - * It also uses the Level classes from java.util.logging as the logging levels. - * - * @since 1.0.0 - */ -public interface ILogRenderer2 extends ILogRenderer { - - /** - * When Logger.setLevel(DEFAULT): restore to what the default level was. - * When log(...,DEFAULT): Log at the default level for the type of object. - */ - static final Level DEFAULT = new Logger.LocalLevel("DEFAULT", Integer.MAX_VALUE-1); //$NON-NLS-1$ - - /** - * When log(...,TRACE) : Log only when in trace mode. - * Don't use in Logger.setLevel(). Has no meaning in that case. - */ - static final Level TRACE = new Logger.LocalLevel("TRACE", Integer.MAX_VALUE-2); //$NON-NLS-1$ - - /** - * Log the throwable at the given level (if DEFAULT, use default level for a throwable). - * - * @param t - * @param level - * @return - * - * @since 1.0.0 - */ - String log(Throwable t, Level level); - - /** - * Log the object at the given level (if DEFAULT, use default level for an object). - * - * @param o - * @param level - * @return - * - * @since 1.0.0 - */ - String log(Object o, Level level); - - /** - * Log the boolean at the given level (if DEFAULT, use default level for a boolean). - * - * @param b - * @param level - * @return - * - * @since 1.0.0 - */ - String log(boolean b, Level level); - - /** - * Log the char at the given level (if DEFAULT, use default level for a char). - * - * @param c - * @param level - * @return - * - * @since 1.0.0 - */ - String log(char c, Level level); - - /** - * Log the byte at the given level (if DEFAULT, use default level for a byte). - * - * @param b - * @param level - * @return - * - * @since 1.0.0 - */ - String log(byte b, Level level); - - /** - * Log the short at the given level (if DEFAULT, use default level for a short). - * - * @param s - * @param level - * @return - * - * @since 1.0.0 - */ - String log(short s, Level level); - - /** - * Log the int at the given level (if DEFAULT, use default level for an int). - * - * @param i - * @param level - * @return - * - * @since 1.0.0 - */ - String log(int i, Level level); - - /** - * Log the long at the given level (if DEFAULT, use default level for a long). - * - * @param l - * @param level - * @return - * - * @since 1.0.0 - */ - String log(long l, Level level); - - /** - * Log the float at the given level (if DEFAULT, use default level for a float). - * - * @param f - * @param level - * @return - * - * @since 1.0.0 - */ - String log(float f, Level level); - - /** - * Log the double at the given level (if DEFAULT, use default level for a double). - * - * @param d - * @param level - * @return - * - * @since 1.0.0 - */ - String log(double d, Level level); -} diff --git a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/JDKConsoleRenderer.java b/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/JDKConsoleRenderer.java deleted file mode 100644 index c7c9d75d3..000000000 --- a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/JDKConsoleRenderer.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.util.logger.proxy; - -import java.util.logging.Level; - -/** - * Default log renderer to use when not running under Eclipse. It logs to sysout and syserr. - * - * @since 1.1.0 - */ - -public class JDKConsoleRenderer implements ILogRenderer2 { - - private boolean fTraceMode = false; // will we actually punch trace messaged or not - - private boolean fSettingTrace = false; - - private Logger fMyLogger = null; - - /** - * Constructer taking a logger. - * - * @param logger - * - * @since 1.1.0 - */ - public JDKConsoleRenderer(Logger logger) { - super(); - fMyLogger = logger; - fTraceMode = fMyLogger.getTraceMode(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer#log(java.lang.String, int) - */ - public String log(String msg, int type) { - - if (type == ILogRenderer.LOG_TRACE && !fTraceMode) - return null; - - if (type == ILogRenderer.LOG_ERROR) - System.err.println(msg); - else - System.out.println(msg); - return ILogRenderer.CONSOLE_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer#setTraceMode(boolean) - */ - public void setTraceMode(boolean flag) { - - if (fSettingTrace) - return; - fSettingTrace = true; - fTraceMode = flag; - fMyLogger.setTraceMode(flag); - fSettingTrace = false; - } - - /** - * Log the string at the given level. - * - * @param msg - * @param level - * @return <code>CONSOLE_DESCRIPTION</code> - * - * @since 1.1.0 - */ - protected String log(String msg, Level level) { - if (level == Level.SEVERE) - System.err.println(msg); - else - System.out.println(msg); - return ILogRenderer.CONSOLE_DESCRIPTION; - } - - /** - * Answer if logging at the given level - * - * @param logLevel - * @return <code>true</code> if logging at the given level. - * - * @since 1.1.0 - */ - protected boolean isLogging(Level logLevel) { - return fTraceMode || fMyLogger.isLoggingLevel(logLevel); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(boolean, java.util.logging.Level) - */ - public String log(boolean b, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(b), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(byte, java.util.logging.Level) - */ - public String log(byte b, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(b), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(char, java.util.logging.Level) - */ - public String log(char c, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(c), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(double, java.util.logging.Level) - */ - public String log(double d, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(d), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(float, java.util.logging.Level) - */ - public String log(float f, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(f), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(int, java.util.logging.Level) - */ - public String log(int i, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(i), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(long, java.util.logging.Level) - */ - public String log(long l, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(l), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(java.lang.Object, java.util.logging.Level) - */ - public String log(Object o, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(o), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(short, java.util.logging.Level) - */ - public String log(short s, Level level) { - if (level == DEFAULT) - level = Level.FINEST; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(String.valueOf(s), level), level); - else - return NOLOG_DESCRIPTION; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.util.logger.proxy.ILogRenderer2#log(java.lang.Throwable, java.util.logging.Level) - */ - public String log(Throwable t, Level level) { - if (level == DEFAULT) - level = Level.SEVERE; - if (isLogging(level)) - return log(fMyLogger.getGenericMsg(fMyLogger.exceptionToString(t), level), level); - else - return NOLOG_DESCRIPTION; - } - -} diff --git a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/Logger.java b/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/Logger.java deleted file mode 100644 index b86ad055a..000000000 --- a/plugins/org.eclipse.jem.util/jemutil-nonworkbnech/org/eclipse/jem/util/logger/proxy/Logger.java +++ /dev/null @@ -1,843 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - - - */ -package org.eclipse.jem.util.logger.proxy; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.*; -import java.util.logging.Level; - -/** - * This is a base, UI independent logger. It will - * construct a consistent msg. body, and call an enfironment specific ILogRenderer. - * By default, this logger will use a console based ILogRenderer, - * and a J2EE Plugin identification. - * - * <p> - * When running outside of Eclipse, the trace and logging level come from the system properties - * <ul> - * <li>"debug" (="true") - The default is <code>false</code>. - * <li>"logLevel" (="level" where "level" is a level string, e.g. SEVERE, WARNING, etc. from the <code>java.util.logging.Level</code> class). - * The default is "WARNING". - * </ul> - * - * - * @since 1.0.0 - */ -public class Logger { - - // This is used by ILogRenderer2 to define the default level. - static class LocalLevel extends Level { - /** - * Comment for <code>serialVersionUID</code> - * - * @since 1.1.0 - */ - private static final long serialVersionUID = -6273357074767854883L; - - public LocalLevel(String name, int level) { - super(name, level); - } - } - - private boolean fTraceMode = false; // will we actually punch trace messaged or not - private String fPluginID; - private ILogRenderer fRenderer = null; - private ILogRenderer2 renderer2 = null; - public String fLineSeperator; - private Level level; - private Level defaultLevel = Level.SEVERE; // By default only severe or greater are logged. - private String logFileName; - private final static String DefaultLoggerPlugin = ILogRenderer.DefaultPluginID; - static private Hashtable Loggers = new Hashtable(); // Keep track of all the Loggers - final protected static String[] LogMark = { "*** ERROR *** ", //$NON-NLS-1$ - "[Trace] ", //$NON-NLS-1$ - "+++ Warning +++ ", //$NON-NLS-1$ - "Info " }; //$NON-NLS-1$ - - final protected static String Filler = " "; // Use this to indent msg. body //$NON-NLS-1$ - - protected Logger() { - this(ILogRenderer.DefaultPluginID); - } - - protected Logger(String pluginID) { - fPluginID = pluginID; - setRenderer(new JDKConsoleRenderer(this)); // Set up default to this. Someone can change it later. - } - - /** - * Return the stacktrace as a print formatted string. - * @param e - * @return the stacktrace as a string. - * - * @since 1.0.0 - */ - public String exceptionToString(Throwable e) { - StringWriter stringWriter = new StringWriter(); - e.printStackTrace(new PrintWriter(stringWriter)); - return stringWriter.toString(); - } - - /** - * Get the system default logger. This is used for clients that don't know if they - * are running in Eclipse or outside of it. This way they have a common logger format - * which switch correctly. - * @return default logger. - * - * @since 1.0.0 - */ - static public Logger getLogger() { - Logger defaultLogger = (Logger) Loggers.get(DefaultLoggerPlugin); - if (defaultLogger == null) { - defaultLogger = new Logger(); - defaultLogger.init(); - Loggers.put(DefaultLoggerPlugin, defaultLogger); - } - return defaultLogger; - } - - /** - * Get the logger for a specific plugin. - * @param pluginId - * @return logger for a specific pluggin. - * - * @since 1.0.0 - */ - static public Logger getLogger(String pluginId) { - if (pluginId == null) - return Logger.getLogger(); - Logger Logger = (Logger) Loggers.get(pluginId); - if (Logger == null) { - Logger = new Logger(pluginId); - Logger.init(); - Loggers.put(pluginId, Logger); - } - return Logger; - } - - /** - * Used by subclass to get a logger if it exists, but not create one. - * @param pluginId - * @return logger. - * - * @since 1.0.0 - */ - static protected Logger getLoggerIfExists(String pluginId) { - if (pluginId == null) - return Logger.getLogger(); - else - return (Logger) Loggers.get(pluginId); - } - - /** - * Get the plugin id for this logger. - * @return pluginid - * - * @since 1.0.0 - */ - public String getPluginID() { - return fPluginID; - } - - /** - * Get the trace mode for this logger - * @return <code>true</code> if tracing is going on. - * - * @since 1.0.0 - */ - public boolean getTraceMode() { - return fTraceMode; - } - - /* - * Indent the Msg. Body to make it easier to read the log - */ - private void indentMsg(String msg, StringBuffer logMsg) { - // Line seperator is different on different platform, unix = \n, windows \r\n and mac \r - String sep = fLineSeperator; - if (msg.indexOf("\r\n") != -1) //$NON-NLS-1$ - sep = "\r\n"; //$NON-NLS-1$ - else if (msg.indexOf("\n") != -1) //$NON-NLS-1$ - sep = "\n"; //$NON-NLS-1$ - else if (msg.indexOf("\r") != -1) //$NON-NLS-1$ - sep = "\r"; //$NON-NLS-1$ - StringTokenizer tokenizer = new StringTokenizer(msg, sep); - boolean first = true; - while (tokenizer.hasMoreTokens()) { - if (first) { - first = false; - logMsg.append(Filler + tokenizer.nextToken()); - } else - logMsg.append(fLineSeperator + Filler + tokenizer.nextToken()); - } - } - /* - * If Eclipse is started with the -XDebug or -debug turn traces on for this Logger - * Creation date: (8/23/2001 7:37:04 PM) - */ - private void init() { - if (System.getProperty("debug") != null) //$NON-NLS-1$ - fTraceMode = true; - level = defaultLevel = Level.parse(System.getProperty("logLevel", Level.WARNING.getName())); //$NON-NLS-1$ - - try { - fLineSeperator = System.getProperty("line.separator"); // Diff on Win/Unix/Mac //$NON-NLS-1$ - } catch (Exception e) { - fLineSeperator = "\n"; //$NON-NLS-1$ - } - } - /* - * Generic log. - * Creation date: (8/24/2001 1:55:34 PM) - * @return java.lang.String - * @param msg java.lang.String - * @param type int - */ - private String logAny(String msg, int type) { - StringBuffer logMsg = new StringBuffer(); - logMsg.append(fLineSeperator); - logMsg.append(LogMark[type]); - return punchLog(logRest(msg, logMsg), type); - } - - /** - * This is to be used by renderers that want to put a msg out - * in a generic format. This just returns the string that - * should be logged. It puts things like headers on it. - * - * @param msg - * @param aLevel - * @return The generic message for the string and level. - * - * @since 1.0.0 - */ - public String getGenericMsg(String msg, Level aLevel) { - StringBuffer genMsg = new StringBuffer(msg.length()+16); - genMsg.append(fLineSeperator); - genMsg.append(getLevelHeader(aLevel)); - genMsg.append(": "); //$NON-NLS-1$ - genMsg.append(new Date()); - indentMsg(msg, genMsg); - return genMsg.toString(); - } - - private static final Level[] LEVEL_SEARCH = new Level[] { - Level.SEVERE, - Level.WARNING, - Level.INFO, - ILogRenderer2.TRACE - }; - - private static final String[] LEVEL_MARK = new String[] { - "*** ERROR ***", //$NON-NLS-1$ - "+++ Warning +++", //$NON-NLS-1$ - "Info", //$NON-NLS-1$ - "[Trace]" //$NON-NLS-1$ - }; - - private String getLevelHeader(Level aLevel) { - for (int i=0; i<LEVEL_SEARCH.length; i++) - if (LEVEL_SEARCH[i] == aLevel) - return LEVEL_MARK[i]; - return aLevel.getName(); // Not found, just use level string. - } - - // The write's are here for history. Will implement using log(obj, Level) for all of the types. - - - /** - * deprecated use log(Level, Exception) - * @param aLevel - * @param ex - * @return - * - * @since 1.0.0 - * - */ - public String write(Level aLevel, Exception ex) { - return log(aLevel, ex); - } - - /** - * deprecated use log(Throwable) - * @param ex - * @return - * - * @since 1.0.0 - * - */ - public String write(Throwable ex) { - return log(ex); - } - - /** - * deprecated use log(Object, Level) - * @param aLevel - * @param logEntry - * @return - * - * @since 1.0.0 - */ - public String write(Level aLevel, Object logEntry) { - return log(logEntry, aLevel); - } - - /** - * deprecated use log(String, Level) - * @param aLevel - * @param string - * @return - * - * @since 1.0.0 - */ - public String write(Level aLevel, String string) { - return log(string, aLevel); - } - /** - * deprecated use log(Throwable, Level) - * @param aLevel - * @param ex - * @return - * - * @since 1.0.0 - */ - public String write(Level aLevel, Throwable ex) { - return log(ex, aLevel); - } - /** - * deprecated use log(Throwable, Level) - * @param aLevel - * @param ex - * @return - * - * @since 1.0.0 - */ - public String log(Level aLevel, Exception ex) { - return log(ex, aLevel); - } - /** - * deprecated use log(Throwable, Level) - * @param aLevel - * @param ex - * @return - * - * @since 1.0.0 - */ - public String log(Level aLevel, Throwable ex) { - return log(ex, aLevel); - } - - /** - * Get the logging level - * @return logging level - * - * @since 1.0.0 - */ - public Level getLevel() { - return level; - } - - /** - * Check if the requested level is being logged. (e.g. if current level is SEVERE, then FINE will not be logged). - * @param requestlevel - * @return <code>true</code> if the level will be logged. - * - * @since 1.0.0 - */ - public boolean isLoggingLevel(Level requestlevel) { - if (requestlevel == ILogRenderer2.TRACE && !getTraceMode()) - return false; // We aren't tracing but requested trace. - - return !(requestlevel.intValue() < getLevel().intValue() || getLevel() == Level.OFF); - } - - /** - * Log an error string. - * @param msg - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logError(String msg) { - return log(msg, Level.SEVERE); - } - - /** - * Log an error throwable - * @param e - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logError(Throwable e) { - return log(e, Level.SEVERE); - } - - /** - * Log an info message. - * @param msg - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logInfo(String msg) { - return log(msg, Level.INFO); - } - -/** - * Log a throwable as a warning. - * @param e - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logInfo(Throwable e) { - return log(e, Level.INFO); - } - - /** - * Append the string to logMsg buffer passed in. Append the date and format the - * string with nice indentation. - * - * @param msg - * @param logMsg - * @return the string from the logMsg after logging the rest. - * - * @since 1.0.0 - */ - protected String logRest(String msg, StringBuffer logMsg) { - logMsg.append(new Date()); - indentMsg(msg, logMsg); - return logMsg.toString(); - } - - /** - * Log the msg as trace only. - * @param msg - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logTrace(String msg) { - if (fTraceMode) - return log(msg, ILogRenderer2.TRACE); - else - return ILogRenderer.NOLOG_DESCRIPTION; - } - - /** - * Log the throwable as trace only. - * @param e - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logTrace(Throwable e) { - return log(e, ILogRenderer2.TRACE); - } - - /** - * Log the message as warning. - * @param msg - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logWarning(String msg) { - return log(msg, Level.WARNING); - } - /** - * Log the throwable as a warning. - * @param e - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String logWarning(Throwable e) { - return log(e, Level.WARNING); - } - - /** - * Ask the Renderer to punch the msg. in the log.. one - * caller at the time - * Creation date: (8/24/2001 9:19:17 AM) - * @return java.lang.String - * @param msg java.lang.String - * @param type int - */ - protected synchronized String punchLog(String msg, int type) { - return fRenderer.log(msg, type); - } - - /** - * Set the renderer to use. - * @param renderer - * - * @since 1.0.0 - */ - public void setRenderer(ILogRenderer renderer) { - fRenderer = renderer; - renderer2 = (renderer instanceof ILogRenderer2) ? (ILogRenderer2) renderer : null; - renderer.setTraceMode(getTraceMode()); - } - - /** - * Set the trace mode. - * @param flag <code>true</code> to turn on tracing. - * - * @since 1.0.0 - */ - public void setTraceMode(boolean flag) { - fTraceMode = flag; - if (fRenderer != null) - fRenderer.setTraceMode(flag); - } - - /** - * Set the level cutoff for logging. Anything below this level will not log. - * Do not set level to <code>ILogRenderer2.TRACE</code>. It doesn't make sense. - * - * @param level (Use <code>ILogRenderer2.DEFAULT</code> to restore to default for this logger. - * - * @since 1.0.0 - */ - public void setLevel(Level level) { - this.level = level != ILogRenderer2.DEFAULT ? level : defaultLevel; - } - - /** - * Set the default level for this logger. It won't touch the current level. - * - * @param level - * - * @since 1.0.0 - */ - public void setDefaultLevel(Level level) { - this.defaultLevel = level; - } - - /** - * Get the log file name. - * @return Returns the logFileName. - */ - public String getLogFileName() { - return logFileName; - } - - /** - * Set the log file name. - * @param logFileName The logFileName to set. - */ - public void setLogFileName(String logFileName) { - this.logFileName = logFileName; - } - - // Now all of the log() types that use a Level. - - /** - * Log the throwable at the default level for a throwable. - * @param e - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(Throwable e) { - return log(e, ILogRenderer2.DEFAULT); - } - - /** - * Log the throwable at the given level. - * @param e - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(Throwable e, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(e, logLevel); - } else { - // Do it the old way. - String stackTrace = exceptionToString(e); - return logAny(stackTrace, getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.SEVERE)); - } - } - - public String log(Object o) { - return log(o, ILogRenderer2.DEFAULT); - } - - /** - * Log the object at the given level. - * @param o - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(Object o, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(o, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(o), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - // The following are added to match up with Hyades so that primitives can be logged too. - - /** - * Log a boolean at the default level. - * @param b - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(boolean b) { - return log(b, ILogRenderer2.DEFAULT); - } - - /** - * Log a boolean at the given level. - * @param b - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(boolean b, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(b, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(b), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the character at the default level. - * @param c - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(char c) { - return log(c, ILogRenderer2.DEFAULT); - } - - /** - * Log the character at the given level. - * @param c - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(char c, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(c, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(c), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the byte at the default level. - * @param b - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(byte b) { - return log(b, ILogRenderer2.DEFAULT); - } - - /** - * Log the byte at the given level. - * @param b - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(byte b, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(b, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(b), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the short at the default level. - * @param s - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(short s) { - return log(s, ILogRenderer2.DEFAULT); - } - - /** - * Log the short at the given level. - * @param s - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(short s, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(s, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(s), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the int at the default level. - * @param i - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(int i) { - return log(i, ILogRenderer2.DEFAULT); - } - - /** - * Log the int at the default level. - * @param i - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(int i, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(i, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(i), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the long at the default level. - * @param l - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(long l) { - return log(l, ILogRenderer2.DEFAULT); - } - - /** - * Log the long at the given level. - * @param l - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(long l, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(l, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(l), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the float at the default level. - * @param f - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(float f) { - return log(f, ILogRenderer2.DEFAULT); - } - - /** - * Log the float at the given level. - * @param f - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(float f, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(f, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(f), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /** - * Log the double at the default level - * @param d - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(double d) { - return log(d, ILogRenderer2.DEFAULT); - } - - /** - * Log the double at the given level - * - * @param d - * @param logLevel - * @return how it was logged. See <code>CONSOLE_DESCRIPTION.</code> - * - * @since 1.0.0 - */ - public String log(double d, Level logLevel) { - if (renderer2 != null) { - return renderer2.log(d, logLevel); - } else { - // Do it the old way. - return logAny(String.valueOf(d), getOldType(logLevel != ILogRenderer2.DEFAULT ? level : Level.FINEST)); - } - } - - /* - * Turn new type into old type. The defaultLevel is the - * level to use if the incoming level is marked as default. - */ - private int getOldType(Level aLevel) { - if (aLevel == Level.SEVERE) - return ILogRenderer.LOG_ERROR; - else if (aLevel == Level.WARNING) - return ILogRenderer.LOG_WARNING; - else if (aLevel == Level.INFO) - return ILogRenderer.LOG_INFO; - else if (aLevel == ILogRenderer2.TRACE) - return ILogRenderer.LOG_TRACE; - else - return ILogRenderer.LOG_INFO; - } -} |