1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

log messages with os_log

This commit is contained in:
Andrey Filipenkov 2021-03-13 13:47:06 +03:00
parent 6e41e3154c
commit 75282366c0
4 changed files with 44 additions and 2 deletions

View File

@ -165,7 +165,6 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception)
void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color) void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color)
{ {
#ifndef VCMI_IOS
TColor colorCode; TColor colorCode;
switch(color) switch(color)
{ {
@ -205,7 +204,6 @@ void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color)
#else #else
std::cout << colorCode; std::cout << colorCode;
#endif #endif
#endif
} }
int CConsoleHandler::run() int CConsoleHandler::run()

View File

@ -13,3 +13,5 @@ extern const char *ios_cachesPath();
extern const char *ios_bundlePath(); extern const char *ios_bundlePath();
extern const char *ios_frameworksPath(); extern const char *ios_frameworksPath();
extern const char *ios_bundleIdentifier();

View File

@ -22,3 +22,5 @@ const char *ios_cachesPath() { return standardPath(NSCachesDirectory); }
const char *ios_bundlePath() { return NSBundle.mainBundle.bundlePath.UTF8String; } const char *ios_bundlePath() { return NSBundle.mainBundle.bundlePath.UTF8String; }
const char *ios_frameworksPath() { return [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:@"Frameworks"].UTF8String; } // TODO: sharedFrameworksPath? const char *ios_frameworksPath() { return [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:@"Frameworks"].UTF8String; } // TODO: sharedFrameworksPath?
const char *ios_bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; }

View File

@ -30,6 +30,11 @@ namespace ELogLevel
return ANDROID_LOG_UNKNOWN; return ANDROID_LOG_UNKNOWN;
} }
} }
#elif defined(VCMI_IOS)
extern "C" {
#import "../CIOSUtils.h"
#include <os/log.h>
}
#endif #endif
namespace vstd namespace vstd
@ -353,6 +358,41 @@ void CLogConsoleTarget::write(const LogRecord & record)
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
__android_log_write(ELogLevel::toAndroid(record.level), ("VCMI-" + record.domain.getName()).c_str(), message.c_str()); __android_log_write(ELogLevel::toAndroid(record.level), ("VCMI-" + record.domain.getName()).c_str(), message.c_str());
#elif defined(VCMI_IOS)
os_log_type_t type;
switch (record.level)
{
case ELogLevel::TRACE:
type = OS_LOG_TYPE_DEBUG;
break;
case ELogLevel::DEBUG:
type = OS_LOG_TYPE_DEFAULT;
break;
case ELogLevel::INFO:
type = OS_LOG_TYPE_INFO;
break;
case ELogLevel::WARN:
type = OS_LOG_TYPE_ERROR;
break;
case ELogLevel::ERROR:
type = OS_LOG_TYPE_FAULT;
break;
default:
return;
}
os_log_t currentLog;
static std::unordered_map<std::string, decltype(currentLog)> logs;
const auto& domainName = record.domain.getName();
auto logIt = logs.find(domainName);
if (logIt != logs.end())
currentLog = logIt->second;
else
{
currentLog = os_log_create(ios_bundleIdentifier(), domainName.c_str());
logs.insert({domainName, currentLog});
}
os_log_with_type(currentLog, type, "%s", message.c_str());
#else #else
const bool printToStdErr = record.level >= ELogLevel::WARN; const bool printToStdErr = record.level >= ELogLevel::WARN;