Commit | Line | Data |
---|---|---|
43e5396b | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
43e5396b | 3 | * |
c0c0989a MJ |
4 | * Copyright (C) 2016 EfficiOS Inc. |
5 | * Copyright (C) 2016 Alexandre Montplaisir <alexmonthy@efficios.com> | |
6 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
43e5396b DG |
7 | */ |
8 | ||
1ddceb36 | 9 | #define _LGPL_SOURCE |
6e7bc9e0 | 10 | #include "org_lttng_ust_agent_log4j_LttngLog4jApi.h" |
464c4756 | 11 | #include "lttng_ust_log4j_tp.h" |
8ab5c06b | 12 | #include "../common/lttng_ust_context.h" |
43e5396b | 13 | |
9aabed2d | 14 | /* |
8ab5c06b | 15 | * Deprecated function from before the context information was passed. |
9aabed2d | 16 | */ |
6e7bc9e0 | 17 | JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepoint(JNIEnv *env, |
2208d8b5 | 18 | jobject jobj __attribute__((unused)), |
43e5396b DG |
19 | jstring msg, |
20 | jstring logger_name, | |
21 | jstring class_name, | |
22 | jstring method_name, | |
501f6777 CB |
23 | jstring file_name, |
24 | jint line_number, | |
25 | jlong timestamp, | |
26 | jint loglevel, | |
27 | jstring thread_name) | |
43e5396b DG |
28 | { |
29 | jboolean iscopy; | |
30 | const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy); | |
31 | const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy); | |
32 | const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy); | |
33 | const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy); | |
501f6777 CB |
34 | const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy); |
35 | const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy); | |
43e5396b | 36 | |
cbc06a3b | 37 | lttng_ust_tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr, |
501f6777 CB |
38 | class_name_cstr, method_name_cstr, file_name_cstr, |
39 | line_number, timestamp, loglevel, thread_name_cstr); | |
9aabed2d DG |
40 | |
41 | (*env)->ReleaseStringUTFChars(env, msg, msg_cstr); | |
42 | (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr); | |
43 | (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr); | |
44 | (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr); | |
501f6777 CB |
45 | (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr); |
46 | (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr); | |
9aabed2d DG |
47 | } |
48 | ||
8ab5c06b AM |
49 | /* |
50 | * Tracepoint used by Java applications using the log4j handler. | |
51 | */ | |
52 | JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepointWithContext(JNIEnv *env, | |
2208d8b5 | 53 | jobject jobj __attribute__((unused)), |
8ab5c06b AM |
54 | jstring msg, |
55 | jstring logger_name, | |
56 | jstring class_name, | |
57 | jstring method_name, | |
58 | jstring file_name, | |
59 | jint line_number, | |
60 | jlong timestamp, | |
61 | jint loglevel, | |
62 | jstring thread_name, | |
b1ca4c5f AM |
63 | jbyteArray context_info_entries, |
64 | jbyteArray context_info_strings) | |
8ab5c06b AM |
65 | { |
66 | jboolean iscopy; | |
67 | const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy); | |
68 | const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy); | |
69 | const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy); | |
70 | const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy); | |
71 | const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy); | |
72 | const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy); | |
b1ca4c5f AM |
73 | signed char *context_info_entries_array; |
74 | signed char *context_info_strings_array; | |
8ab5c06b AM |
75 | |
76 | /* | |
77 | * Write these to the TLS variables, so that the UST callbacks in | |
78 | * lttng_ust_context.c can access them. | |
79 | */ | |
b1ca4c5f AM |
80 | context_info_entries_array = (*env)->GetByteArrayElements(env, context_info_entries, &iscopy); |
81 | lttng_ust_context_info_tls.ctx_entries = (struct lttng_ust_jni_ctx_entry *) context_info_entries_array; | |
82 | lttng_ust_context_info_tls.ctx_entries_len = (*env)->GetArrayLength(env, context_info_entries); | |
83 | context_info_strings_array = (*env)->GetByteArrayElements(env, context_info_strings, &iscopy); | |
84 | lttng_ust_context_info_tls.ctx_strings = context_info_strings_array; | |
85 | lttng_ust_context_info_tls.ctx_strings_len = (*env)->GetArrayLength(env, context_info_strings); | |
8ab5c06b | 86 | |
cbc06a3b | 87 | lttng_ust_tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr, |
8ab5c06b AM |
88 | class_name_cstr, method_name_cstr, file_name_cstr, |
89 | line_number, timestamp, loglevel, thread_name_cstr); | |
90 | ||
b1ca4c5f AM |
91 | lttng_ust_context_info_tls.ctx_entries = NULL; |
92 | lttng_ust_context_info_tls.ctx_entries_len = 0; | |
93 | lttng_ust_context_info_tls.ctx_strings = NULL; | |
94 | lttng_ust_context_info_tls.ctx_strings_len = 0; | |
8ab5c06b AM |
95 | (*env)->ReleaseStringUTFChars(env, msg, msg_cstr); |
96 | (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr); | |
97 | (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr); | |
98 | (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr); | |
99 | (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr); | |
100 | (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr); | |
b1ca4c5f AM |
101 | (*env)->ReleaseByteArrayElements(env, context_info_entries, context_info_entries_array, 0); |
102 | (*env)->ReleaseByteArrayElements(env, context_info_strings, context_info_strings_array, 0); | |
8ab5c06b | 103 | } |