jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Partly revert removal of LoggingManager and LogKit-adapter
Date Wed, 25 Nov 2020 16:53:38 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new cb684ba  Partly revert removal of LoggingManager and LogKit-adapter
cb684ba is described below

commit cb684bad0b54e9782a563984168a62c63dda6947
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Wed Nov 25 17:47:03 2020 +0100

    Partly revert removal of LoggingManager and LogKit-adapter
    
    Partly revert 43217ec8086c8f2dc485936cd020c9c8107b698e "Remove LoggingManager class (it
has been deprecated since JMeter 3.2)"
    
    At least jmeter-plugins had some code, that still relied on JMeters
    LogKit-adapter and the LoggingManager class. So we will not remove those
    in the next release (5.4), but rather a bit later.
---
 .../org/apache/jorphan/logging/LoggingManager.java | 228 +++++++++++++++++++++
 .../apache/jorphan/logging/Slf4jLogkitLogger.java  | 163 +++++++++++++++
 xdocs/changes.xml                                  |   5 +-
 3 files changed, 395 insertions(+), 1 deletion(-)

diff --git a/src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java b/src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java
new file mode 100644
index 0000000..0bd44cc
--- /dev/null
+++ b/src/jorphan/src/main/java/org/apache/jorphan/logging/LoggingManager.java
@@ -0,0 +1,228 @@
+/*
+ * 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 java.util.Properties;
+
+import org.apache.log.LogTarget;
+import org.apache.log.Logger;
+import org.apache.log.Priority;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manages JMeter logging
+ * @deprecated since 3.2, use SLF4J for logger creation
+ */
+@Deprecated
+public final class LoggingManager {
+
+    /**
+     * Predefined format patterns, selected by the property log_format_type (see
+     * jmeter.properties) The new-line is added later
+     * @deprecated  since 3.2, use SLF4J for logging
+     */
+    @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$
+
+    /**
+     * @deprecated  since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static final String LOG_FILE = "log_file";  //$NON_NLS-1$
+
+    /**
+     * @deprecated  since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static final String LOG_PRIORITY = "log_level";  //$NON_NLS-1$
+
+    private LoggingManager() {
+        // non-instantiable - static methods only
+    }
+
+    /**
+     * Initialise the logging system from the Jmeter properties. Logkit loggers
+     * inherit from their parents.
+     *
+     * Normally the jmeter properties file defines a single log file, so set
+     * this as the default from "log_file", default "jmeter.log" The default
+     * priority is set from "log_level", with a default of INFO
+     *
+     * @param properties
+     *            {@link Properties} to be used for initialization
+     * @deprecated  since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void initializeLogging(Properties properties) {
+        // NOP
+    }
+
+    /**
+     * Handle LOG_PRIORITY.category=priority and LOG_FILE.category=file_name
+     * properties. If the prefix is detected, then remove it to get the
+     * category.
+     *
+     * @param appProperties
+     *            {@link Properties} that contain the
+     *            {@link LoggingManager#LOG_PRIORITY LOG_PRIORITY} and
+     *            {@link LoggingManager#LOG_FILE LOG_FILE} prefixed entries
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setLoggingLevels(Properties appProperties) {
+        // NOP
+    }
+
+    /**
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    private static final String PACKAGE_PREFIX = "org.apache."; //$NON_NLS-1$
+
+    /**
+     * Removes the standard prefix, i.e. "org.apache.".
+     *
+     * @param name from which to remove the prefix
+     * @return the name with the prefix removed
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @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.
+     *
+     * @return Logger
+     */
+    public static Logger getLoggerForClass() {
+        String className = new Exception().getStackTrace()[1].getClassName();
+        return new Slf4jLogkitLogger(LoggerFactory.getLogger(className));
+    }
+
+    /**
+     * Get the Logger for a class.
+     *
+     * @param category - the full name of the logger category
+     *
+     * @return Logger
+     */
+    public static Logger getLoggerFor(String category) {
+        return new Slf4jLogkitLogger(LoggerFactory.getLogger(category));
+    }
+
+    /**
+     * Get the Logger for a class.
+     *
+     * @param category - the full name of the logger category, this will have the prefix
removed.
+     *
+     * @return Logger
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static Logger getLoggerForShortName(String category) {
+        return getLoggerFor(category);
+    }
+
+    /**
+     * Set the logging priority for a category.
+     *
+     * @param priority - string containing the priority name, e.g. "INFO", "WARN", "DEBUG",
"FATAL_ERROR"
+     * @param category - string containing the category
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setPriority(String priority, String category) {
+        // NOP
+    }
+
+    /**
+     * Set the logging priority for a category.
+     *
+     * @param priority - priority, e.g. DEBUG, INFO
+     * @param fullName - e.g. org.apache.jmeter.etc, will have the prefix removed.
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setPriorityFullName(String priority, String fullName) {
+        // NOP
+    }
+
+    /**
+     * Set the logging priority for a category.
+     *
+     * @param priority - e.g. Priority.DEBUG
+     * @param category - string containing the category
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setPriority(Priority priority, String category) {
+        // NOP
+    }
+
+    /**
+     * Set the logging priority.
+     *
+     * @param priority - e.g. Priority.DEBUG
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setPriority(String priority) {
+        // NOP
+    }
+
+    /**
+     * Set the default logging priority.
+     *
+     * @param priority e.g. Priority.DEBUG
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setPriority(Priority priority) {
+        // NOP
+    }
+
+    /**
+     * Set the logging target for a category.
+     *
+     * @param target the LogTarget
+     * @param category the category name
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void setTarget(LogTarget target, String category) {
+        // NOP
+    }
+
+    /**
+     * Add logTargets to root logger
+     * FIXME What's the clean way to add a LogTarget afterwards ?
+     * @param logTargets LogTarget array
+     * @deprecated since 3.2, use SLF4J for logging
+     */
+    @Deprecated
+    public static void addLogTargetToRootLogger(LogTarget[] logTargets) {
+        // NOP
+    }
+}
diff --git a/src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java b/src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java
new file mode 100644
index 0000000..f3e373c
--- /dev/null
+++ b/src/jorphan/src/main/java/org/apache/jorphan/logging/Slf4jLogkitLogger.java
@@ -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.
+ */
+@Deprecated // Logger & Priority will be dropped in 3.3; so will this class be
+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));
+    }
+}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index a454b3b..b18a291 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -74,7 +74,10 @@ applications when JMeter is starting up.</p>
 
 <ch_section>Incompatible changes</ch_section>
 <ul>
-    <li>Remove <code>LoggingManager</code> class (it has been deprecated
since JMeter 3.2)</li>
+    <li>Remove LogKit logger functionality from some classes. This was intended to
completely remove
+      <code>LoggingManager</code> class (it has been deprecated since JMeter
3.2), but as jmeter-plugins
+      depended on it, <code>LoggingManager</code> and our <code>LogKit</code>-adapter
will remain for
+      this version (but is still deprecated).</li>
 </ul>
 <!-- =================== Improvements =================== -->
 


Mime
View raw message