Fix: Correctly report filter notifications on Java agent teardown
[lttng-ust.git] / liblttng-ust-java-agent / jni / log4j / lttng_ust_log4j.c
CommitLineData
43e5396b 1/*
8ab5c06b 2 * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
43e5396b
DG
3 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; only
8 * version 2.1 of the License.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
6e7bc9e0 20#include "org_lttng_ust_agent_log4j_LttngLog4jApi.h"
43e5396b
DG
21
22#define TRACEPOINT_DEFINE
23#define TRACEPOINT_CREATE_PROBES
501f6777 24#include "lttng_ust_log4j.h"
8ab5c06b 25#include "../common/lttng_ust_context.h"
43e5396b 26
9aabed2d 27/*
8ab5c06b 28 * Deprecated function from before the context information was passed.
9aabed2d 29 */
6e7bc9e0 30JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepoint(JNIEnv *env,
43e5396b
DG
31 jobject jobj,
32 jstring msg,
33 jstring logger_name,
34 jstring class_name,
35 jstring method_name,
501f6777
CB
36 jstring file_name,
37 jint line_number,
38 jlong timestamp,
39 jint loglevel,
40 jstring thread_name)
43e5396b
DG
41{
42 jboolean iscopy;
43 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
44 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
45 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
46 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
501f6777
CB
47 const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
48 const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
43e5396b 49
8286ff50 50 tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
501f6777
CB
51 class_name_cstr, method_name_cstr, file_name_cstr,
52 line_number, timestamp, loglevel, thread_name_cstr);
9aabed2d
DG
53
54 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
55 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
56 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
57 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
501f6777
CB
58 (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
59 (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
9aabed2d
DG
60}
61
8ab5c06b
AM
62/*
63 * Tracepoint used by Java applications using the log4j handler.
64 */
65JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepointWithContext(JNIEnv *env,
66 jobject jobj,
67 jstring msg,
68 jstring logger_name,
69 jstring class_name,
70 jstring method_name,
71 jstring file_name,
72 jint line_number,
73 jlong timestamp,
74 jint loglevel,
75 jstring thread_name,
76 jbyteArray context_info)
77{
78 jboolean iscopy;
79 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
80 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
81 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
82 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
83 const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
84 const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
85 signed char *context_info_array;
86
87 /*
88 * Write these to the TLS variables, so that the UST callbacks in
89 * lttng_ust_context.c can access them.
90 */
91 context_info_array = (*env)->GetByteArrayElements(env, context_info, &iscopy);
92 lttng_ust_context_info_tls.ctx = (struct lttng_ust_jni_ctx *) context_info_array;
93 lttng_ust_context_info_tls.len = (*env)->GetArrayLength(env, context_info);
94
95 tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
96 class_name_cstr, method_name_cstr, file_name_cstr,
97 line_number, timestamp, loglevel, thread_name_cstr);
98
99 lttng_ust_context_info_tls.ctx = NULL;
100 lttng_ust_context_info_tls.len = 0;
101 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
102 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
103 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
104 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
105 (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
106 (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
107 (*env)->ReleaseByteArrayElements(env, context_info, context_info_array, 0);
108}
This page took 0.027584 seconds and 4 git commands to generate.