jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vladimirsitni...@apache.org
Subject [jmeter] branch master updated: Mark the currently selected log level in the options menu
Date Sun, 05 Apr 2020 12:40:22 GMT
This is an automated email from the ASF dual-hosted git repository.

vladimirsitnikov 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 2314361  Mark the currently selected log level in the options menu
2314361 is described below

commit 231436138836aafd9f697896cdc9b442faa4e8d2
Author: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
AuthorDate: Sun Apr 5 15:39:58 2020 +0300

    Mark the currently selected log level in the options menu
---
 .../org/apache/jmeter/gui/action/LogLevelCommand.java    | 16 +++++++++++++---
 .../java/org/apache/jmeter/gui/util/JMeterMenuBar.java   | 16 +++++++++++++---
 xdocs/changes.xml                                        |  4 +++-
 3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/core/src/main/java/org/apache/jmeter/gui/action/LogLevelCommand.java b/src/core/src/main/java/org/apache/jmeter/gui/action/LogLevelCommand.java
index 2454d55..a21473f 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/action/LogLevelCommand.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/action/LogLevelCommand.java
@@ -21,10 +21,13 @@ import java.awt.event.ActionEvent;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apiguardian.api.API;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.event.Level;
 
 /**
  * Implements log level setting menu item.
@@ -49,12 +52,19 @@ public class LogLevelCommand extends AbstractAction {
     @Override
     public void doAction(ActionEvent ev) {
         String levelString = ev.getActionCommand().substring(ActionNames.LOG_LEVEL_PREFIX.length());
-        log.warn("Setting root log level: {}", levelString);
-        Configurator.setRootLevel(org.apache.logging.log4j.Level.toLevel(levelString));
+        log.info("Setting root log level: {}", levelString);
+        Configurator.setRootLevel(Level.toLevel(levelString));
     }
 
     @Override
     public Set<String> getActionNames() {
         return commands;
     }
+
+    @API(since = "5.3", status = API.Status.INTERNAL)
+    public static Level getRootLevel() {
+        final LoggerContext loggerContext = LoggerContext.getContext(false);
+        final LoggerConfig loggerConfig = loggerContext.getConfiguration().getRootLogger();
+        return loggerConfig.getLevel();
+    }
 }
diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java
index 4ebb954..a7bd559 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JMeterMenuBar.java
@@ -47,6 +47,7 @@ import org.apache.jmeter.gui.action.ActionNames;
 import org.apache.jmeter.gui.action.ActionRouter;
 import org.apache.jmeter.gui.action.KeyStrokes;
 import org.apache.jmeter.gui.action.LoadRecentProject;
+import org.apache.jmeter.gui.action.LogLevelCommand;
 import org.apache.jmeter.gui.action.LookAndFeelCommand;
 import org.apache.jmeter.gui.plugin.MenuCreator;
 import org.apache.jmeter.gui.plugin.MenuCreator.MENU_LOCATION;
@@ -56,9 +57,9 @@ import org.apache.jmeter.util.LocaleChangeListener;
 import org.apache.jmeter.util.SSLManager;
 import org.apache.jorphan.reflect.ClassFinder;
 import org.apache.jorphan.util.JOrphanUtils;
+import org.apache.logging.log4j.Level;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.event.Level;
 
 public class JMeterMenuBar extends JMenuBar implements LocaleChangeListener {
     private static final long serialVersionUID = 241L;
@@ -300,12 +301,21 @@ public class JMeterMenuBar extends JMenuBar implements LocaleChangeListener
{
         JMenu menuLoggerLevel = makeMenuRes("menu_logger_level"); //$NON-NLS-1$
         JMenuItem menuItem;
         String levelString;
-        for (Level level : Level.values()) {
+        // Note: slf4j does not provide a way to set log level, so we use log4j levels here
+        Level currentLevel = LogLevelCommand.getRootLevel();
+        ButtonGroup loggerLevels = new ButtonGroup();
+        Level[] logLevels = Level.values();
+        Arrays.sort(logLevels);
+        for (Level level : logLevels) {
             levelString = level.toString();
-            menuItem = new JMenuItem(levelString);
+            menuItem = new JRadioButtonMenuItem(levelString);
             menuItem.addActionListener(ActionRouter.getInstance());
             menuItem.setActionCommand(ActionNames.LOG_LEVEL_PREFIX + levelString);
             menuItem.setToolTipText(levelString); // show the classname to the user
+            if (level.equals(currentLevel)) {
+                menuItem.setSelected(true);
+            }
+            loggerLevels.add(menuItem);
             menuLoggerLevel.add(menuItem);
         }
         optionsMenu.add(menuLoggerLevel);
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 3b71c14..18a91b6 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -102,7 +102,9 @@ For instance: log viewer, JSR223 code editor were not previously scaled
with zoo
 Undo is implemented on a field level basis (each fields has its own history), and the history
is
 invalidated when tree selection changes.</p>
 
-<p>Mark the currently selected language in the options menu</p>
+<p>Mark the currently selected language in the options menu.</p>
+
+<p>Mark the currently selected log level in the options menu.</p>
 <!--
 <ch_title>Functions</ch_title>
 -->


Mime
View raw message