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:
parent
6e41e3154c
commit
75282366c0
@ -165,7 +165,6 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception)
|
||||
|
||||
void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color)
|
||||
{
|
||||
#ifndef VCMI_IOS
|
||||
TColor colorCode;
|
||||
switch(color)
|
||||
{
|
||||
@ -205,7 +204,6 @@ void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color)
|
||||
#else
|
||||
std::cout << colorCode;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
int CConsoleHandler::run()
|
||||
|
@ -13,3 +13,5 @@ extern const char *ios_cachesPath();
|
||||
|
||||
extern const char *ios_bundlePath();
|
||||
extern const char *ios_frameworksPath();
|
||||
|
||||
extern const char *ios_bundleIdentifier();
|
||||
|
@ -22,3 +22,5 @@ const char *ios_cachesPath() { return standardPath(NSCachesDirectory); }
|
||||
|
||||
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_bundleIdentifier() { return NSBundle.mainBundle.bundleIdentifier.UTF8String; }
|
||||
|
@ -30,6 +30,11 @@ namespace ELogLevel
|
||||
return ANDROID_LOG_UNKNOWN;
|
||||
}
|
||||
}
|
||||
#elif defined(VCMI_IOS)
|
||||
extern "C" {
|
||||
#import "../CIOSUtils.h"
|
||||
#include <os/log.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace vstd
|
||||
@ -353,6 +358,41 @@ void CLogConsoleTarget::write(const LogRecord & record)
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
__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
|
||||
|
||||
const bool printToStdErr = record.level >= ELogLevel::WARN;
|
||||
|
Loading…
Reference in New Issue
Block a user