Author: pmouawad
Date: Sun Feb 5 13:43:13 2017
New Revision: 1781757
URL: http://svn.apache.org/viewvc?rev=1781757&view=rev
Log:
Bug 60589 - Migrate LogKit to SLF4J - Drop avalon, logkit and excalibur with
backward compatibility for 3rd party modules
Part 2 of PR #254
Contributed by Woonsan Ko
Bugzilla Id: 60589
Added:
jmeter/trunk/src/jorphan/org/apache/jorphan/logging/Slf4jLogkitLogger.java
(with props)
jmeter/trunk/src/jorphan/org/apache/log/
jmeter/trunk/src/jorphan/org/apache/log/ContextMap.java (with props)
jmeter/trunk/src/jorphan/org/apache/log/LogEvent.java (with props)
jmeter/trunk/src/jorphan/org/apache/log/LogTarget.java (with props)
jmeter/trunk/src/jorphan/org/apache/log/Logger.java (with props)
jmeter/trunk/src/jorphan/org/apache/log/Priority.java (with props)
Modified:
jmeter/trunk/src/jorphan/org/apache/jorphan/logging/LoggingManager.java
Modified:
jmeter/trunk/src/jorphan/org/apache/jorphan/logging/LoggingManager.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/logging/LoggingManager.java?rev=1781757&r1=1781756&r2=1781757&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/logging/LoggingManager.java
(original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/logging/LoggingManager.java Sun
Feb 5 13:43:13 2017
@@ -18,64 +18,39 @@
package org.apache.jorphan.logging;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Properties;
-import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.DefaultContext;
-import org.apache.log.Hierarchy;
import org.apache.log.LogTarget;
import org.apache.log.Logger;
import org.apache.log.Priority;
-import org.apache.log.format.PatternFormatter;
-import org.apache.log.output.NullOutputLogTarget;
-import org.apache.log.output.io.WriterTarget;
-import org.xml.sax.SAXException;
+import org.slf4j.LoggerFactory;
/**
* Manages JMeter logging
+ * @deprecated since 3.2, use SLF4J for logger creation
*/
+@Deprecated
public final class LoggingManager {
- // N.B time pattern is passed to java.text.SimpleDateFormat
- /*
+
+ /**
* Predefined format patterns, selected by the property log_format_type
(see
* jmeter.properties) The new-line is added later
+ * @deprecated
*/
+ @Deprecated
public static final String DEFAULT_PATTERN = "%{time:yyyy/MM/dd HH:mm:ss}
%5.5{priority} - " //$NON_NLS-1$
+ "%{category}: %{message} %{throwable}"; //$NON_NLS-1$
- private static final String PATTERN_THREAD_PREFIX = "%{time:yyyy/MM/dd
HH:mm:ss} %5.5{priority} " //$NON_NLS-1$
- + "%20{thread} %{category}: %{message} %{throwable}";
//$NON_NLS-1$
-
- private static final String PATTERN_THREAD_SUFFIX = "%{time:yyyy/MM/dd
HH:mm:ss} %5.5{priority} " //$NON_NLS-1$
- + "%{category}[%{thread}]: %{message} %{throwable}"; //$NON_NLS-1$
-
- // Needs to be volatile as may be referenced from multiple threads
- // TODO see if this can be made final somehow
- private static volatile PatternFormatter format = null;
-
- /** Used to hold the default logging target. */
- //@GuardedBy("this")
- private static LogTarget target = new NullOutputLogTarget();
-
- // Hack to detect when System.out has been set as the target, to avoid
closing it
- private static volatile boolean isTargetSystemOut = false;// Is the target
System.out?
-
- private static volatile boolean isWriterSystemOut = false;// Is the Writer
System.out?
-
+ /**
+ * @deprecated
+ */
+ @Deprecated
public static final String LOG_FILE = "log_file"; //$NON_NLS-1$
+ /**
+ * @deprecated
+ */
+ @Deprecated
public static final String LOG_PRIORITY = "log_level"; //$NON_NLS-1$
private LoggingManager() {
@@ -92,103 +67,11 @@ public final class LoggingManager {
*
* @param properties
* {@link Properties} to be used for initialization
+ * @deprecated
*/
+ @Deprecated
public static void initializeLogging(Properties properties) {
- setFormat(properties);
-
- // Set the top-level defaults
- setTarget(makeWriter(properties.getProperty(LOG_FILE, "jmeter.log"),
LOG_FILE)); //$NON_NLS-1$
- setPriority(properties.getProperty(LOG_PRIORITY, "INFO"));
-
- setLoggingLevels(properties);
- // now set the individual categories (if any)
-
- setConfig(properties);// Further configuration
- }
-
- private static void setFormat(Properties properties) {
- String pattern = DEFAULT_PATTERN;
- String type = properties.getProperty("log_format_type", "");
//$NON_NLS-1$
- if (type.length() == 0) {
- pattern = properties.getProperty("log_format", DEFAULT_PATTERN);
//$NON_NLS-1$
- } else {
- if (type.equalsIgnoreCase("thread_suffix")) { //$NON_NLS-1$
- pattern = PATTERN_THREAD_SUFFIX;
- } else if (type.equalsIgnoreCase("thread_prefix")) { //$NON_NLS-1$
- pattern = PATTERN_THREAD_PREFIX;
- } else {
- pattern = DEFAULT_PATTERN;
- }
- }
- format = new PatternFormatter(pattern + "\n"); //$NON_NLS-1$
- }
-
- private static void setConfig(Properties p) {
- String cfg = p.getProperty("log_config"); //$NON_NLS-1$
- if (cfg == null) {
- return;
- }
-
- // Make sure same hierarchy is used
- Hierarchy hier = Hierarchy.getDefaultHierarchy();
- LogKitLoggerManager manager = new LogKitLoggerManager(null, hier,
null, null);
-
- DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder();
- try {
- Configuration c = builder.buildFromFile(cfg);
- Context ctx = new DefaultContext();
- manager.contextualize(ctx);
- manager.configure(c);
- } catch (IllegalArgumentException | ContextException
- | IOException | SAXException | ConfigurationException e) {
- // This happens if the default log-target id-ref specifies a
non-existent target
- System.out.println("Error processing logging config " + cfg);
- System.out.println(e.toString());
- } catch (NullPointerException e) {
- // This can happen if a log-target id-ref specifies a non-existent
target
- System.out.println("Error processing logging config " + cfg);
- System.out.println("Perhaps a log target is missing?");
- }
- }
-
- /*
- * Helper method to ensure that format is initialised if
initializeLogging()
- * has not yet been called.
- */
- private static PatternFormatter getFormat() {
- if (format == null) {
- format = new PatternFormatter(DEFAULT_PATTERN + "\n");
//$NON_NLS-1$
- }
- return format;
- }
-
- /*
- * Helper method to handle log target creation. If there is an error
- * creating the file, then it uses System.out.
- */
- private static Writer makeWriter(String logFile, String propName) {
- // If the name contains at least one set of paired single-quotes,
reformat using DateFormat
- final int length = logFile.split("'",-1).length;
- if (length > 1 && length %2 == 1){
- try {
- SimpleDateFormat df = new SimpleDateFormat(logFile);
- logFile = df.format(new Date());
- } catch (Exception ignored) {
- }
- }
- Writer wt;
- isWriterSystemOut = false;
- try {
- File logFileAsFile = new File(logFile);
- System.out.println("Writing log file to:
"+logFileAsFile.getAbsolutePath());
- wt = new FileWriter(logFile); //NOSONAR
- } catch (Exception e) {
- System.out.println(propName + "=" + logFile + " " + e.toString());
- System.out.println("[" + propName + "-> System.out]");
- isWriterSystemOut = true;
- wt = new PrintWriter(System.out); //NOSONAR
- }
- return wt;
+ // NOP
}
/**
@@ -200,24 +83,17 @@ public final class LoggingManager {
* {@link Properties} that contain the
* {@link LoggingManager#LOG_PRIORITY LOG_PRIORITY} and
* {@link LoggingManager#LOG_FILE LOG_FILE} prefixed entries
+ * @deprecated
*/
+ @Deprecated
public static void setLoggingLevels(Properties appProperties) {
- for (Object o : appProperties.keySet()) {
- String prop = (String) o;
- if (prop.startsWith(LOG_PRIORITY + ".")) //$NON_NLS-1$
- // don't match the empty category
- {
- String category = prop.substring(LOG_PRIORITY.length() + 1);
- setPriority(appProperties.getProperty(prop), category);
- }
- if (prop.startsWith(LOG_FILE + ".")) { //$NON_NLS-1$
- String category = prop.substring(LOG_FILE.length() + 1);
- String file = appProperties.getProperty(prop);
- setTarget(new WriterTarget(makeWriter(file, prop),
getFormat()), category);
- }
- }
+ // NOP
}
+ /**
+ * @deprecated
+ */
+ @Deprecated
private static final String PACKAGE_PREFIX = "org.apache."; //$NON_NLS-1$
/**
@@ -225,13 +101,16 @@ public final class LoggingManager {
*
* @param name from which to remove the prefix
* @return the name with the prefix removed
+ * @deprecated
*/
+ @Deprecated
public static String removePrefix(String name){
if (name.startsWith(PACKAGE_PREFIX)) { // remove the package prefix
name = name.substring(PACKAGE_PREFIX.length());
}
return name;
}
+
/**
* Get the Logger for a class - no argument needed because the calling
class
* name is derived automatically from the call stack.
@@ -240,7 +119,7 @@ public final class LoggingManager {
*/
public static Logger getLoggerForClass() {
String className = new Exception().getStackTrace()[1].getClassName();
- return
Hierarchy.getDefaultHierarchy().getLoggerFor(removePrefix(className));
+ return new Slf4jLogkitLogger(LoggerFactory.getLogger(className));
}
/**
@@ -251,7 +130,7 @@ public final class LoggingManager {
* @return Logger
*/
public static Logger getLoggerFor(String category) {
- return Hierarchy.getDefaultHierarchy().getLoggerFor(category);
+ return new Slf4jLogkitLogger(LoggerFactory.getLogger(category));
}
/**
@@ -260,9 +139,11 @@ public final class LoggingManager {
* @param category - the full name of the logger category, this will have
the prefix removed.
*
* @return Logger
+ * @deprecated
*/
+ @Deprecated
public static Logger getLoggerForShortName(String category) {
- return
Hierarchy.getDefaultHierarchy().getLoggerFor(removePrefix(category));
+ return getLoggerFor(category);
}
/**
@@ -270,9 +151,11 @@ public final class LoggingManager {
*
* @param priority - string containing the priority name, e.g. "INFO",
"WARN", "DEBUG", "FATAL_ERROR"
* @param category - string containing the category
+ * @deprecated
*/
+ @Deprecated
public static void setPriority(String priority, String category) {
- setPriority(Priority.getPriorityForName(trimPriority(priority)),
category);
+ // NOP
}
/**
@@ -280,9 +163,11 @@ public final class LoggingManager {
*
* @param priority - priority, e.g. DEBUG, INFO
* @param fullName - e.g. org.apache.jmeter.etc, will have the prefix
removed.
+ * @deprecated
*/
+ @Deprecated
public static void setPriorityFullName(String priority, String fullName) {
- setPriority(Priority.getPriorityForName(trimPriority(priority)),
removePrefix(fullName));
+ // NOP
}
/**
@@ -290,30 +175,33 @@ public final class LoggingManager {
*
* @param priority - e.g. Priority.DEBUG
* @param category - string containing the category
+ * @deprecated
*/
+ @Deprecated
public static void setPriority(Priority priority, String category) {
-
Hierarchy.getDefaultHierarchy().getLoggerFor(category).setPriority(priority);
+ // NOP
}
- public static void setPriority(String p) {
- setPriority(Priority.getPriorityForName(trimPriority(p)));
- }
-
/**
- * @param priority String log priority
- * @return String trimmed priority
+ * Set the logging priority.
+ *
+ * @param priority - e.g. Priority.DEBUG
+ * @deprecated
*/
- private static final String trimPriority(String priority) {
- return priority.trim();
+ @Deprecated
+ public static void setPriority(String p) {
+ // NOP
}
/**
* Set the default logging priority.
*
* @param priority e.g. Priority.DEBUG
+ * @deprecated
*/
+ @Deprecated
public static void setPriority(Priority priority) {
- Hierarchy.getDefaultHierarchy().setDefaultPriority(priority);
+ // NOP
}
/**
@@ -321,46 +209,21 @@ public final class LoggingManager {
*
* @param target the LogTarget
* @param category the category name
+ * @deprecated
*/
+ @Deprecated
public static void setTarget(LogTarget target, String category) {
- Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor(category);
- logger.setLogTargets(new LogTarget[] { target });
- }
-
- /**
- * Sets the default log target from the parameter. The existing target is
- * first closed if necessary.
- *
- * @param targetFile
- * (Writer)
- */
- private static synchronized void setTarget(Writer targetFile) {
- if (target == null) {
- target = getTarget(targetFile, getFormat());
- isTargetSystemOut = isWriterSystemOut;
- } else {
- if (!isTargetSystemOut && target instanceof WriterTarget) {
- ((WriterTarget) target).close();
- }
- target = getTarget(targetFile, getFormat());
- isTargetSystemOut = isWriterSystemOut;
- }
- Hierarchy.getDefaultHierarchy().setDefaultLogTarget(target);
- }
-
- private static LogTarget getTarget(Writer targetFile, PatternFormatter
fmt) {
- return new WriterTarget(targetFile, fmt);
+ // NOP
}
/**
* Add logTargets to root logger
* FIXME What's the clean way to add a LogTarget afterwards ?
* @param logTargets LogTarget array
+ * @deprecated
*/
+ @Deprecated
public static void addLogTargetToRootLogger(LogTarget[] logTargets) {
- LogTarget[] newLogTargets = new LogTarget[logTargets.length+1];
- System.arraycopy(logTargets, 0, newLogTargets, 1, logTargets.length);
- newLogTargets[0] = target;
-
Hierarchy.getDefaultHierarchy().getRootLogger().setLogTargets(newLogTargets);
+ // NOP
}
}
Added:
jmeter/trunk/src/jorphan/org/apache/jorphan/logging/Slf4jLogkitLogger.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/logging/Slf4jLogkitLogger.java?rev=1781757&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/logging/Slf4jLogkitLogger.java
(added)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/logging/Slf4jLogkitLogger.java
Sun Feb 5 13:43:13 2017
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jorphan.logging;
+
+import org.apache.log.Priority;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Wrapper, implementing <code>org.apache.log.Logger</code> and delegating to
the internal SLF4J logger.
+ */
+class Slf4jLogkitLogger extends org.apache.log.Logger {
+
+ private final Logger slf4jLogger;
+
+ Slf4jLogkitLogger(final Logger slf4jLogger) {
+ this.slf4jLogger = slf4jLogger;
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return slf4jLogger.isDebugEnabled();
+ }
+
+ @Override
+ public void debug(String message, Throwable throwable) {
+ slf4jLogger.debug(message, throwable);
+ }
+
+ @Override
+ public void debug(String message) {
+ slf4jLogger.debug(message);
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return slf4jLogger.isInfoEnabled();
+ }
+
+ @Override
+ public void info(String message, Throwable throwable) {
+ slf4jLogger.info(message, throwable);
+ }
+
+ @Override
+ public void info(String message) {
+ slf4jLogger.info(message);
+ }
+
+ @Override
+ public boolean isWarnEnabled() {
+ return slf4jLogger.isWarnEnabled();
+ }
+
+ @Override
+ public void warn(String message, Throwable throwable) {
+ slf4jLogger.warn(message, throwable);
+ }
+
+ @Override
+ public void warn(String message) {
+ slf4jLogger.warn(message);
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return slf4jLogger.isErrorEnabled();
+ }
+
+ @Override
+ public void error(String message, Throwable throwable) {
+ slf4jLogger.error(message, throwable);
+ }
+
+ @Override
+ public void error(String message) {
+ slf4jLogger.error(message);
+ }
+
+ @Override
+ public boolean isFatalErrorEnabled() {
+ return slf4jLogger.isErrorEnabled();
+ }
+
+ @Override
+ public void fatalError(String message, Throwable throwable) {
+ slf4jLogger.error(message, throwable);
+ }
+
+ @Override
+ public void fatalError(String message) {
+ slf4jLogger.error(message);
+ }
+
+ @Override
+ public boolean isPriorityEnabled(Priority priority) {
+ if (priority == Priority.FATAL_ERROR) {
+ return slf4jLogger.isErrorEnabled();
+ } else if (priority == Priority.ERROR) {
+ return slf4jLogger.isErrorEnabled();
+ } else if (priority == Priority.WARN) {
+ return slf4jLogger.isWarnEnabled();
+ } else if (priority == Priority.INFO) {
+ return slf4jLogger.isInfoEnabled();
+ } else if (priority == Priority.DEBUG) {
+ return slf4jLogger.isDebugEnabled();
+ }
+
+ return false;
+ }
+
+ @Override
+ public void log(Priority priority, String message, Throwable throwable) {
+ if (priority == Priority.FATAL_ERROR) {
+ slf4jLogger.error(message, throwable);
+ } else if (priority == Priority.ERROR) {
+ slf4jLogger.error(message, throwable);
+ } else if (priority == Priority.WARN) {
+ slf4jLogger.warn(message, throwable);
+ } else if (priority == Priority.INFO) {
+ slf4jLogger.info(message, throwable);
+ } else if (priority == Priority.DEBUG) {
+ slf4jLogger.debug(message, throwable);
+ }
+ }
+
+ @Override
+ public void log(Priority priority, String message) {
+ if (priority == Priority.FATAL_ERROR) {
+ slf4jLogger.error(message);
+ } else if (priority == Priority.ERROR) {
+ slf4jLogger.error(message);
+ } else if (priority == Priority.WARN) {
+ slf4jLogger.warn(message);
+ } else if (priority == Priority.INFO) {
+ slf4jLogger.info(message);
+ } else if (priority == Priority.DEBUG) {
+ slf4jLogger.debug(message);
+ }
+ }
+
+ @Override
+ public org.apache.log.Logger getChildLogger(String subCategory) {
+ return new Slf4jLogkitLogger(LoggerFactory
+ .getLogger(slf4jLogger.getName() +
org.apache.log.Logger.CATEGORY_SEPARATOR + subCategory));
+ }
+}
Propchange:
jmeter/trunk/src/jorphan/org/apache/jorphan/logging/Slf4jLogkitLogger.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jmeter/trunk/src/jorphan/org/apache/log/ContextMap.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/log/ContextMap.java?rev=1781757&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/log/ContextMap.java (added)
+++ jmeter/trunk/src/jorphan/org/apache/log/ContextMap.java Sun Feb 5 13:43:13
2017
@@ -0,0 +1,260 @@
+/*
+ * Copyright 1999-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.log;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+
+/**
+ * The ContextMap contains non-hierarchical context information
+ * relevant to a particular LogEvent. It may include information
+ * such as;
+ *
+ * <ul>
+ * <li>user ->fred</li>
+ * <li>hostname ->helm.realityforge.org</li>
+ * <li>ipaddress ->1.2.3.4</li>
+ * <li>interface ->127.0.0.1</li>
+ * <li>caller � �->com.biz.MyCaller.method(MyCaller.java:18)</li>
+ * <li>source � �->1.6.3.2:33</li>
+ * </ul>
+ * The context is bound to a thread (and inherited by sub-threads) but
+ * it can also be added to by LogTargets.
+ *
+ * @author <a href="mailto:[email protected]">Avalon Development Team</a>
+ * @author Peter Donald
+ * @deprecated
+ */
+@Deprecated
+public final class ContextMap
+ implements Serializable
+{
+ ///Thread local for holding instance of map associated with current thread
+ private static final ThreadLocal c_localContext = new
InheritableThreadLocal();
+
+ private final ContextMap m_parent;
+
+ ///Container to hold map of elements
+ private Hashtable m_map = new Hashtable();
+
+ ///Flag indicating whether this map should be readonly
+ private transient boolean m_readOnly;
+
+ /**
+ * Get the Current ContextMap.
+ * This method returns a ContextMap associated with current thread. If the
+ * thread doesn't have a ContextMap associated with it then a new
+ * ContextMap is created.
+ *
+ * @return the current ContextMap
+ */
+ public static final ContextMap getCurrentContext()
+ {
+ return getCurrentContext( true );
+ }
+
+ /**
+ * Get the Current ContextMap.
+ * This method returns a ContextMap associated with current thread.
+ * If the thread doesn't have a ContextMap associated with it and
+ * autocreate is true then a new ContextMap is created.
+ *
+ * @param autocreate true if a ContextMap is to be created if it doesn't
exist
+ * @return the current ContextMap
+ */
+ public static final ContextMap getCurrentContext( final boolean autocreate
)
+ {
+ //Check security permission here???
+ ContextMap context = (ContextMap)c_localContext.get();
+
+ if( null == context && autocreate )
+ {
+ context = new ContextMap();
+ c_localContext.set( context );
+ }
+
+ return context;
+ }
+
+ /**
+ * Bind a particular ContextMap to current thread.
+ *
+ * @param context the context map (may be null)
+ */
+ public static final void bind( final ContextMap context )
+ {
+ //Check security permission here??
+ c_localContext.set( context );
+ }
+
+ /**
+ * Default constructor.
+ */
+ public ContextMap()
+ {
+ this( null );
+ }
+
+ /**
+ * Constructor that sets parent contextMap.
+ *
+ * @param parent the parent ContextMap
+ */
+ public ContextMap( final ContextMap parent )
+ {
+ m_parent = parent;
+ }
+
+ /**
+ * Make the context read-only.
+ * This makes it safe to allow untrusted code reference
+ * to ContextMap.
+ */
+ public void makeReadOnly()
+ {
+ m_readOnly = true;
+ }
+
+ /**
+ * Determine if context is read-only.
+ *
+ * @return true if Context is read only, false otherwise
+ */
+ public boolean isReadOnly()
+ {
+ return m_readOnly;
+ }
+
+ /**
+ * Empty the context map.
+ *
+ */
+ public void clear()
+ {
+ checkReadable();
+
+ m_map.clear();
+ }
+
+ /**
+ * Get an entry from the context.
+ *
+ * @param key the key to map
+ * @param defaultObject a default object to return if key does not exist
+ * @return the object in context
+ */
+ public Object get( final String key, final Object defaultObject )
+ {
+ final Object object = get( key );
+
+ if( null != object )
+ {
+ return object;
+ }
+ else
+ {
+ return defaultObject;
+ }
+ }
+
+ /**
+ * Get an entry from the context.
+ *
+ * @param key the key to map
+ * @return the object in context or null if none with specified key
+ */
+ public Object get( final String key )
+ {
+ if( key == null )
+ {
+ return null;
+ }
+
+ final Object result = m_map.get( key );
+
+ if( null == result && null != m_parent )
+ {
+ return m_parent.get( key );
+ }
+
+ return result;
+ }
+
+ /**
+ * Set a value in context
+ *
+ * @param key the key
+ * @param value the value (may be null)
+ */
+ public void set( final String key, final Object value )
+ {
+ checkReadable();
+
+ if( value == null )
+ {
+ m_map.remove( key );
+ }
+ else
+ {
+ m_map.put( key, value );
+ }
+ }
+
+ /**
+ * Retrieve keys of entries into context map.
+ *
+ * @return the keys of items in context
+ */
+ /*
+ public String[] getKeys()
+ {
+ return (String[])m_map.keySet().toArray( new String[ 0 ] );
+ }
+ */
+
+ /**
+ * Get the number of contexts in map.
+ *
+ * @return the number of contexts in map
+ */
+ public int getSize()
+ {
+ return m_map.size();
+ }
+
+ /**
+ * Helper method that sets context to read-only after de-serialization.
+ *
+ * @return the corrected object version
+ */
+ private Object readResolve()
+ {
+ makeReadOnly();
+ return this;
+ }
+
+ /**
+ * Utility method to verify that Context is read-only.
+ */
+ private void checkReadable()
+ {
+ if( isReadOnly() )
+ {
+ throw new IllegalStateException( "ContextMap is read only and can
not be modified" );
+ }
+ }
+}
Propchange: jmeter/trunk/src/jorphan/org/apache/log/ContextMap.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jmeter/trunk/src/jorphan/org/apache/log/LogEvent.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/log/LogEvent.java?rev=1781757&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/log/LogEvent.java (added)
+++ jmeter/trunk/src/jorphan/org/apache/log/LogEvent.java Sun Feb 5 13:43:13
2017
@@ -0,0 +1,214 @@
+/*
+ * Copyright 1999-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.log;
+
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+
+/**
+ * This class encapsulates each individual log event.
+ * LogEvents usually originate at a Logger and are routed
+ * to LogTargets.
+ *
+ * @author <a href="mailto:[email protected]">Avalon Development Team</a>
+ * @author Peter Donald
+ * @deprecated
+ */
+@Deprecated
+public final class LogEvent
+ implements Serializable
+{
+ //A Constant used when retrieving time relative to start of applicaiton
start
+ private static final long START_TIME = System.currentTimeMillis();
+
+ ///The category that this LogEvent concerns. (Must not be null)
+ private String m_category;
+
+ ///The message to be logged. (Must not be null)
+ private String m_message;
+
+ ///The exception that caused LogEvent if any. (May be null)
+ private Throwable m_throwable;
+
+ ///The time in millis that LogEvent occurred
+ private long m_time;
+
+ ///The priority of LogEvent. (Must not be null)
+ private Priority m_priority;
+
+ ///The context map associated with LogEvent. (May be null).
+ private ContextMap m_contextMap;
+
+ /**
+ * Get Priority for LogEvent.
+ *
+ * @return the LogEvent Priority
+ */
+ public final Priority getPriority()
+ {
+ return m_priority;
+ }
+
+ /**
+ * Set the priority of LogEvent.
+ *
+ * @param priority the new LogEvent priority
+ */
+ public final void setPriority( final Priority priority )
+ {
+ m_priority = priority;
+ }
+
+ /**
+ * Get ContextMap associated with LogEvent
+ *
+ * @return the ContextMap
+ */
+ public final ContextMap getContextMap()
+ {
+ return m_contextMap;
+ }
+
+ /**
+ * Set the ContextMap for this LogEvent.
+ *
+ * @param contextMap the context map
+ */
+ public final void setContextMap( final ContextMap contextMap )
+ {
+ m_contextMap = contextMap;
+ }
+
+ /**
+ * Get the category that LogEvent relates to.
+ *
+ * @return the name of category
+ */
+ public final String getCategory()
+ {
+ return m_category;
+ }
+
+ /**
+ * Get the message associated with event.
+ *
+ * @return the message
+ */
+ public final String getMessage()
+ {
+ return m_message;
+ }
+
+ /**
+ * Get throwabe instance associated with event.
+ *
+ * @return the Throwable
+ */
+ public final Throwable getThrowable()
+ {
+ return m_throwable;
+ }
+
+ /**
+ * Get the absolute time of the log event.
+ *
+ * @return the absolute time
+ */
+ public final long getTime()
+ {
+ return m_time;
+ }
+
+ /**
+ * Get the time of the log event relative to start of application.
+ *
+ * @return the time
+ */
+ public final long getRelativeTime()
+ {
+ return m_time - START_TIME;
+ }
+
+ /**
+ * Set the LogEvent category.
+ *
+ * @param category the category
+ */
+ public final void setCategory( final String category )
+ {
+ m_category = category;
+ }
+
+ /**
+ * Set the message for LogEvent.
+ *
+ * @param message the message
+ */
+ public final void setMessage( final String message )
+ {
+ m_message = message;
+ }
+
+ /**
+ * Set the throwable for LogEvent.
+ *
+ * @param throwable the instance of Throwable
+ */
+ public final void setThrowable( final Throwable throwable )
+ {
+ m_throwable = throwable;
+ }
+
+ /**
+ * Set the absolute time of LogEvent.
+ *
+ * @param time the time
+ */
+ public final void setTime( final long time )
+ {
+ m_time = time;
+ }
+
+ /**
+ * Helper method that replaces deserialized priority with correct
singleton.
+ *
+ * @return the singleton version of object
+ * @exception ObjectStreamException if an error occurs
+ */
+ private Object readResolve()
+ throws ObjectStreamException
+ {
+ if( null == m_category )
+ {
+ m_category = "";
+ }
+ if( null == m_message )
+ {
+ m_message = "";
+ }
+
+ String priorityName = "";
+ if( null != m_priority )
+ {
+ priorityName = m_priority.getName();
+ }
+
+ m_priority = Priority.getPriorityForName( priorityName );
+
+ return this;
+ }
+}
Propchange: jmeter/trunk/src/jorphan/org/apache/log/LogEvent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jmeter/trunk/src/jorphan/org/apache/log/LogTarget.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/log/LogTarget.java?rev=1781757&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/log/LogTarget.java (added)
+++ jmeter/trunk/src/jorphan/org/apache/log/LogTarget.java Sun Feb 5 13:43:13
2017
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1999-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.log;
+
+/**
+ * LogTarget is a class to encapsulate outputting LogEvent's.
+ * This provides the base for all output and filter targets.
+ *
+ * Warning: If performance becomes a problem then this
+ * interface will be rewritten as a abstract class.
+ *
+ * @author Peter Donald
+ * @deprecated
+ */
+@Deprecated
+public interface LogTarget
+{
+ /**
+ * Process a log event.
+ * In NO case should this method ever throw an exception/error.
+ * The reason is that logging is usually added for debugging/auditing
+ * purposes and it would be unnaceptable to have your debugging
+ * code cause more errors.
+ *
+ * @param event the event
+ */
+ void processEvent( LogEvent event );
+}
Propchange: jmeter/trunk/src/jorphan/org/apache/log/LogTarget.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jmeter/trunk/src/jorphan/org/apache/log/Logger.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/log/Logger.java?rev=1781757&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/log/Logger.java (added)
+++ jmeter/trunk/src/jorphan/org/apache/log/Logger.java Sun Feb 5 13:43:13 2017
@@ -0,0 +1,286 @@
+/*
+ * Copyright 1999-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.log;
+
+/**
+ * The object interacted with by client objects to perform logging.
+ *
+ * @author <a href="mailto:[email protected]">Avalon Development Team</a>
+ * @author Peter Donald
+ * @deprecated
+ */
+@Deprecated
+public abstract class Logger
+{
+ private static final Logger[] EMPTY_SET = new Logger[ 0 ];
+
+ /**
+ * Separator character use to separate different categories
+ * @deprecated
+ */
+ @Deprecated
+ public static final char CATEGORY_SEPARATOR = '.';
+
+ /**
+ * Determine if messages of priority DEBUG will be logged.
+ *
+ * @return true if DEBUG messages will be logged
+ */
+ public abstract boolean isDebugEnabled();
+
+ /**
+ * Log a debug priority event.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ public abstract void debug( final String message, final Throwable
throwable );
+
+ /**
+ * Log a debug priority event.
+ *
+ * @param message the message
+ */
+ public abstract void debug( final String message );
+
+ /**
+ * Determine if messages of priority INFO will be logged.
+ *
+ * @return true if INFO messages will be logged
+ */
+ public abstract boolean isInfoEnabled();
+
+ /**
+ * Log a info priority event.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ public abstract void info( final String message, final Throwable throwable
);
+
+ /**
+ * Log a info priority event.
+ *
+ * @param message the message
+ */
+ public abstract void info( final String message );
+
+ /**
+ * Determine if messages of priority WARN will be logged.
+ *
+ * @return true if WARN messages will be logged
+ */
+ public abstract boolean isWarnEnabled();
+
+ /**
+ * Log a warn priority event.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ public abstract void warn( final String message, final Throwable throwable
);
+
+ /**
+ * Log a warn priority event.
+ *
+ * @param message the message
+ */
+ public abstract void warn( final String message );
+
+ /**
+ * Determine if messages of priority ERROR will be logged.
+ *
+ * @return true if ERROR messages will be logged
+ */
+ public abstract boolean isErrorEnabled();
+
+ /**
+ * Log a error priority event.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ public abstract void error( final String message, final Throwable
throwable );
+
+ /**
+ * Log a error priority event.
+ *
+ * @param message the message
+ */
+ public abstract void error( final String message );
+
+ /**
+ * Determine if messages of priority FATAL_ERROR will be logged.
+ *
+ * @return true if FATAL_ERROR messages will be logged
+ */
+ public abstract boolean isFatalErrorEnabled();
+
+ /**
+ * Log a fatalError priority event.
+ *
+ * @param message the message
+ * @param throwable the throwable
+ */
+ public abstract void fatalError( final String message, final Throwable
throwable );
+
+ /**
+ * Log a fatalError priority event.
+ *
+ * @param message the message
+ */
+ public abstract void fatalError( final String message );
+
+ /**
+ * Make this logger additive. I.e. Send all log events to parent
+ * loggers LogTargets regardless of whether or not the
+ * LogTargets have been overidden.
+ *
+ * This is derived from Log4js notion of Additivity.
+ *
+ * @param additivity true to make logger additive, false otherwise
+ * @deprecated
+ */
+ @Deprecated
+ public void setAdditivity( final boolean additivity )
+ {
+ // NOP
+ }
+
+ /**
+ * Determine if messages of priority �will be logged.
+ * @param priority the priority
+ * @return true if messages will be logged
+ */
+ public abstract boolean isPriorityEnabled( final Priority priority );
+
+ /**
+ * Log a event at specific priority with a certain message and throwable.
+ *
+ * @param priority the priority
+ * @param message the message
+ * @param throwable the throwable
+ */
+ public abstract void log( final Priority priority,
+ final String message,
+ final Throwable throwable );
+
+ /**
+ * Log a event at specific priority with a certain message.
+ *
+ * @param priority the priority
+ * @param message the message
+ */
+ public abstract void log( final Priority priority, final String message );
+
+ /**
+ * Set the priority for this logger.
+ *
+ * @param priority the priority
+ * @deprecated
+ */
+ @Deprecated
+ public void setPriority( final Priority priority )
+ {
+ // NOP
+ }
+
+ /**
+ * Unset the priority of Logger.
+ * (Thus it will use it's parent's priority or DEBUG if no parent.
+ * @deprecated
+ */
+ @Deprecated
+ public void unsetPriority()
+ {
+ // NOP
+ }
+
+ /**
+ * Unset the priority of Logger.
+ * (Thus it will use it's parent's priority or DEBUG if no parent.
+ * If recursive is true unset priorities of all child loggers.
+ *
+ * @param recursive true to unset priority of all child loggers
+ * @deprecated
+ */
+ @Deprecated
+ public void unsetPriority( final boolean recursive )
+ {
+ // NOP
+ }
+
+ /**
+ * Set the log targets for this logger.
+ *
+ * @param logTargets the Log Targets
+ * @deprecated
+ */
+ @Deprecated
+ public void setLogTargets( final LogTarget[] logTargets )
+ {
+ // NOP
+ }
+
+ /**
+ * Unset the logtargets for this logger.
+ * This logger (and thus all child loggers who don't specify logtargets)
will
+ * inherit from the parents LogTargets.
+ * @deprecated
+ */
+ @Deprecated
+ public void unsetLogTargets()
+ {
+ // NOP
+ }
+
+ /**
+ * Unset the logtargets for this logger and all child loggers if recursive
is set.
+ * The loggers unset (and all child loggers who don't specify logtargets)
will
+ * inherit from the parents LogTargets.
+ * @param recursive the recursion policy
+ * @deprecated
+ */
+ @Deprecated
+ public void unsetLogTargets( final boolean recursive )
+ {
+ // NOP
+ }
+
+ /**
+ * Get all the child Loggers of current logger.
+ *
+ * @return the child loggers
+ * @deprecated
+ */
+ @Deprecated
+ public Logger[] getChildren()
+ {
+ // NOP
+ return EMPTY_SET;
+ }
+
+ /**
+ * Create a new child logger.
+ * The category of child logger is [current-category].subcategory
+ *
+ * @param subCategory the subcategory of this logger
+ * @return the new logger
+ * @exception IllegalArgumentException if subCategory has an empty element
name
+ */
+ public abstract Logger getChildLogger( final String subCategory );
+}
Propchange: jmeter/trunk/src/jorphan/org/apache/log/Logger.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jmeter/trunk/src/jorphan/org/apache/log/Priority.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/log/Priority.java?rev=1781757&view=auto
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/log/Priority.java (added)
+++ jmeter/trunk/src/jorphan/org/apache/log/Priority.java Sun Feb 5 13:43:13
2017
@@ -0,0 +1,193 @@
+/*
+ * Copyright 1999-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.log;
+
+import java.io.Serializable;
+
+/**
+ * Class representing and holding constants for priority.
+ *
+ * @author Peter Donald
+ * @deprecated
+ */
+@Deprecated
+public final class Priority
+ implements Serializable
+{
+ /**
+ * Developer orientated messages, usually used during development of
product.
+ */
+ public static final Priority DEBUG = new Priority( "DEBUG", 5 );
+
+ /**
+ * Useful information messages such as state changes, client connection,
user login etc.
+ */
+ public static final Priority INFO = new Priority( "INFO", 10 );
+
+ /**
+ * A problem or conflict has occurred but it may be recoverable, then
+ * again it could be the start of the system failing.
+ */
+ public static final Priority WARN = new Priority( "WARN", 15 );
+
+ /**
+ * A problem has occurred but it is not fatal. The system will still
function.
+ */
+ public static final Priority ERROR = new Priority( "ERROR", 20 );
+
+ /**
+ * Something caused whole system to fail. This indicates that an
administrator
+ * should restart the system and try to fix the problem that caused the
failure.
+ */
+ public static final Priority FATAL_ERROR = new Priority( "FATAL_ERROR", 25
);
+
+ /**
+ * Do not log anything.
+ */
+ public static final Priority NONE = new Priority( "NONE",
Integer.MAX_VALUE );
+
+ private final String m_name;
+ private final int m_priority;
+
+ /**
+ * Retrieve a Priority object for the name parameter.
+ *
+ * @param priority the priority name
+ * @return the Priority for name
+ */
+ public static Priority getPriorityForName( final String priority )
+ {
+ if( Priority.DEBUG.getName().equals( priority ) )
+ {
+ return Priority.DEBUG;
+ }
+ else if( Priority.INFO.getName().equals( priority ) )
+ {
+ return Priority.INFO;
+ }
+ else if( Priority.WARN.getName().equals( priority ) )
+ {
+ return Priority.WARN;
+ }
+ else if( Priority.ERROR.getName().equals( priority ) )
+ {
+ return Priority.ERROR;
+ }
+ else if( Priority.FATAL_ERROR.getName().equals( priority ) )
+ {
+ return Priority.FATAL_ERROR;
+ }
+ else if( Priority.NONE.getName().equals( priority ) )
+ {
+ return Priority.NONE;
+ }
+ else
+ {
+ return Priority.DEBUG;
+ }
+ }
+
+ /**
+ * Private Constructor to block instantiation outside class.
+ *
+ * @param name the string name of priority
+ * @param priority the numerical code of priority
+ */
+ private Priority( final String name, final int priority )
+ {
+ if( null == name )
+ {
+ throw new NullPointerException( "name" );
+ }
+
+ m_name = name;
+ m_priority = priority;
+ }
+
+ /**
+ * Overidden string to display Priority in human readable form.
+ *
+ * @return the string describing priority
+ */
+ public String toString()
+ {
+ return "Priority[" + getName() + "/" + getValue() + "]";
+ }
+
+ /**
+ * Get numerical value associated with priority.
+ *
+ * @return the numerical value
+ */
+ public int getValue()
+ {
+ return m_priority;
+ }
+
+ /**
+ * Get name of priority.
+ *
+ * @return the priorities name
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * Test whether this priority is greater than other priority.
+ *
+ * @param other the other Priority
+ * @return TRUE if the priority is greater else FALSE
+ */
+ public boolean isGreater( final Priority other )
+ {
+ return m_priority > other.getValue();
+ }
+
+ /**
+ * Test whether this priority is lower than other priority.
+ *
+ * @param other the other Priority
+ * @return TRUE if the priority is lower else FALSE
+ */
+ public boolean isLower( final Priority other )
+ {
+ return m_priority < other.getValue();
+ }
+
+ /**
+ * Test whether this priority is lower or equal to other priority.
+ *
+ * @param other the other Priority
+ * @return TRUE if the priority is lower or equal else FALSE
+ */
+ public boolean isLowerOrEqual( final Priority other )
+ {
+ return m_priority <= other.getValue();
+ }
+
+ /**
+ * Helper method that replaces deserialized object with correct singleton.
+ *
+ * @return the singleton version of object
+ */
+ private Object readResolve()
+ {
+ return getPriorityForName( m_name );
+ }
+}
Propchange: jmeter/trunk/src/jorphan/org/apache/log/Priority.java
------------------------------------------------------------------------------
svn:mime-type = text/plain