Fix: JUL support multiple loglevels
authorDavid Goulet <dgoulet@efficios.com>
Thu, 27 Feb 2014 19:51:55 +0000 (14:51 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 27 Feb 2014 21:15:21 +0000 (16:15 -0500)
Fixes #744

Signed-off-by: David Goulet <dgoulet@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-jul/org/lttng/ust/jul/LTTngEvent.java
liblttng-ust-jul/org/lttng/ust/jul/LTTngLogHandler.java
liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java
liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java

index a519f449e2c7ede19e7ceaa97ab30d48939361da..6d81922ea9148f330718085570044a1140889081 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.lttng.ust.jul;
 
+import java.util.ArrayList;
 import java.lang.String;
 
 import org.lttng.ust.jul.LTTngUst;
@@ -26,7 +27,7 @@ class LTTngLogLevel {
        public int level;
        public int type;
 
-       public LTTngLogLevel(String event_name, int level, int type) {
+       public LTTngLogLevel(int level, int type) {
                this.type = type;
                this.level = level;
        }
@@ -35,10 +36,14 @@ class LTTngLogLevel {
 public class LTTngEvent {
        /* Name of the event. */
        public String name;
-       public LTTngLogLevel logLevel;
+       public ArrayList<LTTngLogLevel> logLevels = new ArrayList<LTTngLogLevel>();
+
+       public void addLogLevel(int loglevel, int loglevel_type) {
+               this.logLevels.add(new LTTngLogLevel(loglevel, loglevel_type));
+       }
 
        public LTTngEvent(String name, int loglevel, int loglevel_type) {
                this.name = name;
-               this.logLevel = new LTTngLogLevel(name, loglevel, loglevel_type);
+               this.addLogLevel(loglevel, loglevel_type);
        }
 }
index 1ad1171279b271f60d64f2a8a8c22cae1b79a2e5..b4e1c088423a5a2e68f491b07ff9c24c528c97f7 100644 (file)
@@ -22,6 +22,7 @@ import java.util.logging.Handler;
 import java.util.logging.LogRecord;
 import java.util.logging.LogManager;
 import java.util.logging.Level;
+import java.util.ArrayList;
 import java.util.HashMap;
 
 import org.lttng.ust.jul.LTTngUst;
@@ -40,8 +41,8 @@ public class LTTngLogHandler extends Handler {
         * enabled should use the loglevel/type below.
         */
        public int logLevelUseAll = 0;
-       public int logLevelAll = 0;
-       public int logLevelTypeAll;
+       public ArrayList<LTTngLogLevel> logLevelsAll =
+               new ArrayList<LTTngLogLevel>();
 
        /* Am I a root Log Handler. */
        public int is_root = 0;
@@ -61,8 +62,25 @@ public class LTTngLogHandler extends Handler {
                LTTngUst.init();
        }
 
-       public void setEvent(LTTngEvent event) {
-               eventMap.put(event.name, event);
+       /**
+        * Add event to handler hash map if new.
+        *
+        * @return 0 if it did not exist else 1.
+        */
+       public int setEvent(LTTngEvent new_event) {
+               LTTngEvent event;
+
+               event = eventMap.get(new_event.name);
+               if (event == null) {
+                       eventMap.put(new_event.name, new_event);
+                       /* Did not exists. */
+                       return 0;
+               } else {
+                       /* Add new event loglevel to existing event. */
+                       event.logLevels.addAll(new_event.logLevels);
+                       /* Already exists. */
+                       return 1;
+               }
        }
 
        @Override
@@ -81,24 +99,34 @@ public class LTTngLogHandler extends Handler {
                /* Get back the event if any and check for loglevel. */
                event = eventMap.get(logger_name);
                if (event != null) {
-                       rec_log_level = record.getLevel().intValue();
-                       ev_log_level = event.logLevel.level;
-                       ev_type = event.logLevel.type;
-
-                       switch (ev_type) {
-                       case LTTngLogLevelABI.LOGLEVEL_TYPE_RANGE:
-                               if (ev_log_level <= rec_log_level) {
+                       for (LTTngLogLevel ev_log : event.logLevels) {
+                               /* Get record and event log level. */
+                               rec_log_level = record.getLevel().intValue();
+                               ev_log_level = ev_log.level;
+
+                               switch (ev_log.type) {
+                               case LTTngLogLevelABI.LOGLEVEL_TYPE_RANGE:
+                                       if (ev_log_level <= rec_log_level) {
+                                               fire_tp = 1;
+                                       }
+                                       break;
+                               case LTTngLogLevelABI.LOGLEVEL_TYPE_SINGLE:
+                                       if (ev_log_level == rec_log_level) {
+                                               fire_tp = 1;
+                                       }
+                                       break;
+                               case LTTngLogLevelABI.LOGLEVEL_TYPE_ALL:
                                        fire_tp = 1;
+                                       break;
                                }
-                               break;
-                       case LTTngLogLevelABI.LOGLEVEL_TYPE_SINGLE:
-                               if (ev_log_level == rec_log_level) {
-                                       fire_tp = 1;
+
+                               /*
+                                * If we match, stop right now else continue to the next
+                                * loglevel contained in the event.
+                                */
+                               if (fire_tp == 1) {
+                                       break;
                                }
-                               break;
-                       case LTTngLogLevelABI.LOGLEVEL_TYPE_ALL:
-                               fire_tp = 1;
-                               break;
                        }
                } else {
                        /* No loglevel attached thus fire tracepoint. */
index 4cb5a7319e99fdad88bdfd684b1c350befdcc33b..9b544be55086f11441090cdeadae1ccb80251572 100644 (file)
@@ -152,6 +152,7 @@ public interface LTTngSessiondCmd2_4 {
                 */
                public int enableLogger(LTTngLogHandler handler, LTTngEvent event,
                                HashMap enabledLoggers) {
+                       int ret;
                        Logger logger;
 
                        logger = handler.logManager.getLogger(event.name);
@@ -159,9 +160,12 @@ public interface LTTngSessiondCmd2_4 {
                                return 0;
                        }
 
-                       handler.setEvent(event);
-                       logger.addHandler(handler);
-                       enabledLoggers.put(event.name, logger);
+                       ret = handler.setEvent(event);
+                       if (ret == 0) {
+                               /* Newly created event, add the handler. */
+                               logger.addHandler(handler);
+                               enabledLoggers.put(event.name, logger);
+                       }
 
                        return 1;
                }
@@ -176,7 +180,7 @@ public interface LTTngSessiondCmd2_4 {
                public LTTngEvent execute(LTTngLogHandler handler, HashMap enabledLoggers) {
                        int ret;
                        Logger logger;
-                       LTTngEvent event;
+                       LTTngEvent event = null;
 
                        if (name == null) {
                                this.code = lttng_jul_ret_code.CODE_INVALID_CMD;
@@ -192,9 +196,11 @@ public interface LTTngSessiondCmd2_4 {
                                 * Keep the loglevel value for all events in case an event
                                 * appears later on.
                                 */
-                               handler.logLevelUseAll = 1;
-                               handler.logLevelAll = lttngLogLevel;
-                               handler.logLevelTypeAll = lttngLogLevelType;
+                               if (lttngLogLevel != -1) {
+                                       handler.logLevelUseAll = 1;
+                                       handler.logLevelsAll.add(new LTTngLogLevel(lttngLogLevel,
+                                                               lttngLogLevelType));
+                               }
 
                                while (loggers.hasMoreElements()) {
                                        loggerName = loggers.nextElement().toString();
@@ -203,22 +209,26 @@ public interface LTTngSessiondCmd2_4 {
                                                continue;
                                        }
 
-                                       if (enabledLoggers.get(loggerName) != null) {
-                                               continue;
-                                       }
-
                                        /*
                                         * Create new event object and set it in the log handler so
                                         * we can process the record entry with the right
                                         * attributes like the loglevels.
                                         */
-                                       event = new LTTngEvent(loggerName, lttngLogLevel,
-                                                       lttngLogLevelType);
+                                       event = new LTTngEvent(loggerName, 0, 0);
+                                       /* Clean up loglevel and merge the the ones from all events. */
+                                       event.logLevels.clear();
+                                       event.logLevels.addAll(handler.logLevelsAll);
                                        enableLogger(handler, event, enabledLoggers);
                                }
                                this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
 
-                               event = new LTTngEvent("*", lttngLogLevel, lttngLogLevelType);
+                               /*
+                                * Only return an event if this is a newly created event
+                                * meaning the loglevel is valid.
+                                */
+                               if (lttngLogLevel != -1) {
+                                       event = new LTTngEvent("*", lttngLogLevel, lttngLogLevelType);
+                               }
                                return event;
                        }
 
index 594e735a25309dea2ee21348e85204f71285561c..f3ac80dc6e78860ae8ae4fb72cfb182da65a445d 100644 (file)
@@ -133,8 +133,7 @@ public class LTTngTCPSessiondClient {
                                                 */
                                                if (handler.logLevelUseAll == 1) {
                                                        it.remove();
-                                                       event.logLevel.level = handler.logLevelAll;
-                                                       event.logLevel.type = handler.logLevelTypeAll;
+                                                       event.logLevels.addAll(handler.logLevelsAll);
                                                        modifiedEvents.add(event);
                                                }
 
@@ -144,8 +143,8 @@ public class LTTngTCPSessiondClient {
                                                 */
                                                if (event.name.equals("*")) {
                                                        enableCmd.name = event.name;
-                                                       enableCmd.lttngLogLevel = event.logLevel.level;
-                                                       enableCmd.lttngLogLevelType = event.logLevel.type;
+                                                       /* Tell the command NOT to add the loglevel. */
+                                                       enableCmd.lttngLogLevel = -1;
                                                        /*
                                                         * The return value is irrelevant since the * event is
                                                         * always kept in the set.
This page took 0.029412 seconds and 4 git commands to generate.