Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust-java-agent / jni / log4j / lttng_ust_log4j.c
CommitLineData
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"
43e5396b
DG
11
12#define TRACEPOINT_DEFINE
13#define TRACEPOINT_CREATE_PROBES
501f6777 14#include "lttng_ust_log4j.h"
8ab5c06b 15#include "../common/lttng_ust_context.h"
43e5396b 16
9aabed2d 17/*
8ab5c06b 18 * Deprecated function from before the context information was passed.
9aabed2d 19 */
6e7bc9e0 20JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepoint(JNIEnv *env,
43e5396b
DG
21 jobject jobj,
22 jstring msg,
23 jstring logger_name,
24 jstring class_name,
25 jstring method_name,
501f6777
CB
26 jstring file_name,
27 jint line_number,
28 jlong timestamp,
29 jint loglevel,
30 jstring thread_name)
43e5396b
DG
31{
32 jboolean iscopy;
33 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
34 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
35 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
36 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
501f6777
CB
37 const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
38 const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
43e5396b 39
8286ff50 40 tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
501f6777
CB
41 class_name_cstr, method_name_cstr, file_name_cstr,
42 line_number, timestamp, loglevel, thread_name_cstr);
9aabed2d
DG
43
44 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
45 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
46 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
47 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
501f6777
CB
48 (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
49 (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
9aabed2d
DG
50}
51
8ab5c06b
AM
52/*
53 * Tracepoint used by Java applications using the log4j handler.
54 */
55JNIEXPORT void JNICALL Java_org_lttng_ust_agent_log4j_LttngLog4jApi_tracepointWithContext(JNIEnv *env,
56 jobject jobj,
57 jstring msg,
58 jstring logger_name,
59 jstring class_name,
60 jstring method_name,
61 jstring file_name,
62 jint line_number,
63 jlong timestamp,
64 jint loglevel,
65 jstring thread_name,
b1ca4c5f
AM
66 jbyteArray context_info_entries,
67 jbyteArray context_info_strings)
8ab5c06b
AM
68{
69 jboolean iscopy;
70 const char *msg_cstr = (*env)->GetStringUTFChars(env, msg, &iscopy);
71 const char *logger_name_cstr = (*env)->GetStringUTFChars(env, logger_name, &iscopy);
72 const char *class_name_cstr = (*env)->GetStringUTFChars(env, class_name, &iscopy);
73 const char *method_name_cstr = (*env)->GetStringUTFChars(env, method_name, &iscopy);
74 const char *file_name_cstr = (*env)->GetStringUTFChars(env, file_name, &iscopy);
75 const char *thread_name_cstr = (*env)->GetStringUTFChars(env, thread_name, &iscopy);
b1ca4c5f
AM
76 signed char *context_info_entries_array;
77 signed char *context_info_strings_array;
8ab5c06b
AM
78
79 /*
80 * Write these to the TLS variables, so that the UST callbacks in
81 * lttng_ust_context.c can access them.
82 */
b1ca4c5f
AM
83 context_info_entries_array = (*env)->GetByteArrayElements(env, context_info_entries, &iscopy);
84 lttng_ust_context_info_tls.ctx_entries = (struct lttng_ust_jni_ctx_entry *) context_info_entries_array;
85 lttng_ust_context_info_tls.ctx_entries_len = (*env)->GetArrayLength(env, context_info_entries);
86 context_info_strings_array = (*env)->GetByteArrayElements(env, context_info_strings, &iscopy);
87 lttng_ust_context_info_tls.ctx_strings = context_info_strings_array;
88 lttng_ust_context_info_tls.ctx_strings_len = (*env)->GetArrayLength(env, context_info_strings);
8ab5c06b
AM
89
90 tracepoint(lttng_log4j, event, msg_cstr, logger_name_cstr,
91 class_name_cstr, method_name_cstr, file_name_cstr,
92 line_number, timestamp, loglevel, thread_name_cstr);
93
b1ca4c5f
AM
94 lttng_ust_context_info_tls.ctx_entries = NULL;
95 lttng_ust_context_info_tls.ctx_entries_len = 0;
96 lttng_ust_context_info_tls.ctx_strings = NULL;
97 lttng_ust_context_info_tls.ctx_strings_len = 0;
8ab5c06b
AM
98 (*env)->ReleaseStringUTFChars(env, msg, msg_cstr);
99 (*env)->ReleaseStringUTFChars(env, logger_name, logger_name_cstr);
100 (*env)->ReleaseStringUTFChars(env, class_name, class_name_cstr);
101 (*env)->ReleaseStringUTFChars(env, method_name, method_name_cstr);
102 (*env)->ReleaseStringUTFChars(env, file_name, file_name_cstr);
103 (*env)->ReleaseStringUTFChars(env, thread_name, thread_name_cstr);
b1ca4c5f
AM
104 (*env)->ReleaseByteArrayElements(env, context_info_entries, context_info_entries_array, 0);
105 (*env)->ReleaseByteArrayElements(env, context_info_strings, context_info_strings_array, 0);
8ab5c06b 106}
This page took 0.031864 seconds and 4 git commands to generate.