nodist_liblttng_ust_jul_jni_la_SOURCES = org_lttng_ust_jul_LTTngUst.h
dist_noinst_DATA = $(LTTNG_JUL_SRCDIR)/LTTngUst.java \
$(LTTNG_JUL_SRCDIR)/LTTngAgent.java \
+ $(LTTNG_JUL_SRCDIR)/LTTngEvent.java \
$(LTTNG_JUL_SRCDIR)/LTTngLogHandler.java \
$(LTTNG_JUL_SRCDIR)/LTTngSessiondCmd2_4.java \
$(LTTNG_JUL_SRCDIR)/LTTngTCPSessiondClient.java \
LTTNG_AGENT_FILES = $(LTTNG_JUL_SRCDIR)/LTTngAgent.java \
$(LTTNG_JUL_SRCDIR)/LTTngLogHandler.java \
+ $(LTTNG_JUL_SRCDIR)/LTTngEvent.java \
$(LTTNG_JUL_SRCDIR)/LTTngSessiondCmd2_4.java \
$(LTTNG_JUL_SRCDIR)/LTTngTCPSessiondClient.java \
$(LTTNG_JUL_SRCDIR)/LTTngThread.java
--- /dev/null
+/*
+ * Copyright (C) 2014 - David Goulet <dgoulet@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.lttng.ust.jul;
+
+import java.lang.String;
+
+import org.lttng.ust.jul.LTTngUst;
+
+class LTTngLogLevel {
+ /* This level is a JUL int level value. */
+ public int level;
+ public int type;
+
+ public LTTngLogLevel(String event_name, int level, int type) {
+ this.type = type;
+ this.level = level;
+ }
+}
+
+public class LTTngEvent {
+ /* Name of the event. */
+ public String name;
+ public LTTngLogLevel logLevel;
+
+ public LTTngEvent(String name, int loglevel, int loglevel_type) {
+ this.name = name;
+ this.logLevel = new LTTngLogLevel(name, loglevel, loglevel_type);
+ }
+}
public static final int LOGLEVEL_TYPE_SINGLE = 2;
}
-class LTTngLogLevel {
- /* Event name on which this loglevel is applied on. */
- private String event_name;
- /* This level is a JUL int level value. */
- private int level;
- private int type;
-
- public LTTngLogLevel(String event_name, int level, int type) {
- this.event_name = event_name;
- this.type = type;
- this.level = level;
- }
-
- public String getName() {
- return this.event_name;
- }
-
- public int getLevel() {
- return this.level;
- }
-
- public int getType() {
- return this.type;
- }
-}
-
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;
+
public LogManager logManager;
- private HashMap<String, LTTngLogLevel> logLevels =
- new HashMap<String, LTTngLogLevel>();
+ /* Indexed by name and corresponding LTTngEvent. */
+ private HashMap<String, LTTngEvent> eventMap =
+ new HashMap<String, LTTngEvent>();
public LTTngLogHandler(LogManager logManager) {
super();
LTTngUst.init();
}
- public void setLogLevel(String event_name, int level, int type) {
- LTTngLogLevel lttngLogLevel = new LTTngLogLevel(event_name, level,
- type);
- logLevels.put(event_name, lttngLogLevel);
+ public void setEvent(LTTngEvent event) {
+ eventMap.put(event.name, event);
}
@Override
@Override
public void publish(LogRecord record) {
int fire_tp = 0, rec_log_level, ev_type, ev_log_level;
+ LTTngEvent event;
LTTngLogLevel lttngLogLevel;
- String event_name = record.getLoggerName();
+ String logger_name = record.getLoggerName();
- lttngLogLevel = logLevels.get(event_name);
- if (lttngLogLevel != null) {
+ /* 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 = lttngLogLevel.getLevel();
- ev_type = lttngLogLevel.getType();
+ ev_log_level = event.logLevel.level;
+ ev_type = event.logLevel.type;
switch (ev_type) {
case LTTngLogLevelABI.LOGLEVEL_TYPE_RANGE:
return data;
}
+ /*
+ * Enable a logger meaning add our handler to it using an exiting
+ * event. If successful, the logger is added to the given enabled
+ * Loggers hashmap.
+ *
+ * @return 0 if NO logger is found else 1 if added.
+ */
+ public int enableLogger(LTTngLogHandler handler, LTTngEvent event,
+ HashMap enabledLoggers) {
+ Logger logger;
+
+ logger = handler.logManager.getLogger(event.name);
+ if (logger == null) {
+ return 0;
+ }
+
+ handler.setEvent(event);
+ logger.addHandler(handler);
+ enabledLoggers.put(event.name, logger);
+
+ return 1;
+ }
+
/**
* Execute enable handler action which is to enable the given handler
* to the received name.
* @return Event name as a string if the event is NOT found thus was
* not enabled.
*/
- public String execute(LTTngLogHandler handler, HashMap enabledLoggers) {
+ public LTTngEvent execute(LTTngLogHandler handler, HashMap enabledLoggers) {
+ int ret;
Logger logger;
+ LTTngEvent event;
if (name == null) {
this.code = lttng_jul_ret_code.CODE_INVALID_CMD;
if (name.trim().equals("*")) {
String loggerName;
Enumeration loggers = handler.logManager.getLoggerNames();
+
+ /*
+ * Keep the loglevel value for all events in case an event
+ * appears later on.
+ */
+ handler.logLevelUseAll = 1;
+ handler.logLevelAll = lttngLogLevel;
+ handler.logLevelTypeAll = lttngLogLevelType;
+
while (loggers.hasMoreElements()) {
loggerName = loggers.nextElement().toString();
/* Somehow there is always an empty string at the end. */
continue;
}
- logger = handler.logManager.getLogger(loggerName);
- handler.setLogLevel(loggerName, lttngLogLevel,
+ /*
+ * 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);
- logger.addHandler(handler);
- enabledLoggers.put(loggerName, logger);
+ enableLogger(handler, event, enabledLoggers);
}
this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
- /*
- * 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);
+
+ event = new LTTngEvent("*", lttngLogLevel, lttngLogLevelType);
+ return event;
}
this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
- logger = handler.logManager.getLogger(name.trim());
- if (logger != null) {
- handler.setLogLevel(name.trim(), lttngLogLevel,
- lttngLogLevelType);
- logger.addHandler(handler);
- enabledLoggers.put(name.trim(), logger);
+
+ /*
+ * 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(name.trim(), lttngLogLevel,
+ lttngLogLevelType);
+ ret = enableLogger(handler, event, enabledLoggers);
+ if (ret == 1) {
return null;
- } else {
- return new String(name);
}
+ return event;
}
}
private Semaphore registerSem;
private Timer eventTimer;
- private List<String> enabledEventList = new ArrayList<String>();
+ private List<LTTngEvent> enabledEventList = new ArrayList<LTTngEvent>();
/*
* Map of Logger objects that have been enabled. They are indexed by name.
*/
* We have to make a copy here since it is possible that the
* enabled event list is changed during an iteration on it.
*/
- List<String> tmpList = new ArrayList<String>(enabledEventList);
+ List<LTTngEvent> tmpList = new ArrayList<LTTngEvent>(enabledEventList);
LTTngSessiondCmd2_4.sessiond_enable_handler enableCmd = new
LTTngSessiondCmd2_4.sessiond_enable_handler();
- for (String strEventName: tmpList) {
+ for (LTTngEvent event: tmpList) {
+ int ret;
+ Logger logger;
+
/*
* Check if this Logger name has been enabled already. Note
* that in the case of "*", it's never added in that hash
* LogHandler can be added twice on a Logger object...
* don't ask...
*/
- if (enabledLoggers.get(strEventName) != null) {
+ logger = enabledLoggers.get(event.name);
+ if (logger != null) {
+ continue;
+ }
+
+ /*
+ * Set to one means that the enable all event has been seen
+ * thus event from that point on must use loglevel for all
+ * events. Else the object has its own loglevel.
+ */
+ if (handler.logLevelUseAll == 1) {
+ event.logLevel.level = handler.logLevelAll;
+ event.logLevel.type = handler.logLevelTypeAll;
+ }
+
+ /*
+ * The all event is a special case since we have to iterate
+ * over every Logger to see which one was not enabled.
+ */
+ if (event.name.equals("*")) {
+ enableCmd.name = event.name;
+ enableCmd.lttngLogLevel = event.logLevel.level;
+ enableCmd.lttngLogLevelType = event.logLevel.type;
+ /*
+ * The return value is irrelevant since the * event is
+ * always kept in the list.
+ */
+ enableCmd.execute(handler, enabledLoggers);
continue;
}
- enableCmd.name = strEventName;
- if (enableCmd.execute(handler, enabledLoggers) == null) {
- enabledEventList.remove(strEventName);
+ ret = enableCmd.enableLogger(handler, event, enabledLoggers);
+ if (ret == 1) {
+ /* Enabled so remove the event from the list. */
+ enabledEventList.remove(event);
}
}
}
}
case CMD_ENABLE:
{
- String event_name;
+ LTTngEvent event;
LTTngSessiondCmd2_4.sessiond_enable_handler enableCmd =
new LTTngSessiondCmd2_4.sessiond_enable_handler();
if (data == null) {
break;
}
enableCmd.populate(data);
- event_name = enableCmd.execute(this.handler, this.enabledLoggers);
- if (event_name != null) {
+ event = enableCmd.execute(this.handler, this.enabledLoggers);
+ if (event != null) {
/*
* Add the event to the list so it can be enabled if
* the logger appears at some point in time.
*/
- if (enabledEventList.contains(event_name) == false) {
- enabledEventList.add(event_name);
+ if (enabledEventList.contains(event) == false) {
+ enabledEventList.add(event);
}
}
data = enableCmd.getBytes();