$(pkgpath)/filter/FilterChangeNotifier.java \
$(pkgpath)/filter/IFilterChangeListener.java \
$(pkgpath)/session/EventRule.java \
- $(pkgpath)/session/LogLevelSelector.java
+ $(pkgpath)/session/LogLevelSelector.java \
+ $(pkgpath)/utils/LttngUstAgentLogger.java
dist_noinst_DATA = $(jarfile_manifest)
$(pkgpath)/client/*.class \
$(pkgpath)/context/*.class \
$(pkgpath)/filter/*.class \
- $(pkgpath)/session/*.class
+ $(pkgpath)/session/*.class \
+ $(pkgpath)/utils/*.class
$(jarfile): classnoinst.stamp
$(JAR) cfm $(JARFLAGS) $@ $(jarfile_manifest) $(classes) && rm -f $(jarfile_symlink) && $(LN_S) $@ $(jarfile_symlink)
$(pkgpath)/context/*.class \
$(pkgpath)/filter/*.class \
$(pkgpath)/session/*.class \
+ $(pkgpath)/utils/*.class \
$(juljniout)/org_lttng_ust_agent_context_LttngContextApi.h
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import org.lttng.ust.agent.utils.LttngUstAgentLogger;
+
/**
* Client for agents to connect to a local session daemon, using a TCP socket.
*
/*
* Connect to the session daemon before anything else.
*/
+ LttngUstAgentLogger.log(getClass(), "Connecting to sessiond");
connectToSessiond();
/*
* Register to the session daemon as the Java component of the
* UST application.
*/
+ LttngUstAgentLogger.log(getClass(), "Registering to sessiond");
registerToSessiond();
/*
* session daemon. This will return if and only if there is a
* fatal error or the socket closes.
*/
+ LttngUstAgentLogger.log(getClass(), "Waiting on sessiond commands...");
handleSessiondCmd();
} catch (UnknownHostException uhe) {
uhe.printStackTrace();
* Dispose this client and close any socket connection it may hold.
*/
public void close() {
+ LttngUstAgentLogger.log(getClass(), "Closing client");
this.quit = true;
try {
* We don't send any reply to the registration done command.
* This just marks the end of the initial session setup.
*/
+ LttngUstAgentLogger.log(getClass(), "Registration done");
continue;
}
case CMD_LIST:
SessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
LttngAgentResponse response = listLoggerCmd.execute(logAgent);
responseData = response.getBytes();
+ LttngUstAgentLogger.log(getClass(), "Received list loggers command");
break;
}
case CMD_EVENT_ENABLE:
SessiondCommand enableEventCmd = new SessiondEnableEventCommand(inputData);
LttngAgentResponse response = enableEventCmd.execute(logAgent);
responseData = response.getBytes();
+ LttngUstAgentLogger.log(getClass(), "Received enable event command");
break;
}
case CMD_EVENT_DISABLE:
SessiondCommand disableEventCmd = new SessiondDisableEventCommand(inputData);
LttngAgentResponse response = disableEventCmd.execute(logAgent);
responseData = response.getBytes();
+ LttngUstAgentLogger.log(getClass(), "Received disable event command");
break;
}
case CMD_APP_CTX_ENABLE:
SessiondCommand enableAppCtxCmd = new SessiondEnableAppContextCommand(inputData);
LttngAgentResponse response = enableAppCtxCmd.execute(logAgent);
responseData = response.getBytes();
+ LttngUstAgentLogger.log(getClass(), "Received enable app-context command");
break;
}
case CMD_APP_CTX_DISABLE:
SessiondCommand disableAppCtxCmd = new SessiondDisableAppContextCommand(inputData);
LttngAgentResponse response = disableAppCtxCmd.execute(logAgent);
responseData = response.getBytes();
+ LttngUstAgentLogger.log(getClass(), "Received disable app-context command");
break;
}
default:
responseData = new byte[4];
ByteBuffer buf = ByteBuffer.wrap(responseData);
buf.order(ByteOrder.BIG_ENDIAN);
+ LttngUstAgentLogger.log(getClass(), "Received unknown command, ignoring");
break;
}
}
/* Send response to the session daemon. */
+ LttngUstAgentLogger.log(getClass(), "Sending response");
this.outToSessiond.write(responseData, 0, responseData.length);
this.outToSessiond.flush();
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@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.agent.utils;
+
+/**
+ * Logging infrastructure for the lttng-ust Java agent. It prints log messages
+ * to stderr but only when the environment variable LTTNG_UST_DEBUG is defined.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstAgentLogger {
+
+ private static final String ENV_VAR_NAME = "LTTNG_UST_DEBUG";
+ private static final boolean LOGGING_ENABLED = (System.getenv(ENV_VAR_NAME) == null ? false : true);
+
+ /**
+ * Log event. Will be printed to stderr if the environment variable
+ * "LTTNG_UST_DEBUG" is defined.
+ *
+ * @param c
+ * The class logging the message (should normally be called with
+ * {@link #getClass()}).
+ * @param message
+ * The message to print
+ */
+ public static void log(Class<?> c, String message) {
+ if (LOGGING_ENABLED) {
+ System.err.println(c.getSimpleName() + ": " + message);
+ }
+ }
+}