From 4d32454697acd9a4c96529bf71e7101b979468bb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 27 May 2021 16:19:46 +0200 Subject: [PATCH] android/LogListener: pass formatted message to OnLog() --- src/LogBackend.cxx | 9 +++++++-- src/android/LogListener.cxx | 12 ++---------- src/android/LogListener.hxx | 3 +-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/LogBackend.cxx b/src/LogBackend.cxx index e5e98c5f1..19139da09 100644 --- a/src/LogBackend.cxx +++ b/src/LogBackend.cxx @@ -183,9 +183,14 @@ Log(LogLevel level, const Domain &domain, const char *msg) noexcept #ifdef ANDROID __android_log_print(ToAndroidLogLevel(level), "MPD", "%s: %s", domain.GetName(), msg); - if (logListener != nullptr) + if (logListener != nullptr) { + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "%s: %s", + domain.GetName(), msg); + logListener->OnLog(Java::GetEnv(), ToAndroidLogLevel(level), - "%s: %s", domain.GetName(), msg); + buffer); + } #else if (level < log_threshold) diff --git a/src/android/LogListener.cxx b/src/android/LogListener.cxx index 36c78a142..d5e2a3070 100644 --- a/src/android/LogListener.cxx +++ b/src/android/LogListener.cxx @@ -20,8 +20,6 @@ #include "LogListener.hxx" #include "java/Class.hxx" #include "java/String.hxx" -#include "util/AllocatedString.hxx" -#include "util/FormatString.hxx" LogListener::LogListener(JNIEnv *env, jobject obj) noexcept :Java::GlobalObject(env, obj) @@ -33,16 +31,10 @@ LogListener::LogListener(JNIEnv *env, jobject obj) noexcept } void -LogListener::OnLog(JNIEnv *env, int priority, - const char *fmt, ...) const noexcept +LogListener::OnLog(JNIEnv *env, int priority, const char *msg) const noexcept { assert(env != nullptr); - std::va_list args; - va_start(args, fmt); - const auto log = FormatStringV(fmt, args); - va_end(args); - env->CallVoidMethod(Get(), onLogMethod, priority, - Java::String(env, log.c_str()).Get()); + Java::String(env, msg).Get()); } diff --git a/src/android/LogListener.hxx b/src/android/LogListener.hxx index 0a0e2a1bb..e1907fce2 100644 --- a/src/android/LogListener.hxx +++ b/src/android/LogListener.hxx @@ -28,8 +28,7 @@ class LogListener : public Java::GlobalObject { public: LogListener(JNIEnv *env, jobject obj) noexcept; - void OnLog(JNIEnv *env, int priority, - const char *fmt, ...) const noexcept; + void OnLog(JNIEnv *env, int priority, const char *msg) const noexcept; }; #endif