JUL: use root logger to capture events
[lttng-ust.git] / liblttng-ust-jul / org / lttng / ust / jul / LTTngLogHandler.java
index f61677d0b3b270e96a07fef07a817ef73f00c33c..4c617fb91918f0afe192b66836782bb2178b6d68 100644 (file)
@@ -22,33 +22,25 @@ import java.util.logging.Handler;
 import java.util.logging.LogRecord;
 import java.util.logging.LogManager;
 import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.lttng.ust.jul.LTTngUst;
 
-/* Note: This is taken from the LTTng tools ABI. */
-class LTTngLogLevelABI {
-       /* Loglevel type. */
-       public static final int LOGLEVEL_TYPE_ALL = 0;
-       public static final int LOGLEVEL_TYPE_RANGE = 1;
-       public static final int LOGLEVEL_TYPE_SINGLE = 2;
-}
-
 public class LTTngLogHandler extends Handler {
-       /*
-        * Indicate if the enable all event has been seen and if yes logger that we
-        * enabled should use the loglevel/type below.
-        */
-       public int logLevelUseAll = 0;
-       public int logLevelAll = 0;
-       public int logLevelTypeAll;
+       /* Am I a root Log Handler. */
+       public int is_root = 0;
+       public int refcount = 0;
 
        public LogManager logManager;
 
-       /* Indexed by name and corresponding LTTngEvent. */
-       private HashMap<String, LTTngEvent> eventMap =
-               new HashMap<String, LTTngEvent>();
+       /* Logger object attached to this handler that can trigger a tracepoint. */
+       public Map<String, LTTngEvent> enabledEvents =
+               Collections.synchronizedMap(new HashMap<String, LTTngEvent>());
 
+       /* Constructor */
        public LTTngLogHandler(LogManager logManager) {
                super();
 
@@ -58,8 +50,11 @@ public class LTTngLogHandler extends Handler {
                LTTngUst.init();
        }
 
-       public void setEvent(LTTngEvent event) {
-               eventMap.put(event.name, event);
+       /*
+        * Cleanup this handler state meaning put it back to a vanilla state.
+        */
+       public void clear() {
+               this.enabledEvents.clear();
        }
 
        @Override
@@ -70,50 +65,21 @@ public class LTTngLogHandler extends Handler {
 
        @Override
        public void publish(LogRecord record) {
-               int fire_tp = 0, rec_log_level, ev_type, ev_log_level;
-               LTTngEvent event;
-               LTTngLogLevel lttngLogLevel;
-               String logger_name = record.getLoggerName();
-
-               /* 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) {
-                                       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;
-                       }
-               } else {
-                       /* No loglevel attached thus fire tracepoint. */
-                       fire_tp = 1;
-               }
-
-               if (fire_tp == 0) {
-                       return;
-               }
-
                /*
                 * Specific tracepoing designed for JUL events. The source class of the
                 * caller is used for the event name, the raw message is taken, the
                 * loglevel of the record and the thread ID.
                 */
-               LTTngUst.tracepoint(record.getMessage(), record.getLoggerName(),
-                               record.getSourceClassName(), record.getSourceMethodName(),
-                               record.getMillis(), record.getLevel().intValue(),
-                               record.getThreadID());
+               if (this.is_root == 1) {
+                       LTTngUst.tracepointS(record.getMessage(),
+                                       record.getLoggerName(), record.getSourceClassName(),
+                                       record.getSourceMethodName(), record.getMillis(),
+                                       record.getLevel().intValue(), record.getThreadID());
+               } else {
+                       LTTngUst.tracepointU(record.getMessage(),
+                                       record.getLoggerName(), record.getSourceClassName(),
+                                       record.getSourceMethodName(), record.getMillis(),
+                                       record.getLevel().intValue(), record.getThreadID());
+               }
        }
 }
This page took 0.025749 seconds and 4 git commands to generate.