cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject [1/4] git commit: Add ability to set/get logging levels to nodetool patch by Jackson Chung reviewed by Vijay for CASSANDRA-6751
Date Tue, 29 Apr 2014 04:39:26 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk afe2e1407 -> b2ef56478


Add ability to set/get logging levels to nodetool
patch by Jackson Chung reviewed by Vijay for CASSANDRA-6751


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/0a20f5f1
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/0a20f5f1
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/0a20f5f1

Branch: refs/heads/trunk
Commit: 0a20f5f170b3596e6e74bba7daddebd4c1f5963a
Parents: daf54c5
Author: Vijay <vijay2win@gmail.com>
Authored: Mon Apr 28 21:24:07 2014 -0700
Committer: Vijay <vijay2win@gmail.com>
Committed: Mon Apr 28 21:27:58 2014 -0700

----------------------------------------------------------------------
 .../cassandra/service/StorageService.java       | 41 ++++++++++++++++++--
 .../cassandra/service/StorageServiceMBean.java  |  2 +
 .../org/apache/cassandra/tools/NodeCmd.java     | 29 +++++++++++++-
 .../org/apache/cassandra/tools/NodeProbe.java   | 10 +++++
 .../apache/cassandra/tools/NodeToolHelp.yaml    |  6 +++
 5 files changed, 84 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a20f5f1/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 75f6427..f44eaed 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -45,6 +45,7 @@ import com.google.common.util.concurrent.Uninterruptibles;
 import org.apache.cassandra.cql3.CQL3Type;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +58,6 @@ import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.*;
-import org.apache.cassandra.db.Keyspace;
 import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.db.index.SecondaryIndex;
 import org.apache.cassandra.dht.*;
@@ -2795,9 +2795,44 @@ public class StorageService extends NotificationBroadcasterSupport
implements IE
 
     public void setLog4jLevel(String classQualifier, String rawLevel)
     {
+        org.apache.log4j.Logger log4jlogger = org.apache.log4j.Logger.getLogger(classQualifier);
+        // if both classQualifer and rawLevel are empty, reload from configuration
+        if (StringUtils.isBlank(classQualifier) && StringUtils.isBlank(rawLevel))
+        {
+            LogManager.resetConfiguration();
+            CassandraDaemon.initLog4j();
+            return;
+        }
+        // classQualifer is set, but blank level given
+        else if (StringUtils.isNotBlank(classQualifier) && StringUtils.isBlank(rawLevel))
+        {
+            if (log4jlogger.getLevel() != null || log4jlogger.getAllAppenders().hasMoreElements())
+                log4jlogger.setLevel(null);
+            return;
+        }
+
         Level level = Level.toLevel(rawLevel);
-        org.apache.log4j.Logger.getLogger(classQualifier).setLevel(level);
-        logger.info("set log level to " + level + " for classes under '" + classQualifier
+ "' (if the level doesn't look like '" + rawLevel + "' then log4j couldn't parse '" + rawLevel
+ "')");
+        log4jlogger.setLevel(level);
+        logger.info("set log level to {} for classes under '{}' (if the level doesn't look
like '{}' then the logger couldn't parse '{}')", level, classQualifier, rawLevel, rawLevel);
+    }
+
+    /**
+     * @return the runtime logging levels for all the configured loggers
+     */
+    @Override
+    public Map<String,String> getLoggingLevels()
+    {
+        Map<String, String> logLevelMaps = Maps.newLinkedHashMap();
+        org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
+        logLevelMaps.put(rootLogger.getName(), rootLogger.getLevel().toString());
+        Enumeration<org.apache.log4j.Logger> loggers = LogManager.getCurrentLoggers();
+        while (loggers.hasMoreElements())
+        {
+            org.apache.log4j.Logger logger= loggers.nextElement();
+            if (logger.getLevel() != null)
+                logLevelMaps.put(logger.getName(), logger.getLevel().toString());
+        }
+        return logLevelMaps;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a20f5f1/src/java/org/apache/cassandra/service/StorageServiceMBean.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageServiceMBean.java b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
index ed260b8..9b1487f 100644
--- a/src/java/org/apache/cassandra/service/StorageServiceMBean.java
+++ b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
@@ -341,6 +341,8 @@ public interface StorageServiceMBean extends NotificationEmitter
     /** set the logging level at runtime */
     public void setLog4jLevel(String classQualifier, String level);
 
+    public Map<String,String>getLoggingLevels();
+
     /** get the operational mode (leaving, joining, normal, decommissioned, client) **/
     public String getOperationMode();
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a20f5f1/src/java/org/apache/cassandra/tools/NodeCmd.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeCmd.java b/src/java/org/apache/cassandra/tools/NodeCmd.java
index 618097d..b79a037 100644
--- a/src/java/org/apache/cassandra/tools/NodeCmd.java
+++ b/src/java/org/apache/cassandra/tools/NodeCmd.java
@@ -55,6 +55,9 @@ import org.apache.cassandra.streaming.SessionInfo;
 import org.apache.cassandra.utils.EstimatedHistogram;
 import org.apache.cassandra.utils.Pair;
 
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+
+
 public class NodeCmd
 {
     private static final String HISTORYFILE = "nodetool.history";
@@ -184,7 +187,9 @@ public class NodeCmd
         ENABLEBACKUP,
         DISABLEBACKUP,
         SETCACHEKEYSTOSAVE,
-        RELOADTRIGGERS
+        RELOADTRIGGERS,
+        SETLOGGINGLEVEL,
+        GETLOGGINGLEVELS
     }
 
 
@@ -1444,6 +1449,20 @@ public class NodeCmd
                     probe.reloadTriggers();
                     break;
 
+                case SETLOGGINGLEVEL:
+                    String classQualifer = EMPTY;
+                    String level = EMPTY;
+                    if (arguments.length >= 1)
+                        classQualifer = arguments[0];
+                    if (arguments.length == 2)
+                        level = arguments[1];
+                    probe.setLoggingLevel(classQualifer, level);
+                    break;
+
+                case GETLOGGINGLEVELS :
+                    nodeCmd.getLoggingLevels(System.out);
+                    break;
+
                 default :
                     throw new RuntimeException("Unreachable code.");
             }
@@ -1465,6 +1484,14 @@ public class NodeCmd
         System.exit(probe.isFailed() ? 1 : 0);
     }
 
