package org.lttng.ust.jul;
+import java.util.ArrayList;
import java.lang.String;
import org.lttng.ust.jul.LTTngUst;
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;
}
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);
}
}
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;
* 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;
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
/* 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. */
*/
public int enableLogger(LTTngLogHandler handler, LTTngEvent event,
HashMap enabledLoggers) {
+ int ret;
Logger logger;
logger = handler.logManager.getLogger(event.name);
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;
}
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;
* 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();
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;
}
*/
if (handler.logLevelUseAll == 1) {
it.remove();
- event.logLevel.level = handler.logLevelAll;
- event.logLevel.type = handler.logLevelTypeAll;
+ event.logLevels.addAll(handler.logLevelsAll);
modifiedEvents.add(event);
}
*/
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.