<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
- <Lttng name="Lttng" domain="LOG4J">
+ <Lttng name="Lttng1" domain="LOG4J">
+ <Lttng name="Lttng2" domain="LOG4J2">
</Lttng>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
- <AppenderRef ref="Lttng"/>
+ <AppenderRef ref="Lttng1"/>
+ <AppenderRef ref="Lttng2"/>
</Root>
</Loggers>
</Configuration>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
- <Lttng name="Lttng" domain="LOG4J">
+ <Lttng name="Lttng1" domain="LOG4J">
+ <Lttng name="Lttng2" domain="LOG4J2">
</Lttng>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
- <AppenderRef ref="Lttng"/>
+ <AppenderRef ref="Lttng1"/>
+ <AppenderRef ref="Lttng2"/>
</Root>
</Loggers>
</Configuration>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
- <Lttng name="Lttng" domain="LOG4J">
+ <Lttng name="Lttng1" domain="LOG4J">
+ <Lttng name="Lttng2" domain="LOG4J2">
</Lttng>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
- <AppenderRef ref="Lttng"/>
+ <AppenderRef ref="Lttng1"/>
+ <AppenderRef ref="Lttng2"/>
</Root>
</Loggers>
</Configuration>
appenderBuilder.add(standardLayout);
builder.add(appenderBuilder);
- /* Create an Lttng appender */
+ /* Create an Lttng appender for the LOG4J domain */
appenderBuilder = builder.newAppender("Lttng1", "Lttng");
appenderBuilder.addAttribute("domain", "LOG4J");
builder.add(appenderBuilder);
+ /* Create an Lttng appender for the LOG4J2 domain */
+ appenderBuilder = builder.newAppender("Lttng2", "Lttng");
+ appenderBuilder.addAttribute("domain", "LOG4J2");
+ builder.add(appenderBuilder);
+
/* Create a root logger with both appenders attached */
RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.DEBUG);
rootLogger.add(builder.newAppenderRef("Stdout"));
rootLogger.add(builder.newAppenderRef("Lttng1"));
+ rootLogger.add(builder.newAppenderRef("Lttng2"));
builder.add(rootLogger);
Configurator.initialize(builder.build());
* Tracing domains. Corresponds to domains defined by LTTng Tools.
*/
enum Domain {
- JUL(3), LOG4J(4);
+ JUL(3), LOG4J(4), LOG4J2(6);
private int value;
private Domain(int value) {
*/
class LttngLog4j2Agent extends AbstractLttngAgent<LttngLogAppender> {
- private static LttngLog4j2Agent instance = null;
+ private static LttngLog4j2Agent log4j2_instance = null;
+ private static LttngLog4j2Agent log4j1_instance = null;
- private LttngLog4j2Agent() {
- super(Domain.LOG4J);
+ private LttngLog4j2Agent(Domain domain) {
+ super(domain);
}
- public static synchronized LttngLog4j2Agent getInstance() {
- if (instance == null) {
- instance = new LttngLog4j2Agent();
+ public static synchronized LttngLog4j2Agent getLog4j1Instance() {
+ if (log4j1_instance == null) {
+ log4j1_instance = new LttngLog4j2Agent(Domain.LOG4J);
}
- return instance;
+ return log4j1_instance;
+ }
+
+ public static synchronized LttngLog4j2Agent getLog4j2Instance() {
+ if (log4j2_instance == null) {
+ log4j2_instance = new LttngLog4j2Agent(Domain.LOG4J2);
+ }
+ return log4j2_instance;
}
@Override
static native void tracepointWithContext(String message, String loggerName, String className, String methodName,
String fileName, int lineNumber, long timeStamp, int logLevel, String threadName, byte[] contextEntries,
- byte[] contextStrings);
-}
+ byte[] contextStrings, boolean log4j1Compat);
+}
\ No newline at end of file
/* Register to the relevant agent. */
if (domain == LttngLog4j2Agent.Domain.LOG4J) {
- agent = LttngLog4j2Agent.getInstance();
+ agent = LttngLog4j2Agent.getLog4j1Instance();
+ } else if (domain == LttngLog4j2Agent.Domain.LOG4J2) {
+ agent = LttngLog4j2Agent.getLog4j2Instance();
} else {
throw new IllegalArgumentException("Unsupported domain '" + domain + "'");
}
LttngLog4j2Api.tracepointWithContext(message, loggername, classname, methodname, filename, line,
event.getTimeMillis(), event.getLevel().intLevel(), event.getThreadName(),
- contextInfo.getEntriesArray(), contextInfo.getStringsArray());
+ contextInfo.getEntriesArray(), contextInfo.getStringsArray(), agent.getDomain() == Domain.LOG4J);
}
}
lib_LTLIBRARIES = liblttng-ust-log4j-jni.la
liblttng_ust_log4j_jni_la_SOURCES = \
+ lttng_ust_log4j2_tp.c \
+ lttng_ust_log4j2_tp.h \
lttng_ust_log4j_tp.c \
lttng_ust_log4j_tp.h
nodist_liblttng_ust_log4j_jni_la_SOURCES =
#define _LGPL_SOURCE
#include "org_lttng_ust_agent_log4j2_LttngLog4j2Api.h"
#include "lttng_ust_log4j_tp.h"
+#include "lttng_ust_log4j2_tp.h"
#include "../common/lttng_ust_context.h"
/*
jint logLevel,
jstring threadName,
jbyteArray context_info_entries,
- jbyteArray context_info_strings)
+ jbyteArray context_info_strings,
+ jboolean log4j1Compat)
{
jboolean iscopy;
const char *msg_cstr = (*env)->GetStringUTFChars(env, message, &iscopy);
lttng_ust_context_info_tls.ctx_strings = context_info_strings_array;
lttng_ust_context_info_tls.ctx_strings_len = (*env)->GetArrayLength(env, context_info_strings);
- lttng_ust_tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
- class_name_cstr, method_name_cstr, file_name_cstr,
- lineNumber, timeStamp, loglevel_2x_to_1x(logLevel), thread_name_cstr);
+ if (log4j1Compat) {
+ /*
+ * Log4j 1.x compatible tracepoint with loglevel conversion.
+ */
+ lttng_ust_tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
+ class_name_cstr, method_name_cstr, file_name_cstr,
+ lineNumber, timeStamp, loglevel_2x_to_1x(logLevel), thread_name_cstr);
+ } else {
+ /*
+ * Log4j 2.x tracepoint with native loglevel.
+ */
+ lttng_ust_tracepoint(lttng_log4j2, event, msg_cstr, logger_name_cstr,
+ class_name_cstr, method_name_cstr, file_name_cstr,
+ lineNumber, timeStamp, logLevel, thread_name_cstr);
+ }
lttng_ust_context_info_tls.ctx_entries = NULL;
lttng_ust_context_info_tls.ctx_entries_len = 0;
--- /dev/null
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2022 EfficiOS Inc.
+ */
+
+#define _LGPL_SOURCE
+
+#define LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION
+#define LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION
+
+#define LTTNG_UST_TRACEPOINT_DEFINE
+#define LTTNG_UST_TRACEPOINT_CREATE_PROBES
+#include "lttng_ust_log4j2_tp.h"
--- /dev/null
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2022 EfficiOS Inc.
+ */
+
+#undef LTTNG_UST_TRACEPOINT_PROVIDER
+#define LTTNG_UST_TRACEPOINT_PROVIDER lttng_log4j2
+
+#if !defined(_TRACEPOINT_LTTNG_UST_LOG4J2_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_LTTNG_UST_LOG4J2_H
+
+#include <lttng/tracepoint.h>
+
+/*
+ * Tracepoint used by Java applications using the log4j 2.x convention for loglevels.
+ */
+LTTNG_UST_TRACEPOINT_EVENT(lttng_log4j2, event,
+ LTTNG_UST_TP_ARGS(
+ const char *, msg,
+ const char *, logger_name,
+ const char *, class_name,
+ const char *, method_name,
+ const char *, file_name,
+ int, line_number,
+ long, timestamp,
+ int, log_level,
+ const char *, thread_name),
+ LTTNG_UST_TP_FIELDS(
+ lttng_ust_field_string(msg, msg)
+ lttng_ust_field_string(logger_name, logger_name)
+ lttng_ust_field_string(class_name, class_name)
+ lttng_ust_field_string(method_name, method_name)
+ lttng_ust_field_string(filename, file_name)
+ lttng_ust_field_integer(int, line_number, line_number)
+ lttng_ust_field_integer(long, timestamp, timestamp)
+ lttng_ust_field_integer(int, int_loglevel, log_level)
+ lttng_ust_field_string(thread_name, thread_name)
+ )
+)
+
+#endif /* _TRACEPOINT_LTTNG_UST_LOG4J2_H */
+
+#undef LTTNG_UST_TRACEPOINT_INCLUDE
+#define LTTNG_UST_TRACEPOINT_INCLUDE "./lttng_ust_log4j2_tp.h"
+
+/* This part must be outside protection */
+#include <lttng/tracepoint-event.h>
#include <lttng/tracepoint.h>
/*
- * Tracepoint used by Java applications using the log4j log appender.
+ * Tracepoint used by Java applications using the log4j 1.x convention for loglevels.
*/
LTTNG_UST_TRACEPOINT_EVENT(lttng_log4j, event,
LTTNG_UST_TP_ARGS(