+    private void getLoggingLevels(PrintStream out)
+    {
+        // what if some one set a very long logger name? 50 space may not be enough...
+        System.out.printf("%n%-50s%10s%n", "Logger Name", "Log Level");
+        for (Map.Entry<String, String> entry : this.probe.getLoggingLevels().entrySet())
+            System.out.printf("%-50s%10s%n", entry.getKey(), entry.getValue());
+    }
+
     private void printCompactionHistory(PrintStream out)
     {
         out.println("Compaction History: ");

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a20f5f1/src/java/org/apache/cassandra/tools/NodeProbe.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java
index f42fd22..f0ee15d 100644
--- a/src/java/org/apache/cassandra/tools/NodeProbe.java
+++ b/src/java/org/apache/cassandra/tools/NodeProbe.java
@@ -916,6 +916,16 @@ public class NodeProbe
     {
         spProxy.reloadTriggerClasses();
     }
+
+    public void setLoggingLevel(String classQualifier, String level)
+    {
+        ssProxy.setLog4jLevel(classQualifier, level);
+    }
+
+    public Map<String, String> getLoggingLevels()
+    {
+         return ssProxy.getLoggingLevels();
+    }
 }
 
 class ColumnFamilyStoreMBeanIterator implements Iterator<Map.Entry<String, ColumnFamilyStoreMBean>>

http://git-wip-us.apache.org/repos/asf/cassandra/blob/0a20f5f1/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
----------------------------------------------------------------------
diff --git a/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml b/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
index eaab98a..8b0185e 100644
--- a/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
+++ b/src/resources/org/apache/cassandra/tools/NodeToolHelp.yaml
@@ -220,3 +220,9 @@ commands:
   - name: reloadtriggers
     help: |
       reload trigger classes
+  - name: setLoggingLevel
+    help: |
+      Set a log level for a given logger. If both classQualifer and level are empty/null,
it will reset to the initial configuration
+  - name: getLoggingLevels
+    help: |
+      Get the runtime logging levels


Mime
View raw message