diff --git a/clientapp/EntryPoint.cpp b/clientapp/EntryPoint.cpp index 7d1731b4c..271c87459 100644 --- a/clientapp/EntryPoint.cpp +++ b/clientapp/EntryPoint.cpp @@ -227,12 +227,12 @@ int main(int argc, char * argv[]) CConsoleHandler console(callbackFunction); console.start(); - logConfig = new CBasicLogConfigurator(logPath, &console); + CBasicLogConfigurator logConfig(logPath, &console); #else - logConfig = new CBasicLogConfigurator(logPath, nullptr); + CBasicLogConfigurator logConfig(logPath, nullptr); #endif - logConfig->configureDefault(); + logConfig.configureDefault(); logGlobal->info("Starting client of '%s'", GameConstants::VCMI_VERSION); logGlobal->info("Creating console and configuring logger: %d ms", pomtime.getDiff()); logGlobal->info("The log file will be saved to %s", logPath); @@ -289,7 +289,7 @@ int main(int argc, char * argv[]) setSettingInteger("general/saveFrequency", "savefrequency", 1); // Initialize logging based on settings - logConfig->configure(); + logConfig.configure(); logGlobal->debug("settings = %s", settings.toJsonNode().toString()); // Some basic data validation to produce better error messages in cases of incorrect install diff --git a/lib/CConsoleHandler.cpp b/lib/CConsoleHandler.cpp index 3f4c4f5e1..881e5edf9 100644 --- a/lib/CConsoleHandler.cpp +++ b/lib/CConsoleHandler.cpp @@ -27,7 +27,6 @@ VCMI_LIB_NAMESPACE_END #endif #ifndef VCMI_WINDOWS - using TColor = std::string; #define CONSOLE_GREEN "\x1b[1;32m" #define CONSOLE_RED "\x1b[1;31m" #define CONSOLE_MAGENTA "\x1b[1;35m" @@ -41,7 +40,6 @@ VCMI_LIB_NAMESPACE_END #ifndef __MINGW32__ #pragma comment(lib, "dbghelp.lib") #endif - typedef WORD TColor; HANDLE handleIn; HANDLE handleOut; HANDLE handleErr; @@ -52,12 +50,8 @@ VCMI_LIB_NAMESPACE_END #define CONSOLE_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY #define CONSOLE_GRAY FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE #define CONSOLE_TEAL FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY - - static TColor defErrColor; #endif -static TColor defColor; - VCMI_LIB_NAMESPACE_BEGIN #ifdef CREATE_MEMORY_DUMP diff --git a/lib/CConsoleHandler.h b/lib/CConsoleHandler.h index fd3ac2003..cded6b94c 100644 --- a/lib/CConsoleHandler.h +++ b/lib/CConsoleHandler.h @@ -78,12 +78,22 @@ public: } private: + +#ifndef VCMI_WINDOWS + using TColor = std::string; +#else + typedef WORD TColor; +#endif + int run(); void end(); //kills listening thread void setColor(EConsoleTextColor::EConsoleTextColor color); //sets color of text appropriate for given logging level + static TColor defColor; + static TColor defErrColor; + //function to be called when message is received - string: message, bool: whether call was made from in-game console std::function cb; diff --git a/mapeditor/inspector/heroskillswidget.cpp b/mapeditor/inspector/heroskillswidget.cpp index eb099f5a7..4ad7626cc 100644 --- a/mapeditor/inspector/heroskillswidget.cpp +++ b/mapeditor/inspector/heroskillswidget.cpp @@ -15,7 +15,7 @@ #include "../../lib/CSkillHandler.h" #include "inspector.h" -static QList> LevelIdentifiers +static const QList> LevelIdentifiers { {QObject::tr("Beginner"), QVariant::fromValue(1)}, {QObject::tr("Advanced"), QVariant::fromValue(2)}, diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 3180b3e94..40f8ff8e3 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -51,8 +51,6 @@ #include "playersettings.h" #include "validator.h" -static CBasicLogConfigurator * logConfig; - QJsonValue jsonFromPixmap(const QPixmap &p) { QBuffer buffer; @@ -185,7 +183,7 @@ MainWindow::MainWindow(QWidget* parent) : //configure logging const boost::filesystem::path logPath = VCMIDirs::get().userLogsPath() / "VCMI_Editor_log.txt"; console = std::make_unique(); - logConfig = new CBasicLogConfigurator(logPath, console.get()); + logConfig = std::make_unique(logPath, console.get()); logConfig->configureDefault(); logGlobal->info("Starting map editor of '%s'", GameConstants::VCMI_VERSION); logGlobal->info("The log file will be saved to %s", logPath); diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index e11b303e1..b16f342ba 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -13,6 +13,7 @@ VCMI_LIB_NAMESPACE_BEGIN class CMap; class CampaignState; class CConsoleHandler; +class CBasicLogConfigurator; class CGObjectInstance; VCMI_LIB_NAMESPACE_END @@ -39,6 +40,7 @@ class MainWindow : public QMainWindow #ifndef VCMI_MOBILE std::unique_ptr console; #endif + std::unique_ptr logConfig; std::unique_ptr openMapInternal(const QString &); std::shared_ptr openCampaignInternal(const QString &);