Commit 4d324546 authored by Max Kellermann's avatar Max Kellermann

android/LogListener: pass formatted message to OnLog()

parent 4db882f6
......@@ -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)
......
......@@ -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());
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment