storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [11/50] git commit: support loglevel to multilang's log interface and python & ruby implementation
Date Tue, 29 Jul 2014 20:58:10 GMT
support loglevel to multilang's log interface and python & ruby implementation


Project: http://git-wip-us.apache.org/repos/asf/incubator-storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-storm/commit/ea30b703
Tree: http://git-wip-us.apache.org/repos/asf/incubator-storm/tree/ea30b703
Diff: http://git-wip-us.apache.org/repos/asf/incubator-storm/diff/ea30b703

Branch: refs/heads/security
Commit: ea30b703865bf043bea2fc4f7c689f5a13d59c0f
Parents: 69b4601
Author: dashengju <dashengju@qq.com>
Authored: Sun Jul 20 17:34:41 2014 +0800
Committer: dashengju <dashengju@qq.com>
Committed: Sun Jul 20 17:34:41 2014 +0800

----------------------------------------------------------------------
 .../storm/multilang/JsonSerializer.java         |  7 ++++-
 .../jvm/backtype/storm/multilang/ShellMsg.java  | 26 ++++++++++++++++
 .../jvm/backtype/storm/spout/ShellSpout.java    | 30 ++++++++++++++++--
 .../src/jvm/backtype/storm/task/ShellBolt.java  | 32 ++++++++++++++++++--
 .../jvm/backtype/storm/utils/ShellProcess.java  |  2 +-
 storm-core/src/multilang/py/storm.py            | 19 ++++++++++--
 storm-core/src/multilang/rb/storm.rb            | 24 +++++++++++++--
 7 files changed, 129 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/jvm/backtype/storm/multilang/JsonSerializer.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/multilang/JsonSerializer.java b/storm-core/src/jvm/backtype/storm/multilang/JsonSerializer.java
index 4d3c3f8..fc97073 100644
--- a/storm-core/src/jvm/backtype/storm/multilang/JsonSerializer.java
+++ b/storm-core/src/jvm/backtype/storm/multilang/JsonSerializer.java
@@ -144,7 +144,12 @@ public class JsonSerializer implements ISerializer {
         shellMsg.setMetricName(metricName);
         
         Object paramsObj = msg.get("params");
-        shellMsg.setMetricParams(paramsObj); 
+        shellMsg.setMetricParams(paramsObj);
+
+        if (command.equals("log")) {
+            long logLevel = (Long)msg.get("level");
+            shellMsg.setLogLevel((int)logLevel);
+        }
 
         return shellMsg;
     }

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/jvm/backtype/storm/multilang/ShellMsg.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/multilang/ShellMsg.java b/storm-core/src/jvm/backtype/storm/multilang/ShellMsg.java
index ed803c4..e035df0 100644
--- a/storm-core/src/jvm/backtype/storm/multilang/ShellMsg.java
+++ b/storm-core/src/jvm/backtype/storm/multilang/ShellMsg.java
@@ -46,6 +46,24 @@ public class ShellMsg {
     private String metricName;
     private Object metricParams;
 
+    //logLevel
+    public enum ShellLogLevel {
+        TRACE, DEBUG, INFO, WARN, ERROR;
+
+        public static ShellLogLevel fromInt(int i) {
+            switch (i) {
+                case 0: return TRACE;
+                case 1: return DEBUG;
+                case 2: return INFO;
+                case 3: return WARN;
+                case 4: return ERROR;
+                default: return INFO;
+            }
+        }
+    }
+
+    private ShellLogLevel logLevel = ShellLogLevel.INFO;
+
     public String getCommand() {
         return command;
     }
@@ -139,4 +157,12 @@ public class ShellMsg {
     public Object getMetricParams() {
         return metricParams;
     }
+
+    public ShellLogLevel getLogLevel() {
+        return logLevel;
+    }
+
+    public void setLogLevel(int logLevel) {
+        this.logLevel = ShellLogLevel.fromInt(logLevel);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/jvm/backtype/storm/spout/ShellSpout.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/spout/ShellSpout.java b/storm-core/src/jvm/backtype/storm/spout/ShellSpout.java
index b271bfd..70bac5d 100644
--- a/storm-core/src/jvm/backtype/storm/spout/ShellSpout.java
+++ b/storm-core/src/jvm/backtype/storm/spout/ShellSpout.java
@@ -131,8 +131,7 @@ public class ShellSpout implements ISpout {
                 if (command.equals("sync")) {
                     return;
                 } else if (command.equals("log")) {
-                    String msg = shellMsg.getMsg();
-                    LOG.info("Shell msg: " + msg + _process.getProcessInfoString());
+                    handleLog(shellMsg);
                 } else if (command.equals("emit")) {
                     String stream = shellMsg.getStream();
                     Long task = shellMsg.getTask();
@@ -158,6 +157,33 @@ public class ShellSpout implements ISpout {
         }
     }
 
+    private void handleLog(ShellMsg shellMsg) {
+        String msg = shellMsg.getMsg();
+        msg = "ShellLog " + _process.getProcessInfoString() + " " + msg;
+        ShellMsg.ShellLogLevel logLevel = shellMsg.getLogLevel();
+
+        switch (logLevel) {
+            case TRACE:
+                LOG.trace(msg);
+                break;
+            case DEBUG:
+                LOG.debug(msg);
+                break;
+            case INFO:
+                LOG.info(msg);
+                break;
+            case WARN:
+                LOG.warn(msg);
+                break;
+            case ERROR:
+                LOG.error(msg);
+                break;
+            default:
+                LOG.info(msg);
+                break;
+        }
+    }
+
     @Override
     public void activate() {
     }

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/jvm/backtype/storm/task/ShellBolt.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/task/ShellBolt.java b/storm-core/src/jvm/backtype/storm/task/ShellBolt.java
index 430581d..4f8bca5 100644
--- a/storm-core/src/jvm/backtype/storm/task/ShellBolt.java
+++ b/storm-core/src/jvm/backtype/storm/task/ShellBolt.java
@@ -122,8 +122,7 @@ public class ShellBolt implements IBolt {
                         } else if (command.equals("error")) {
                             handleError(shellMsg.getMsg());
                         } else if (command.equals("log")) {
-                            String msg = shellMsg.getMsg();
-                            LOG.info("Shell msg: " + msg + _process.getProcessInfoString());
+                            handleLog(shellMsg);
                         } else if (command.equals("emit")) {
                             handleEmit(shellMsg);
                         } else if (command.equals("metrics")) {
@@ -234,7 +233,34 @@ public class ShellBolt implements IBolt {
                     shellMsg.getStream(), anchors, shellMsg.getTuple());
         }
     }
-    
+
+    private void handleLog(ShellMsg shellMsg) {
+        String msg = shellMsg.getMsg();
+        msg = "ShellLog " + _process.getProcessInfoString() + " " + msg;
+        ShellMsg.ShellLogLevel logLevel = shellMsg.getLogLevel();
+
+        switch (logLevel) {
+            case TRACE:
+                LOG.trace(msg);
+                break;
+            case DEBUG:
+                LOG.debug(msg);
+                break;
+            case INFO:
+                LOG.info(msg);
+                break;
+            case WARN:
+                LOG.warn(msg);
+                break;
+            case ERROR:
+                LOG.error(msg);
+                break;
+            default:
+                LOG.info(msg);
+                break;
+        }
+    }
+
     private void handleMetrics(ShellMsg shellMsg) {
         //get metric name
         String name = shellMsg.getMetricName();

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/jvm/backtype/storm/utils/ShellProcess.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/utils/ShellProcess.java b/storm-core/src/jvm/backtype/storm/utils/ShellProcess.java
index 79e7d50..6bcdf26 100644
--- a/storm-core/src/jvm/backtype/storm/utils/ShellProcess.java
+++ b/storm-core/src/jvm/backtype/storm/utils/ShellProcess.java
@@ -173,7 +173,7 @@ public class ShellProcess implements Serializable {
     }
 
     public String getProcessInfoString() {
-        return String.format(" pid:%s, name:%s ", pid, componentName);
+        return String.format("pid:%s, name:%s", pid, componentName);
     }
 
     public String getProcessTerminationInfoString() {

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/multilang/py/storm.py
----------------------------------------------------------------------
diff --git a/storm-core/src/multilang/py/storm.py b/storm-core/src/multilang/py/storm.py
index adeeb98..d2a3082 100755
--- a/storm-core/src/multilang/py/storm.py
+++ b/storm-core/src/multilang/py/storm.py
@@ -135,8 +135,23 @@ def fail(tup):
 def reportError(msg):
     sendMsgToParent({"command": "error", "msg": msg})
 
-def log(msg):
-    sendMsgToParent({"command": "log", "msg": msg})
+def log(msg, level=2):
+    sendMsgToParent({"command": "log", "msg": msg, "level":level})
+
+def logTrace(msg):
+    log(msg, 0)
+
+def logDebug(msg):
+    log(msg, 1)
+
+def logInfo(msg):
+    log(msg, 2)
+
+def logWarn(msg):
+    log(msg, 3)
+
+def logError(msg):
+    log(msg, 4)
 
 def rpcMetrics(name, params):
     sendMsgToParent({"command": "metrics", "name": name, "params": params})

http://git-wip-us.apache.org/repos/asf/incubator-storm/blob/ea30b703/storm-core/src/multilang/rb/storm.rb
----------------------------------------------------------------------
diff --git a/storm-core/src/multilang/rb/storm.rb b/storm-core/src/multilang/rb/storm.rb
index 57d45f1..17232d1 100644
--- a/storm-core/src/multilang/rb/storm.rb
+++ b/storm-core/src/multilang/rb/storm.rb
@@ -124,8 +124,28 @@ module Storm
       send_msg_to_parent :command => :error, :msg => msg.to_s
     end
 
-    def log(msg)
-      send_msg_to_parent :command => :log, :msg => msg.to_s
+    def log(msg, level=2)
+      send_msg_to_parent :command => :log, :msg => msg.to_s, :level => level
+    end
+
+    def logTrace(msg)
+      log(msg, 0)
+    end
+
+    def logDebug(msg)
+      log(msg, 1)
+    end
+
+    def logInfo(msg)
+      log(msg, 2)
+    end
+
+    def logWarn(msg)
+      log(msg, 3)
+    end
+
+    def logError(msg)
+      log(msg, 4)
     end
 
     def handshake


Mime
View raw message