xref: /aosp_15_r20/external/webrtc/sdk/android/src/jni/logging/log_sink.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2018 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include "sdk/android/src/jni/logging/log_sink.h"
11 
12 #include "absl/strings/string_view.h"
13 #include "sdk/android/generated_logging_jni/JNILogging_jni.h"
14 
15 namespace webrtc {
16 namespace jni {
17 
JNILogSink(JNIEnv * env,const JavaRef<jobject> & j_logging)18 JNILogSink::JNILogSink(JNIEnv* env, const JavaRef<jobject>& j_logging)
19     : j_logging_(env, j_logging) {}
20 JNILogSink::~JNILogSink() = default;
21 
OnLogMessage(const std::string & msg)22 void JNILogSink::OnLogMessage(const std::string& msg) {
23   RTC_DCHECK_NOTREACHED();
24 }
25 
OnLogMessage(const std::string & msg,rtc::LoggingSeverity severity,const char * tag)26 void JNILogSink::OnLogMessage(const std::string& msg,
27                               rtc::LoggingSeverity severity,
28                               const char* tag) {
29   OnLogMessage(absl::string_view{msg}, severity, tag);
30 }
31 
OnLogMessage(absl::string_view msg,rtc::LoggingSeverity severity,const char * tag)32 void JNILogSink::OnLogMessage(absl::string_view msg,
33                               rtc::LoggingSeverity severity,
34                               const char* tag) {
35   JNIEnv* env = AttachCurrentThreadIfNeeded();
36   Java_JNILogging_logToInjectable(
37       env, j_logging_, NativeToJavaString(env, std::string(msg)),
38       NativeToJavaInteger(env, severity), NativeToJavaString(env, tag));
39 }
40 
41 }  // namespace jni
42 }  // namespace webrtc
43