From: David Goulet Date: Wed, 20 Nov 2013 16:35:35 +0000 (-0500) Subject: JUL: fix enable all event for delayed Logger X-Git-Tag: v2.4.0-rc2~19 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=529e6def5152664150912edbb3a01630f83b1ef2;p=lttng-ust.git JUL: fix enable all event for delayed Logger This adds a HashMap containing the enabled Logger names (and wildcard '*'). This is used to make sure we don't enable twice the same Logger for the '*' event name (enable all -a). Signed-off-by: David Goulet Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java b/liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java index 4b893e0b..eab7e5d9 100644 --- a/liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java +++ b/liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java @@ -22,6 +22,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.logging.Logger; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Enumeration; @@ -133,7 +134,7 @@ public interface LTTngSessiondCmd2_4 { * @return Event name as a string if the event is NOT found thus was * not enabled. */ - public String execute(LTTngLogHandler handler) { + public String execute(LTTngLogHandler handler, HashMap enabledLoggers) { Logger logger; if (name == null) { @@ -152,17 +153,28 @@ public interface LTTngSessiondCmd2_4 { continue; } + if (enabledLoggers.get(loggerName) != null) { + continue; + } + logger = handler.logManager.getLogger(loggerName); logger.addHandler(handler); + enabledLoggers.put(loggerName, logger); } this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD; - return null; + /* + * Return the name as a new string so we can add the * event + * name to the event list that we need to enable for new + * Logger. + */ + return new String(name); } this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD; logger = handler.logManager.getLogger(name.trim()); if (logger != null) { logger.addHandler(handler); + enabledLoggers.put(name.trim(), logger); return null; } else { return new String(name); diff --git a/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java b/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java index b89deb81..0c2cb48f 100644 --- a/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java +++ b/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java @@ -29,9 +29,11 @@ import java.io.DataInputStream; import java.net.*; import java.lang.management.ManagementFactory; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Timer; import java.util.TimerTask; +import java.util.logging.Logger; class USTRegisterMsg { public static int pid; @@ -56,6 +58,10 @@ public class LTTngTCPSessiondClient { private Timer eventTimer; private List enabledEventList = new ArrayList(); + /* + * Map of Logger objects that have been enabled. They are indexed by name. + */ + private HashMap enabledLoggers = new HashMap(); /* Timer delay at each 5 seconds. */ private final static long timerDelay = 5 * 1000; private static boolean timerInitialized; @@ -85,8 +91,22 @@ public class LTTngTCPSessiondClient { LTTngSessiondCmd2_4.sessiond_enable_handler enableCmd = new LTTngSessiondCmd2_4.sessiond_enable_handler(); for (String strEventName: tmpList) { + /* + * Check if this Logger name has been enabled already. Note + * that in the case of "*", it's never added in that hash + * table thus the enable command does a lookup for each + * logger name in that hash table for the * case in order + * to make sure we don't enable twice the same logger + * because JUL apparently accepts that the *same* + * LogHandler can be added twice on a Logger object... + * don't ask... + */ + if (enabledLoggers.get(strEventName) != null) { + continue; + } + enableCmd.name = strEventName; - if (enableCmd.execute(handler) == null) { + if (enableCmd.execute(handler, enabledLoggers) == null) { enabledEventList.remove(strEventName); } } @@ -220,13 +240,15 @@ public class LTTngTCPSessiondClient { break; } enableCmd.populate(data); - event_name = enableCmd.execute(this.handler); + event_name = enableCmd.execute(this.handler, this.enabledLoggers); if (event_name != null) { /* * Add the event to the list so it can be enabled if * the logger appears at some point in time. */ - enabledEventList.add(event_name); + if (enabledEventList.contains(event_name) == false) { + enabledEventList.add(event_name); + } } data = enableCmd.getBytes(); break;