Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / jni / log4j / lttng_ust_log4j.c
index c887f7f414e5602f0e72be0f543a261aeb4c838b..ff7395c8ce8db8f4102fbdcc15cfc9c5057960fc 100644 (file)
@@ -1,31 +1,23 @@
 /*
- * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@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 as published by the Free Software Foundation; only
- * version 2.1 of the License.
- *
- * 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.
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * 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
+ * Copyright (C) 2016 EfficiOS Inc.
+ * Copyright (C) 2016 Alexandre Montplaisir <alexmonthy@efficios.com>
+ * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  */
 
-#include "org_lttng_ust_agent_log4j_LTTngLogAppender.h"
+#define _LGPL_SOURCE
+#include "org_lttng_ust_agent_log4j_LttngLog4jApi.h"
 
 #define TRACEPOINT_DEFINE
 #define TRACEPOINT_CREATE_PROBES
 #include "lttng_ust_log4j.h"
+#include "../common/lttng_ust_context.h"
 
 /*
- * System tracepoint meaning only root agent will fire this.
+ * Deprecated function from before the context information was passed.
  */
-JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LTTngLogAppender_tracepointS(JNIEnv *env,
+JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepoint(JNIEnv *env,
                                                jobject jobj,
                                                jstring msg,
                                                jstring logger_name,
@@ -45,7 +37,7 @@ JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LTTngLogAppender_tracepoin
        const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
        const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
 
-       tracepoint(lttng_log4j, sys_event, msg_cstr, logger_name_cstr,
+       tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
                   class_name_cstr, method_name_cstr, file_name_cstr,
                   line_number, timestamp, loglevel, thread_name_cstr);
 
@@ -58,9 +50,9 @@ JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LTTngLogAppender_tracepoin
 }
 
 /*
- * User tracepoint meaning only a non root agent will fire this.
+ * Tracepoint used by Java applications using the log4j handler.
  */
-JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LTTngLogAppender_tracepointU(JNIEnv *env,
+JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepointWithContext(JNIEnv *env,
                                                jobject jobj,
                                                jstring msg,
                                                jstring logger_name,
@@ -70,7 +62,9 @@ JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LTTngLogAppender_tracepoin
                                                jint line_number,
                                                jlong timestamp,
                                                jint loglevel,
-                                               jstring thread_name)
+                                               jstring thread_name,
+                                               jbyteArray context_info_entries,
+                                               jbyteArray context_info_strings)
 {
        jboolean iscopy;
        const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
@@ -79,15 +73,34 @@ JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LTTngLogAppender_tracepoin
        const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
        const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
        const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
+       signed char *context_info_entries_array;
+       signed char *context_info_strings_array;
+
+       /*
+        * Write these to the TLS variables, so that the UST callbacks in
+        * lttng_ust_context.c can access them.
+        */
+       context_info_entries_array = (*env)->GetByteArrayElements(env, context_info_entries, &iscopy);
+       lttng_ust_context_info_tls.ctx_entries = (struct lttng_ust_jni_ctx_entry *) context_info_entries_array;
+       lttng_ust_context_info_tls.ctx_entries_len = (*env)->GetArrayLength(env, context_info_entries);
+       context_info_strings_array = (*env)->GetByteArrayElements(env, context_info_strings, &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);
 
-       tracepoint(lttng_log4j, user_event, msg_cstr, logger_name_cstr,
+       tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
                   class_name_cstr, method_name_cstr, file_name_cstr,
                   line_number, timestamp, loglevel, thread_name_cstr);
 
+       lttng_ust_context_info_tls.ctx_entries = NULL;
+       lttng_ust_context_info_tls.ctx_entries_len = 0;
+       lttng_ust_context_info_tls.ctx_strings = NULL;
+       lttng_ust_context_info_tls.ctx_strings_len = 0;
        (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
        (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
        (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
        (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
        (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
        (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
+       (*env)->ReleaseByteArrayElements(env, context_info_entries, context_info_entries_array, 0);
+       (*env)->ReleaseByteArrayElements(env, context_info_strings, context_info_strings_array, 0);
 }
This page took 0.0245840000000001 seconds and 4 git commands to generate.