1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

VCMIDirs update #5

- Minor fixes
- string based paths -> boost::filesystem::path paths (I hope it's
final)
- New user data path on windows
- New moving dir method on windows.
This commit is contained in:
Karol
2014-08-21 22:26:28 +02:00
parent 2da6d9e7dd
commit 958839668c
25 changed files with 359 additions and 191 deletions

View File

@@ -3,10 +3,7 @@
#include "../CConfigHandler.h"
CBasicLogConfigurator::CBasicLogConfigurator(const boost::filesystem::path & filePath, CConsoleHandler * const console) :
filePath(filePath), console(console), appendToLogFile(false) {}
CBasicLogConfigurator::CBasicLogConfigurator(boost::filesystem::path && filePath, CConsoleHandler * const console) :
CBasicLogConfigurator::CBasicLogConfigurator(boost::filesystem::path filePath, CConsoleHandler * const console) :
filePath(std::move(filePath)), console(console), appendToLogFile(false) {}
void CBasicLogConfigurator::configureDefault()

View File

@@ -22,8 +22,7 @@ class JsonNode;
class DLL_LINKAGE CBasicLogConfigurator
{
public:
CBasicLogConfigurator(const boost::filesystem::path & filePath, CConsoleHandler * const console);
CBasicLogConfigurator(boost::filesystem::path && filePath, CConsoleHandler * const console);
CBasicLogConfigurator(boost::filesystem::path filePath, CConsoleHandler * const console);
/// Configures the logging system by parsing the logging settings. It adds the console target and the file target to the global logger.
/// Doesn't throw, but logs on success or fault.

View File

@@ -1,14 +1,30 @@
#include "StdInc.h"
#include "CLogger.h"
#ifdef VCMI_ANDROID
#include <android/log.h>
namespace ELogLevel
{
int toAndroid(ELogLevel logLevel)
{
switch (logLevel)
{
case TRACE: return ANDROID_LOG_VERBOSE;
case DEBUG: return ANDROID_LOG_DEBUG;
case INFO: return ANDROID_LOG_INFO;
case WARN: return ANDROID_LOG_WARN;
case ERROR: return ANDROID_LOG_ERROR;
default:;
}
return ANDROID_LOG_UNKNOWN;
}
}
#endif
const std::string CLoggerDomain::DOMAIN_GLOBAL = "global";
CLoggerDomain::CLoggerDomain(const std::string & name) : name(name)
{
if(name.empty())
throw std::runtime_error("Logger domain cannot be empty.");
}
CLoggerDomain::CLoggerDomain(std::string && name) : name(std::move(name))
CLoggerDomain::CLoggerDomain(std::string name) : name(std::move(name))
{
if (this->name.empty())
throw std::runtime_error("Logger domain cannot be empty.");
@@ -302,15 +318,16 @@ CLogConsoleTarget::CLogConsoleTarget(CConsoleHandler * console) : console(consol
void CLogConsoleTarget::write(const LogRecord & record)
{
if(threshold > record.level) return;
if(threshold > record.level)
return;
std::string message = formatter.format(record);
#ifdef VCMI_ANDROID
__android_log_print(ANDROID_LOG_INFO, "VCMI", "%s", message.c_str());
__android_log_write(ELogLevel::toAndroid(record.level), "VCMI", message.c_str());
#endif
bool printToStdErr = record.level >= ELogLevel::WARN;
const bool printToStdErr = record.level >= ELogLevel::WARN;
if(console)
{
const EConsoleTextColor::EConsoleTextColor textColor =
@@ -340,22 +357,12 @@ void CLogConsoleTarget::setFormatter(const CLogFormatter & formatter) { this->fo
const CColorMapping & CLogConsoleTarget::getColorMapping() const { return colorMapping; }
void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; }
CLogFileTarget::CLogFileTarget(const boost::filesystem::path & filePath, bool append /*= true*/)
: file(filePath, append ? std::ios_base::app : std::ios_base::out)
{
formatter.setPattern("%d %l %n [%t] - %m");
}
CLogFileTarget::CLogFileTarget(boost::filesystem::path && filePath, bool append /*= true*/)
CLogFileTarget::CLogFileTarget(boost::filesystem::path filePath, bool append /*= true*/)
: file(std::move(filePath), append ? std::ios_base::app : std::ios_base::out)
{
formatter.setPattern("%d %l %n [%t] - %m");
}
CLogFileTarget::~CLogFileTarget()
{
file.close();
}
void CLogFileTarget::write(const LogRecord & record)
{
TLockGuard _(mx);

View File

@@ -19,15 +19,19 @@ class ILogTarget;
namespace ELogLevel
{
enum ELogLevel
{
NOT_SET = 0,
TRACE,
DEBUG,
INFO,
WARN,
ERROR
};
enum ELogLevel
{
NOT_SET = 0,
TRACE,
DEBUG,
INFO,
WARN,
ERROR
};
#ifdef VCMI_ANDROID
int toAndroid(ELogLevel logLevel);
#endif
}
/// The class CLoggerDomain provides convenient access to super domains from a sub domain.
@@ -36,8 +40,7 @@ class DLL_LINKAGE CLoggerDomain
public:
/// Constructs a CLoggerDomain with the domain designated by name.
/// Sub-domains can be specified by separating domains by a dot, e.g. "ai.battle". The global domain is named "global".
explicit CLoggerDomain(const std::string & name);
explicit CLoggerDomain(std::string && name);
explicit CLoggerDomain(std::string name);
const std::string& getName() const;
CLoggerDomain getParent() const;
@@ -288,9 +291,7 @@ class DLL_LINKAGE CLogFileTarget : public ILogTarget
public:
/// Constructs a CLogFileTarget and opens the file designated by file_path. If the append parameter is true, the file
/// will be appended to. Otherwise the file designated by filePath will be truncated before being opened.
explicit CLogFileTarget(const boost::filesystem::path & file_path, bool append = true);
explicit CLogFileTarget(boost::filesystem::path && file_path, bool append = true);
~CLogFileTarget();
explicit CLogFileTarget(boost::filesystem::path file_path, bool append = true);
const CLogFormatter & getFormatter() const;
void setFormatter(const CLogFormatter & formatter);