android/LogListener: pass formatted message to OnLog()
This commit is contained in:
parent
4db882f666
commit
4d32454697
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue