X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-jul%2Forg%2Flttng%2Fust%2Fjul%2FLTTngSessiondCmd2_4.java;h=9b544be55086f11441090cdeadae1ccb80251572;hb=3c3a0129d36e41b4c007ab008f603813efbb66ac;hp=eab7e5d9c1752dce3b35e36da48c7c67f07214af;hpb=529e6def5152664150912edbb3a01630f83b1ef2;p=lttng-ust.git 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 eab7e5d9..9b544be5 100644 --- a/liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java +++ b/liblttng-ust-jul/org/lttng/ust/jul/LTTngSessiondCmd2_4.java @@ -20,6 +20,7 @@ package org.lttng.ust.jul; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.lang.Object; import java.util.logging.Logger; import java.util.ArrayList; import java.util.HashMap; @@ -32,6 +33,12 @@ public interface LTTngSessiondCmd2_4 { */ final static int NAME_MAX = 255; + /* + * Size of a primitive type int in byte. Because you know, Java can't + * provide that since it does not makes sense... + */ + final static int INT_SIZE = 4; + public interface SessiondResponse { /** * Gets a byte array of the command so that it may be streamed @@ -57,7 +64,10 @@ public interface LTTngSessiondCmd2_4 { /** Enable logger by name. */ CMD_ENABLE(2), /** Disable logger by name. */ - CMD_DISABLE(3); + CMD_DISABLE(3), + /** Registration done */ + CMD_REG_DONE(4); + private int code; private lttng_jul_command(int c) { @@ -107,15 +117,21 @@ public interface LTTngSessiondCmd2_4 { public class sessiond_enable_handler implements SessiondResponse, SessiondCommand { private final static int SIZE = 4; public String name; + public int lttngLogLevel; + public int lttngLogLevelType; /** Return status code to the session daemon. */ public lttng_jul_ret_code code; @Override public void populate(byte[] data) { + int data_offset = INT_SIZE * 2; + ByteBuffer buf = ByteBuffer.wrap(data); buf.order(ByteOrder.LITTLE_ENDIAN); - name = new String(data, 0, data.length); + lttngLogLevel = buf.getInt(); + lttngLogLevelType = buf.getInt(); + name = new String(data, data_offset, data.length - data_offset); } @Override @@ -127,6 +143,33 @@ public interface LTTngSessiondCmd2_4 { 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) { + int ret; + Logger logger; + + logger = handler.logManager.getLogger(event.name); + if (logger == null) { + return 0; + } + + ret = handler.setEvent(event); + if (ret == 0) { + /* Newly created event, add the handler. */ + 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. @@ -134,8 +177,10 @@ 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, HashMap enabledLoggers) { + public LTTngEvent execute(LTTngLogHandler handler, HashMap enabledLoggers) { + int ret; Logger logger; + LTTngEvent event = null; if (name == null) { this.code = lttng_jul_ret_code.CODE_INVALID_CMD; @@ -146,6 +191,17 @@ public interface LTTngSessiondCmd2_4 { 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. + */ + if (lttngLogLevel != -1) { + handler.logLevelUseAll = 1; + handler.logLevelsAll.add(new LTTngLogLevel(lttngLogLevel, + lttngLogLevelType)); + } + while (loggers.hasMoreElements()) { loggerName = loggers.nextElement().toString(); /* Somehow there is always an empty string at the end. */ @@ -153,32 +209,43 @@ public interface LTTngSessiondCmd2_4 { continue; } - if (enabledLoggers.get(loggerName) != null) { - continue; - } - - logger = handler.logManager.getLogger(loggerName); - logger.addHandler(handler); - enabledLoggers.put(loggerName, 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(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; + /* - * 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. + * Only return an event if this is a newly created event + * meaning the loglevel is valid. */ - return new String(name); + if (lttngLogLevel != -1) { + 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) { - 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; } }