72eca1d4a7c71be6fb3744d969d74b6352ee9766
[lttng-ust.git] / liblttng-ust-java-agent / jni / log4j / lttng_ust_log4j.c
1 /*
2 * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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
20 #define _LGPL_SOURCE
21 #include "org_lttng_ust_agent_log4j_LttngLog4jApi.h"
22
23 #define TRACEPOINT_DEFINE
24 #define TRACEPOINT_CREATE_PROBES
25 #include "lttng_ust_log4j.h"
26 #include "../common/lttng_ust_context.h"
27
28 /*
29 * Deprecated function from before the context information was passed.
30 */
31 JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepoint(JNIEnv *env,
32 jobject jobj,
33 jstring msg,
34 jstring logger_name,
35 jstring class_name,
36 jstring method_name,
37 jstring file_name,
38 jint line_number,
39 jlong timestamp,
40 jint loglevel,
41 jstring thread_name)
42 {
43 jboolean iscopy;
44 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
45 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
46 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
47 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
48 const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
49 const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
50
51 tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
52 class_name_cstr, method_name_cstr, file_name_cstr,
53 line_number, timestamp, loglevel, thread_name_cstr);
54
55 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
56 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
57 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
58 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
59 (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
60 (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
61 }
62
63 /*
64 * Tracepoint used by Java applications using the log4j handler.
65 */
66 JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepointWithContext(JNIEnv *env,
67 jobject jobj,
68 jstring msg,
69 jstring logger_name,
70 jstring class_name,
71 jstring method_name,
72 jstring file_name,
73 jint line_number,
74 jlong timestamp,
75 jint loglevel,
76 jstring thread_name,
77 jbyteArray context_info_entries,
78 jbyteArray context_info_strings)
79 {
80 jboolean iscopy;
81 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
82 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
83 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
84 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
85 const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
86 const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
87 signed char *context_info_entries_array;
88 signed char *context_info_strings_array;
89
90 /*
91 * Write these to the TLS variables, so that the UST callbacks in
92 * lttng_ust_context.c can access them.
93 */
94 context_info_entries_array = (*env)->GetByteArrayElements(env, context_info_entries, &iscopy);
95 lttng_ust_context_info_tls.ctx_entries = (struct lttng_ust_jni_ctx_entry *) context_info_entries_array;
96 lttng_ust_context_info_tls.ctx_entries_len = (*env)->GetArrayLength(env, context_info_entries);
97 context_info_strings_array = (*env)->GetByteArrayElements(env, context_info_strings, &iscopy);
98 lttng_ust_context_info_tls.ctx_strings = context_info_strings_array;
99 lttng_ust_context_info_tls.ctx_strings_len = (*env)->GetArrayLength(env, context_info_strings);
100
101 tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
102 class_name_cstr, method_name_cstr, file_name_cstr,
103 line_number, timestamp, loglevel, thread_name_cstr);
104
105 lttng_ust_context_info_tls.ctx_entries = NULL;
106 lttng_ust_context_info_tls.ctx_entries_len = 0;
107 lttng_ust_context_info_tls.ctx_strings = NULL;
108 lttng_ust_context_info_tls.ctx_strings_len = 0;
109 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
110 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
111 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
112 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
113 (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
114 (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
115 (*env)->ReleaseByteArrayElements(env, context_info_entries, context_info_entries_array, 0);
116 (*env)->ReleaseByteArrayElements(env, context_info_strings, context_info_strings_array, 0);
117 }
This page took 0.030647 seconds and 3 git commands to generate.