2 * Copyright (C) 2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "platform/android/utils/AndroidInterfaceForCLog.h"
11 #include "CompileInfo.h"
14 #include <spdlog/sinks/android_sink.h>
15 #include <spdlog/sinks/dist_sink.h>
17 // On some Android platforms debug logging is deactivated.
18 // We try to activate debug logging for our app via function "__android_log_set_minimum_priority" from "/system/lib/liblog.so".
19 // The function is defined in API level 30 (Android 11) as:
20 // int32_t __android_log_set_minimum_priority(int32_t priority);
21 void ActivateAndroidDebugLogging()
23 void* libHandle
= dlopen("liblog.so", RTLD_LAZY
);
26 void* funcPtr
= dlsym(libHandle
, "__android_log_set_minimum_priority");
29 typedef int32_t (*android_log_set_minimum_priority_func
)(int32_t);
30 reinterpret_cast<android_log_set_minimum_priority_func
>(funcPtr
)(ANDROID_LOG_DEBUG
);
36 std::unique_ptr
<IPlatformLog
> IPlatformLog::CreatePlatformLog()
38 ActivateAndroidDebugLogging();
39 return std::make_unique
<CAndroidInterfaceForCLog
>();
42 void CAndroidInterfaceForCLog::AddSinks(
43 std::shared_ptr
<spdlog::sinks::dist_sink
<std::mutex
>> distributionSink
) const
45 distributionSink
->add_sink(
46 std::make_shared
<spdlog::sinks::android_sink_st
>(CCompileInfo::GetAppName()));