Android Logger Support

This commit is contained in:
Isuru Samarathunga
2025-10-05 16:17:06 +05:30
parent 66299a7caf
commit a73cc7e69c
2 changed files with 30 additions and 3 deletions

View File

@ -16,7 +16,7 @@
#pragma once
#include <IACore/String.hpp>
#include <IACore/Logger.hpp>
namespace ia {
enum class ExceptionKind {
@ -132,7 +132,7 @@ private:
#define DEFINE_THROWER(name) \
template <typename... Args> NORETURN VOID THROW_##name(Args... args) { \
const auto msg = BuildString(args...); \
printf(#name " %s\n", msg.c_str()); \
Logger::Error("EXCEPT", "(", #name, "): ", msg); \
throw RuntimeException(ExceptionKind::name, msg); \
}
FOR_EACH_RUNTIME_EXCEPT_TYPE(DEFINE_THROWER);

View File

@ -18,6 +18,10 @@
#include <IACore/String.hpp>
#ifdef __ANDROID__
#include <android/log.h>
#endif
namespace ia
{
class Logger
@ -27,21 +31,44 @@ namespace ia
{
StringStream ss;
UNUSED((ss << ... << args));
printf("\033[32m[INFO]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "IAApp", ss.str().c_str());
#else
printf("\033[0;37m[INFO]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
template<typename... Args> STATIC VOID Success(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_INFO, "IAApp", ss.str().c_str());
#else
printf("\033[32m[SUCCESS]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
template<typename... Args> STATIC VOID Warn(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "IAApp", ss.str().c_str());
#else
printf("\033[33m[WARN]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
template<typename... Args> STATIC VOID Error(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_ERROR, "IAApp", ss.str().c_str());
#else
printf("\033[31m[ERROR]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
private: