From 7ebe093078675fafdea99fec4c10e98ea9830d54 Mon Sep 17 00:00:00 2001 From: Phil7789 <87429599+Phil7789@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:35:29 +0200 Subject: [PATCH 1/4] Update Changelog.txt --- Changelog.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 7598dc4..0dda507 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,12 +1,17 @@ [Changelog v0.15.0] -[!WARNING] -SID evaluation slightly changed due to the bug fixing of restrictions overruling pilot filed SIDs. If you encounter odd or unexpected evaluation results please feel free to report back. +>[!WARNING] +>SID evaluation slightly changed due to the bug fixing of restrictions overruling pilot filed SIDs. If you encounter odd or unexpected evaluation results please feel free to report back. :new: **New Features** * GEN - add crash handling * a .txt file is generated with a small stacktrace showing the line or offset, depending if the pdb file was present at the time of the crash * a .dmp file is generated (default is a minidump - a fulldump can be generated by adding a file "create_fulldump" without file ending next to the dll) * the pdb file is generated during the build process +* GEN - new logger added + * logs are now stored in a "logs" folder next to the dll + * logs are rotated on ES start or when reaching 10 MB per file (maximum 5 logs are stored) + * new command ".vsid log dev" to enable logging of development messages (disabled by default) + * new main config setting "logDevOnly" as boolean value * FPLN - add "handover" flag for airports where the TWR controller sends pilots over to radar * flag is shown immediately after takeoff / airborne * airport config values: From bde04d4d42df12b2aea9048ff352b9d658281eec Mon Sep 17 00:00:00 2001 From: Phil7789 <87429599+Phil7789@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:35:43 +0200 Subject: [PATCH 2/4] Add new logger --- logger.cpp | 290 +++++++++++++++++++++++++++++++++++++++++++++++++++++ logger.h | 203 +++++++++++++++++++++++++++++++++++++ 2 files changed, 493 insertions(+) create mode 100644 logger.cpp create mode 100644 logger.h diff --git a/logger.cpp b/logger.cpp new file mode 100644 index 0000000..58f43fb --- /dev/null +++ b/logger.cpp @@ -0,0 +1,290 @@ +#include "pch.h" + +#include "logger.h" +#include "timeHandler.h" + +#include +#include + +void vsid::Logger::initialize() +{ + if (running) return; + + std::error_code ec; + + // get dll path + char pathBuf[MAX_PATH]; + GetModuleFileNameA((HINSTANCE)&__ImageBase, pathBuf, MAX_PATH); + std::filesystem::path dllPath = pathBuf; + logFilePath = dllPath.parent_path() / "logs" / "vsid.log"; + + std::filesystem::create_directory(logFilePath.parent_path(), ec); + + if (!ec) + { + fileLockMutex = CreateMutexA(NULL, FALSE, "Local\\vsid_log_mutex"); + + if (fileLockMutex != NULL && GetLastError() == ERROR_ALREADY_EXISTS) + { + CloseHandle(fileLockMutex); + fileLockMutex = NULL; + } + else if (fileLockMutex != NULL) + { + rotateLogs(); // rotate logs on startup to archive previous session logs + logFile.open(logFilePath, std::ios::app); + } + + } + + // create thread + running = true; + worker = std::thread(workerThread); + + if (!logFile.is_open()) + { + log(LogLevel::Error, "File logging disabled: Insufficient permissions to create or access log directory."); + } + else + log(LogLevel::Info, "Logger initialized successfully (File logging active)."); +} + +void vsid::Logger::shutdown() { + if (!running) return; + + // signal thread stopping + running = false; + cv.notify_all(); + + // wait on closing thread + if (worker.joinable()) worker.join(); + + if (logFile.is_open()) + { + logFile.flush(); + logFile.close(); + } + + if(fileLockMutex) + { + CloseHandle(fileLockMutex); + fileLockMutex = NULL; + } + + if (newConsole) + { + if (consoleOut) + { + fclose(consoleOut); + consoleOut = nullptr; + } + + FreeConsole(); + newConsole = false; + } +} + +void vsid::Logger::toggleConsole() +{ + std::lock_guard lock(consoleMutex); + + if (!newConsole) + { + if (AllocConsole()) + { + newConsole = true; + + // disable close button to prevent ES closing + HWND hwnd = GetConsoleWindow(); + if (hwnd != NULL) + { + HMENU hMenu = GetSystemMenu(hwnd, FALSE); + if (hMenu != NULL) + { + DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND); + } + SetWindowTextA(hwnd, "Console Logger"); + } + + freopen_s(&consoleOut, "CONOUT$", "w", stdout); + + log(LogLevel::Info, "Console output enabled."); + } + } + else + { + log(LogLevel::Info, "Console output disabled."); + + if (consoleOut) + { + fclose(consoleOut); + consoleOut = nullptr; + } + + FreeConsole(); + newConsole = false; + } +} + +std::vector vsid::Logger::fetchEsMsgs() +{ + std::lock_guard lock(esMutex); + std::vector msgs; + + while (!esQueue.empty()) + { + msgs.push_back(std::move(esQueue.front())); + esQueue.pop(); + } + return msgs; +} + +void vsid::Logger::log(LogLevel level, const std::string_view& msg, std::optional debugLevel, bool devOnly) +{ + if (!running) return; + if (devOnly && !logDevOnly) return; + + { + std::lock_guard lock(bgMutex); + bgQueue.push(LogMessage{ level, std::string(msg), debugLevel }); + } + cv.notify_all(); +} + +void vsid::Logger::workerThread() +{ + while (running || !bgQueue.empty()) + { + LogMessage msg; + + // wait if queue is not empty or if worker is not running + { + std::unique_lock lock(bgMutex); + cv.wait(lock, [] { return !bgQueue.empty() || !running; }); + + if (!running && bgQueue.empty()) break; + + msg = std::move(bgQueue.front()); + bgQueue.pop(); + } + + // write log file + + if (logFile.is_open()) + { + // format file log message + std::string fout = std::format("[{:%Y-%m-%d %H:%M:%S}] [{}]", + vsid::time::getUtcNow(), logLvlToString(msg.level)); + + if (msg.level == LogLevel::Debug && msg.debugLevel.has_value()) + std::format_to(std::back_inserter(fout), " [{}]", debugLvlToString(msg.debugLevel.value())); + + std::format_to(std::back_inserter(fout), " {}\n", msg.msg); + + logFile << fout; + + if (logFile.fail()) // revive stream if log file was opened on the disk + logFile.clear(); + + if(msg.level >= LogLevel::Warning) + logFile.flush(); + + if (logFile.tellp() >= 10 * 1024 * 1024) rotateLogs(); // rotate if log file exceeds 10 MB + } + + // console output + { + std::lock_guard lock(consoleMutex); + + if (consoleOut) + { + // format console log message + std::string out = std::format("[{}] [{}]", + vsid::time::toTimeString(vsid::time::getUtcNow()), + logLvlToString(msg.level)); + + if (msg.level == LogLevel::Debug && msg.debugLevel.has_value()) + { + out += std::format(" [{}]", debugLvlToString(msg.debugLevel.value())); + } + + out += std::format(" {}\n", msg.msg); + + fputs(out.c_str(), consoleOut); + fflush(consoleOut); + } + } + + // push to ES queue + if(msg.level > LogLevel::Debug) { + std::lock_guard lock(esMutex); + esQueue.push(std::format("[{}] {}", logLvlToString(msg.level), msg.msg)); + } + } +} + +void vsid::Logger::rotateLogs() +{ + if (logFile.is_open()) + { + logFile.flush(); + logFile.close(); + } + + std::error_code ec; + + for (int i = 3; i >= 1; --i) + { + std::filesystem::path src = logFilePath.parent_path() / std::format("{}.{}{}", logFilePath.stem().string(), i, logFilePath.extension().string()); + std::filesystem::path dst = logFilePath.parent_path() / std::format("{}.{}{}", logFilePath.stem().string(), i + 1, logFilePath.extension().string()); + + if (std::filesystem::exists(src, ec)) + { + std::filesystem::remove(dst, ec); + std::filesystem::rename(src, dst, ec); + } + } + + std::filesystem::path firstLog = logFilePath.parent_path() / std::format("{}.1{}", logFilePath.stem().string(), logFilePath.extension().string()); + if (std::filesystem::exists(logFilePath, ec)) + { + std::filesystem::remove(firstLog, ec); + std::filesystem::rename(logFilePath, firstLog, ec); + } + + logFile.open(logFilePath, std::ios::trunc); +} + +void vsid::Logger::panicFlush() +{ + if (!running) return; + + if (logFile.is_open()) + logFile.flush(); + + if (bgMutex.try_lock()) + { + while (!bgQueue.empty()) + { + LogMessage& msg = bgQueue.front(); + + if (logFile.is_open()) + { + std::string fout = std::format("[{:%Y-%m-%d %H:%M:%S}] [CRASH DUMP] [{}]", + vsid::time::getUtcNow(), logLvlToString(msg.level)); + + if (msg.level == LogLevel::Debug && msg.debugLevel.has_value()) + fout += std::format(" [{}]", debugLvlToString(msg.debugLevel.value())); + + fout += std::format(" {}\n", msg.msg); + + logFile << fout; + } + bgQueue.pop(); + } + + if (logFile.is_open()) logFile.flush(); + + bgMutex.unlock(); + } +} \ No newline at end of file diff --git a/logger.h b/logger.h new file mode 100644 index 0000000..d7141b2 --- /dev/null +++ b/logger.h @@ -0,0 +1,203 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace vsid +{ + enum class LogLevel + { + Debug, + Info, + Warning, + Error + }; + + enum class DebugLevel { + Dev, + Menu, + Atc, + Sid, + Fpln, + Req, + Conf, + Rwy, + Area, + Ese, + Gen, + Func, + Sync + }; + + struct LogMessage { + LogLevel level; + std::string msg; + std::optional debugLevel; + }; + class Logger { + public: + + //************************************ + // Description: Initializes the logger by allocating a console and starting the worker thread + // Method: initialize + // FullName: vsid::Logger::initialize + // Access: public static + // Returns: void + // Qualifier: + //************************************ + static void initialize(); + + //************************************ + // Description: Shuts down the logger by stopping the worker thread and freeing the console + // Method: shutdown + // FullName: vsid::Logger::shutdown + // Access: public static + // Returns: void + // Qualifier: + //************************************ + static void shutdown(); + + //************************************ + // Description: Logs a message by pushing it into the msg queue to be processed by the worker thread + // Method: log + // FullName: vsid::Logger::log + // Access: public static + // Returns: void + // Qualifier: + // Parameter: LogLevel level + // Parameter: const std::string_view & msg + // Parameter: std::optional debugLevel + // Parameter: bool devOnly - if true, msg will only be logged if logDevOnly is true (devmode) + //************************************ + static void log(LogLevel level, const std::string_view& msg, std::optional debugLevel = std::nullopt, bool devOnly = false); + + //************************************ + // Description: Returns if the logger is running + // Method: isRunning + // FullName: vsid::Logger::isRunning + // Access: public static + // Returns: bool + // Qualifier: + //************************************ + inline static bool isRunning() { return running; }; + + //************************************ + // Descriptions: Gets all messages that are pending to be sent to ES (i.e. all messages in the esQueue) to use inside ES + // Method: fetchEsMsgs + // FullName: vsid::Logger::fetchEsMsgs + // Access: public static + // Returns: std::vector + // Qualifier: + //************************************ + static std::vector fetchEsMsgs(); + + //************************************ + // Description: Toggles the console on or off + // Method: toggleConsole + // FullName: vsid::Logger::toggleConsole + // Access: public static + // Returns: void + // Qualifier: + //************************************ + static void toggleConsole(); + + //************************************ + // Description: Flushes all pending log messages to the console immediately, used in crash situations to save pending log msgs + // Method: panicFlush + // FullName: vsid::Logger::panicFlush + // Access: public static + // Returns: void + // Qualifier: + //************************************ + static void panicFlush(); + + //************************************ + // Description: Sets whether only dev-level debug messages should be logged + // FullName: vsid::Logger::setLogDevOnly + // Access: public static + // Returns: void + // Qualifier: + // Parameter: bool devOnly + //************************************ + inline static void setLogDevOnly(bool devOnly) { logDevOnly = devOnly; } + + inline static bool getLogDevOnly() { return logDevOnly; } + + private: + + //************************************ + // Description: Worker thread function that continuously processes log messages from the queue and outputs them to the console + // Method: workerThread + // FullName: vsid::Logger::workerThread + // Access: private static + // Returns: void + // Qualifier: + //************************************ + static void workerThread(); + + inline static constexpr std::string_view logLvlToString(LogLevel lvl) + { + switch (lvl) + { + case LogLevel::Debug: return "DEBUG"; + case LogLevel::Info: return "INFO"; + case LogLevel::Warning: return "WARNING"; + case LogLevel::Error: return "ERROR"; + default: return "UNKNOWN"; + } + }; + + inline static constexpr std::string_view debugLvlToString(DebugLevel lvl) + { + switch (lvl) + { + case DebugLevel::Dev: return "DEV"; + case DebugLevel::Menu: return "MENU"; + case DebugLevel::Atc: return "ATC"; + case DebugLevel::Sid: return "SID"; + case DebugLevel::Fpln: return "FPLN"; + case DebugLevel::Req: return "REQ"; + case DebugLevel::Conf: return "CONF"; + case DebugLevel::Rwy: return "RWY"; + case DebugLevel::Area: return "AREA"; + case DebugLevel::Ese: return "ESE"; + case DebugLevel::Gen: return "GEN"; + case DebugLevel::Func: return "FUNC"; + case DebugLevel::Sync: return "SYNC"; + default: return "N/A"; + } + }; + + //************************************ + // Description: Rotates log files by flushing, closing and then opening a new file + // Method: rotateLogs + // FullName: vsid::Logger::rotateLogs + // Access: private static + // Returns: void + // Qualifier: + //************************************ + static void rotateLogs(); + + inline static bool logDevOnly; + inline static std::queue bgQueue; + inline static std::queue esQueue; + inline static HANDLE fileLockMutex{ NULL }; + inline static std::mutex bgMutex; + inline static std::mutex esMutex; + inline static std::mutex consoleMutex; + inline static std::condition_variable cv; + inline static std::thread worker; + inline static std::atomic running; + inline static bool newConsole; + inline static FILE* consoleOut; + inline static std::ofstream logFile; + inline static std::filesystem::path logFilePath; + }; +} From b1750b9f406b70d2cb87d0d30be3ea19d289af21 Mon Sep 17 00:00:00 2001 From: Phil7789 <87429599+Phil7789@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:40:29 +0200 Subject: [PATCH 3/4] Remove logging --- messageHandler.cpp | 61 ---------------------------------------------- messageHandler.h | 9 ------- 2 files changed, 70 deletions(-) diff --git a/messageHandler.cpp b/messageHandler.cpp index 5f50cff..eec5485 100644 --- a/messageHandler.cpp +++ b/messageHandler.cpp @@ -10,67 +10,6 @@ vsid::MessageHandler::MessageHandler() {} vsid::MessageHandler::~MessageHandler() { this->closeConsole(); } -void vsid::MessageHandler::writeMessage(std::string sender, std::string msg, DebugArea debugArea) -{ - if (sender == "DEBUG" && this->getLevel() != Level::Debug) return; - - try - { - if (this->currentLevel == Level::Debug && (this->debugArea == debugArea || this->debugArea == DebugArea::All) && sender == "DEBUG") - { - std::string area; - if (debugArea == DebugArea::Atc) area = "ATC"; - else if (debugArea == DebugArea::Conf) area = "CONF"; - else if (debugArea == DebugArea::Dev) area = "DEV"; - else if (debugArea == DebugArea::Req) area = "REQ"; - else if (debugArea == DebugArea::Rwy) area = "RWY"; - else if (debugArea == DebugArea::Sid) area = "SID"; - else if (debugArea == DebugArea::Menu) area = "MENU"; - else if (debugArea == DebugArea::Fpln) area = "FPLN"; - else area = "N/A"; - - std::cout << "[" << vsid::time::toTimeString(vsid::time::getUtcNow()) << "] [" << area << "] " << msg << '\n'; - } - else if (/*this->currentLevel != Level::Debug && */sender != "DEBUG") this->msg.push_back(std::pair(sender, msg)); - } - catch (std::exception& e) - { - this->msg.push_back(std::pair("ERROR", e.what())); - } - -} - -void vsid::MessageHandler::writeMessage(std::string sender, std::string msg, const std::source_location& loc, DebugArea debugArea) -{ - if (sender == "DEBUG" && this->getLevel() != Level::Debug) return; - - try - { - if (this->currentLevel == Level::Debug && (this->debugArea == debugArea || this->debugArea == DebugArea::All) && sender == "DEBUG") - { - std::string area; - if (debugArea == DebugArea::Atc) area = "ATC"; - else if (debugArea == DebugArea::Conf) area = "CONF"; - else if (debugArea == DebugArea::Dev) area = "DEV"; - else if (debugArea == DebugArea::Req) area = "REQ"; - else if (debugArea == DebugArea::Rwy) area = "RWY"; - else if (debugArea == DebugArea::Sid) area = "SID"; - else if (debugArea == DebugArea::Menu) area = "MENU"; - else if (debugArea == DebugArea::Fpln) area = "FPLN"; - else area = "N/A"; - - std::cout << "[" << vsid::time::toTimeString(vsid::time::getUtcNow()) << "] [" << area << "] " << msg - << " | file: " << loc.file_name() << " | func: " << loc.function_name() << " | " << " line: " << loc.line() << '\n'; - } - else if (/*this->currentLevel != Level::Debug && */sender != "DEBUG") this->msg.push_back(std::pair(sender, msg)); - } - catch (std::exception& e) - { - this->msg.push_back(std::pair("ERROR", e.what())); - } - -} - std::pair vsid::MessageHandler::getMessage() { if (this->msg.size() > 0) diff --git a/messageHandler.h b/messageHandler.h index 0453bce..f0fbb89 100644 --- a/messageHandler.h +++ b/messageHandler.h @@ -62,15 +62,6 @@ namespace vsid Dev }; - /** - * @brief Writes message to the local storage - this can be used to forward messages to ES chat - * - * @param sender front of msg, usually a level of DEBUG, ERROR, WARNING, INFO - * @param msg - */ - void writeMessage(std::string sender, std::string msg, DebugArea debugArea = DebugArea::All); - - void writeMessage(std::string sender, std::string msg, const std::source_location& loc, DebugArea debugArea = DebugArea::All); /** * @brief Retrieve the first message from the local message stack * From d3a0a887fb3d5946620c8b33322dfda7e43c65a3 Mon Sep 17 00:00:00 2001 From: Phil7789 <87429599+Phil7789@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:41:31 +0200 Subject: [PATCH 4/4] Update to new logger --- area.cpp | 13 +- configparser.cpp | 135 +++--- configparser.h | 1 + crashhandler.h | 4 + display.cpp | 72 ++- eseparser.cpp | 40 +- flightplan.cpp | 64 +-- menu.cpp | 284 ++++++----- menu.h | 26 +- timeHandler.cpp | 5 +- utils.cpp | 12 +- vSIDPlugin.cpp | 1152 ++++++++++++++++++++++---------------------- vSIDPlugin.h | 16 +- versionchecker.cpp | 35 +- 14 files changed, 949 insertions(+), 910 deletions(-) diff --git a/area.cpp b/area.cpp index b561d47..e0ccfba 100644 --- a/area.cpp +++ b/area.cpp @@ -3,9 +3,11 @@ #include "area.h" #include "messageHandler.h" #include "utils.h" +#include "logger.h" #include #include +#include vsid::Area::Area(std::vector> &coords, bool isActive, bool arrAsDep) { @@ -13,8 +15,8 @@ vsid::Area::Area(std::vector> &coords, bool { if(coord.first.empty() || coord.second.empty()) { - messageHandler->writeMessage("WARNING", "Empty coordinate string found (first: \"" + coord.first + - "\" / second: \"" + coord.second + "\"! Skipping coordinate."); + vsid::Logger::log(vsid::LogLevel::Warning, std::format("Empty coordinate string found (first: [{}] / second: [{}]! Skipping coordinate.", + coord.first, coord.second)); continue; } this->points.push_back(toPoint(coord)); @@ -43,16 +45,13 @@ void vsid::Area::showline() { for (auto& line : this->lines) { - messageHandler->writeMessage("DEBUG", "line: " + std::to_string(line.first.lon) + ":" + std::to_string(line.first.lat) + " - " + - std::to_string(line.second.lon) + "." + std::to_string(line.second.lat)); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("area line: {}:{} - {}:{}", + line.first.lon, line.first.lat, line.second.lon, line.second.lat), vsid::DebugLevel::Area); } } vsid::Area::Point vsid::Area::toPoint(std::pair &pos) { - /*double lat = toDeg(pos.first); - double lon = toDeg(pos.second);*/ - double lat = vsid::utils::toDeg(pos.first); double lon = vsid::utils::toDeg(pos.second); diff --git a/configparser.cpp b/configparser.cpp index 17776e2..67a7b4c 100644 --- a/configparser.cpp +++ b/configparser.cpp @@ -5,9 +5,11 @@ #include "messageHandler.h" #include "sid.h" #include "constants.h" +#include "logger.h" #include #include +#include vsid::ConfigParser::ConfigParser() { @@ -30,20 +32,20 @@ void vsid::ConfigParser::loadMainConfig() } catch(const json::parse_error &e) { - messageHandler->writeMessage("ERROR", "Failed to parse main config: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to parse main config: " + std::string(e.what())); } catch (const json::type_error& e) { - messageHandler->writeMessage("ERROR", "Failed to parse main config: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to parse main config: " + std::string(e.what())); } catch (const json::other_error& e) { - messageHandler->writeMessage("ERROR", "Failed to parse main config: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to parse main config: " + std::string(e.what())); } if (this->vSidConfig.is_null()) { - messageHandler->writeMessage("ERROR", "Failed to parse main config. (Critical!)"); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to parse main config. (Critical!)"); return; } @@ -55,8 +57,14 @@ void vsid::ConfigParser::loadMainConfig() this->notifyUpdate = this->vSidConfig.value("notifyUpdate", 1); + // set hand over warning altitude + this->hovWarningAlt = this->vSidConfig.value("hovWarningAlt", 1500); + // set logging of dev only messages + + this->logDevOnly = this->vSidConfig.value("logDevOnly", false); + try { // import colors or set default values @@ -365,23 +373,23 @@ void vsid::ConfigParser::loadMainConfig() } catch (std::error_code& e) { - messageHandler->writeMessage("ERROR", "Failed to import colors: " + e.message()); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to import colors: " + e.message()); } catch (const json::parse_error& e) { - messageHandler->writeMessage("ERROR", "[Parse Error] in color config section: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "[Parse Error] in color config section: " + std::string(e.what())); } catch (const json::type_error& e) { - messageHandler->writeMessage("ERROR", "[Type Error] in color config section: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "[Type Error] in color config section: " + std::string(e.what())); } catch (const json::other_error& e) { - messageHandler->writeMessage("ERROR", "[Other Error] in color config section: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "[Other Error] in color config section: " + std::string(e.what())); } catch (const json::out_of_range& e) { - messageHandler->writeMessage("ERROR", "[Out of Range] in color config section: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "[Out of Range] in color config section: " + std::string(e.what())); } // get request times @@ -393,7 +401,7 @@ void vsid::ConfigParser::loadMainConfig() } catch (json::parse_error& e) { - messageHandler->writeMessage("ERROR", "Failed to get request timers: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to get request timers: " + std::string(e.what())); } // get clrf min values @@ -407,7 +415,7 @@ void vsid::ConfigParser::loadMainConfig() } catch (json::out_of_range& e) { - messageHandler->writeMessage("ERROR", "Failed to get clrf min values: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to get clrf min values: " + std::string(e.what())); } // get indicator reference values @@ -420,7 +428,7 @@ void vsid::ConfigParser::loadMainConfig() } catch (json::out_of_range& e) { - messageHandler->writeMessage("ERROR", "Failed to get indicator default reference values: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to get indicator default reference values: " + std::string(e.what())); } } @@ -444,13 +452,13 @@ void vsid::ConfigParser::loadAirportConfig(std::map } else { - messageHandler->writeMessage("ERROR", "No config path for airports in main config"); + vsid::Logger::log(vsid::LogLevel::Error, "No config path for airports in main config"); return; } if (!std::filesystem::exists(basePath)) { - messageHandler->writeMessage("ERROR", "No airport config folder found at: " + basePath.string()); + vsid::Logger::log(vsid::LogLevel::Error, "No airport config folder found at: " + basePath.string()); return; } @@ -559,17 +567,18 @@ void vsid::ConfigParser::loadAirportConfig(std::map if (lat == "" || lon == "") { - messageHandler->writeMessage("ERROR", "Couldn't read LAT or LON value for \"" + - coord.key() + "\" in area \"" + area.key() + "\" at \"" + - icao + "\""); + vsid::Logger::log(vsid::LogLevel::Error, + std::format("Couldn't read LAT or LON value for [{}] in area [{}] at [{}]", + coord.key(), area.key(), icao)); break; } coords.push_back({ lat, lon }); } if (coords.size() < 3) { - messageHandler->writeMessage("ERROR", "Area \"" + area.key() + "\" in \"" + - icao + "\" has not enough points configured (less than 3)."); + vsid::Logger::log(vsid::LogLevel::Error, + std::format("Area [{}] in [{}] has not enough points configured (less than 3).", + area.key(), icao)); continue; } if (savedAreas.contains(icao)) @@ -732,8 +741,8 @@ void vsid::ConfigParser::loadAirportConfig(std::map fieldSetting.base = sidField.key().substr(0, sidField.key().length() - 1); fixedNumber = sidField.key().back(); - messageHandler->writeMessage("DEBUG", "[" + sidField.key() + "] contained a number - setting as fixed SID number: " + - fixedNumber, vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] contained a number - setting as fixed SID number [{}]", + sidField.key(), fixedNumber), vsid::DebugLevel::Conf); } else { @@ -1190,26 +1199,26 @@ void vsid::ConfigParser::loadAirportConfig(std::map if (newSid.timeFrom != -1 && newSid.timeTo != -1) aptInfo.timeSids.push_back(newSid); // #dev - debugging msgs for evaluation of sid restriction levels - std::string sidName = newSid.base + ((newSid.number.empty()) ? "_" : newSid.number) + newSid.designator + " (ID: " + newSid.id + ")"; - messageHandler->writeMessage("DEBUG", "[" + sidName + "] wpt: " + newSid.waypoint, vsid::MessageHandler::DebugArea::Conf); + std::string sidName = std::format("{}{}{} (ID: {})", newSid.base, (newSid.number.empty()) ? "_" : newSid.number, newSid.designator, newSid.id); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] wpt: {}", sidName, newSid.waypoint), vsid::DebugLevel::Conf); for (auto& [_, trans] : newSid.transition) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] trans: " + trans.base + "_" + trans.designator, vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] trans: {}", sidName, trans.base + "_" + trans.designator), vsid::DebugLevel::Conf); } - messageHandler->writeMessage("DEBUG", "[" + sidName + "] rwys: " + vsid::utils::join(newSid.rwys, ','), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] rwys: {}", sidName, vsid::utils::join(newSid.rwys, ',')), vsid::DebugLevel::Conf); for (auto& [sEquip, allow] : newSid.equip) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] equip: " + sEquip + " allowed " + ((allow) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] equip: {} allowed {}", sidName, sEquip, (allow) ? "TRUE" : "FALSE"), vsid::DebugLevel::Conf); } - messageHandler->writeMessage("DEBUG", "[" + sidName + "] initial: " + std::to_string(newSid.initialClimb), vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] via: " + ((newSid.climbvia) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] prio: " + std::to_string(newSid.prio), vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] pilotfiled: " + ((newSid.pilotfiled) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] initialClimb: {}", sidName, newSid.initialClimb), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] climb via: {}", sidName, (newSid.climbvia) ? "TRUE" : "FALSE"), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] prio: {}", sidName, newSid.prio), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] pilotfiled: {}", sidName, (newSid.pilotfiled) ? "TRUE" : "FALSE"), vsid::DebugLevel::Conf); for (auto& [actArrList, arrType] : newSid.actArrRwy) { for(auto& [arrWhich, actArr] : arrType) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] actArrRwy: " + actArrList + " - " + arrWhich + " - " + actArr, vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] actArrRwy: {} - {} - {}", sidName, actArrList, arrWhich, actArr), vsid::DebugLevel::Conf); } } @@ -1217,36 +1226,36 @@ void vsid::ConfigParser::loadAirportConfig(std::map { for (auto& [depWhich, actDep] : depType) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] actDepRwy: " + actDepList + " - " + depWhich + " - " + actDep, vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] actDepRwy: {} - {} - {}", sidName, actDepList, depWhich, actDep), vsid::DebugLevel::Conf); } } - messageHandler->writeMessage("DEBUG", "[" + sidName + "] wtc: " + newSid.wtc, vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] engType: " + newSid.engineType, vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] wingType: " + newSid.wingType, vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] wtc: {}", sidName, newSid.wtc), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] engType: {}", sidName, newSid.engineType), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] wingType: {}", sidName, newSid.wingType), vsid::DebugLevel::Conf); for (auto& [sAcftType, allow] : newSid.acftType) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] acftType: " + sAcftType + " allowed " + ((allow) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] acftType: {} allowed {}", sidName, sAcftType, (allow) ? "TRUE" : "FALSE"), vsid::DebugLevel::Conf); } - messageHandler->writeMessage("DEBUG", "[" + sidName + "] engCount: " + std::to_string(newSid.engineCount), vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] mtow: " + std::to_string(newSid.mtow), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] engCount: {}", sidName, newSid.engineCount), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] mtow: {}", sidName, newSid.mtow), vsid::DebugLevel::Conf); for (auto& [sDest, allow] : newSid.dest) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] dest: " + sDest + " allow " + ((allow) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] dest: {} allow {}", sidName, sDest, (allow) ? "TRUE" : "FALSE"), vsid::DebugLevel::Conf); } for (auto& [allow, routeList] : newSid.route) { for (auto& [sId, sRoute] : routeList) { - messageHandler->writeMessage("DEBUG", "[" + sidName + "] route: " + allow + " id: " + - sId + " routing: " + vsid::utils::join(sRoute, ','), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] route [{}] id [{}] routing [{}]", + sidName, allow, sId, vsid::utils::join(sRoute, ',')), vsid::DebugLevel::Conf); } } - messageHandler->writeMessage("DEBUG", "[" + sidName + "] rule: " + newSid.customRule, vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] area: " + newSid.area, vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] lvp: " + std::to_string(newSid.lvp), vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] timeFrom: " + std::to_string(newSid.timeFrom), vsid::MessageHandler::DebugArea::Conf); - messageHandler->writeMessage("DEBUG", "[" + sidName + "] timeTo: " + std::to_string(newSid.timeTo), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] rule: {}", sidName, newSid.customRule), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] area: {}", sidName, newSid.area), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] lvp: {}", sidName, newSid.lvp), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] timeFrom: {}", sidName, newSid.timeFrom), vsid::DebugLevel::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] timeTo: {}", sidName, newSid.timeTo), vsid::DebugLevel::Conf); // end dev - debugging msgs for sid restriction levels } } @@ -1258,23 +1267,23 @@ void vsid::ConfigParser::loadAirportConfig(std::map } catch (const json::parse_error& e) { - messageHandler->writeMessage("ERROR", "[Parse] Failed to load airport config (" + icao + "): " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[Parse] Failed to load airport config ({}): {}", icao, e.what())); } catch (const json::type_error& e) { - messageHandler->writeMessage("ERROR", "[Type] Failed to load airport config (" + icao + "): " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[Type] Failed to load airport config ({}): {}", icao, e.what())); } catch (const json::out_of_range& e) { - messageHandler->writeMessage("ERROR", "[Range] Failed to load airport config (" + icao + "): " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[Range] Failed to load airport config ({}): {}", icao, e.what())); } catch (const json::other_error& e) { - messageHandler->writeMessage("ERROR", "[Other] Failed to load airport config (" + icao + "): " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[Other] Failed to load airport config ({}): {}", icao, e.what())); } catch (const std::exception &e) { - messageHandler->writeMessage("ERROR", "Failure in config (" + icao + "): " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failure in config ({}): {}", icao, e.what())); } /* DOCUMENTATION on how to get all values below a key @@ -1294,7 +1303,7 @@ void vsid::ConfigParser::loadAirportConfig(std::map if (aptConfig.contains(it->first)) ++it; else { - messageHandler->writeMessage("INFO", "No config found for: " + it->first); + vsid::Logger::log(vsid::LogLevel::Info, "No config found for: " + it->first); it = activeAirports.erase(it); } } @@ -1315,7 +1324,7 @@ void vsid::ConfigParser::loadGrpConfig() if (!std::filesystem::exists(basePath)) { - messageHandler->writeMessage("ERROR", "No grp config found in: " + basePath.string()); + vsid::Logger::log(vsid::LogLevel::Error, "No grp config found in: " + basePath.string()); return; } for (const std::filesystem::path& entry : std::filesystem::directory_iterator(basePath)) @@ -1332,11 +1341,11 @@ void vsid::ConfigParser::loadGrpConfig() } catch (const json::parse_error& e) { - messageHandler->writeMessage("ERROR:", "Failed to load grp config: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to load grp config: {}", e.what())); } catch (const json::type_error& e) { - messageHandler->writeMessage("ERROR:", "Failed to load grp config: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to load grp config: {}", e.what())); } } } @@ -1357,7 +1366,7 @@ void vsid::ConfigParser::loadRnavList() if (!std::filesystem::exists(basePath)) { - messageHandler->writeMessage("ERROR", "Path to check for RNAV List does not exist: " + basePath.string()); + vsid::Logger::log(vsid::LogLevel::Error, "Path to check for RNAV List does not exist: " + basePath.string()); return; } @@ -1375,16 +1384,16 @@ void vsid::ConfigParser::loadRnavList() } catch (const json::parse_error& e) { - messageHandler->writeMessage("ERROR:", "Failed to load rnav list: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to load rnav list: {}", e.what())); } catch (const json::type_error& e) { - messageHandler->writeMessage("ERROR:", "Failed to load rnav list: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to load rnav list: {}", e.what())); } if (rnavConfigFile.empty()) { - messageHandler->writeMessage("ERROR", "RNAV List is empty. Is it present besides the plugin DLL file?"); + vsid::Logger::log(vsid::LogLevel::Error, "RNAV List is empty. Is it present besides the plugin DLL file?"); return; } @@ -1394,12 +1403,12 @@ void vsid::ConfigParser::loadRnavList() } catch (json::type_error &e) { - messageHandler->writeMessage("ERROR", "Failed to read rnav list: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to read rnav list: {}", e.what())); } return; } - messageHandler->writeMessage("ERROR", "No RNAV capable list found at: " + basePath.string()); + vsid::Logger::log(vsid::LogLevel::Error, "No RNAV capable list found at: " + basePath.string()); } const COLORREF vsid::ConfigParser::getColor(std::string color) @@ -1414,7 +1423,7 @@ const COLORREF vsid::ConfigParser::getColor(std::string color) { if (!messageHandler->genErrorsContains(ERROR_CONF_COLOR + "_" + color)) { - messageHandler->writeMessage("ERROR", "Failed to retrieve color: \"" + color + "\". Code: " + ERROR_CONF_COLOR); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to retrieve color: [{}]. Code: {}", color, ERROR_CONF_COLOR)); messageHandler->addGenError(ERROR_CONF_COLOR + "_" + color); } // return purple if color could not be found to signal error @@ -1431,7 +1440,7 @@ int vsid::ConfigParser::getReqTime(std::string time) } else { - messageHandler->writeMessage("ERROR", "Failed to retrieve request time setting for key \"" + time + "\""); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to retrieve request time setting for key [{}]", time)); return 0; } } diff --git a/configparser.h b/configparser.h index 8735b5c..79a9687 100644 --- a/configparser.h +++ b/configparser.h @@ -162,6 +162,7 @@ namespace vsid bool preferTopsky; int notifyUpdate; int hovWarningAlt; + bool logDevOnly; private: std::set configPaths; diff --git a/crashhandler.h b/crashhandler.h index 9dcdc92..dc2245c 100644 --- a/crashhandler.h +++ b/crashhandler.h @@ -7,6 +7,8 @@ #include #include +#include "logger.h" + #include "include/es/EuroScopePlugIn.h" // expose plug-in entry point for crash handler to identify vsid module @@ -46,6 +48,8 @@ namespace vsid //************************************ inline LONG WINAPI vSIDCrashHandler(EXCEPTION_POINTERS* exceptionInfo) { + vsid::Logger::panicFlush(); // flush logs to file in case of crash + PVOID crashAdress = exceptionInfo->ExceptionRecord->ExceptionAddress; // get the crashed module diff --git a/display.cpp b/display.cpp index 9f4507b..9715e25 100644 --- a/display.cpp +++ b/display.cpp @@ -5,8 +5,10 @@ #include "constants.h" #include "messageHandler.h" #include "utils.h" +#include "logger.h" #include +#include vsid::Display::Display(int id, std::shared_ptr plugin, const std::string name) : EuroScopePlugIn::CRadarScreen() { @@ -14,7 +16,9 @@ vsid::Display::Display(int id, std::shared_ptr plugin, const s this->plugin = plugin; this->name = name; } -vsid::Display::~Display() { messageHandler->writeMessage("DEBUG", "Removed display with id: " + std::to_string(this->id), vsid::MessageHandler::DebugArea::Menu); } +vsid::Display::~Display() { + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Removed display with id: {}", this->id), vsid::DebugLevel::Menu); +} void vsid::Display::OnAsrContentLoaded(bool loaded) { @@ -28,11 +32,11 @@ void vsid::Display::OnAsrContentToBeClosed() if (std::shared_ptr sharedPlugin = this->plugin.lock()) { - messageHandler->writeMessage("DEBUG", "Removing display with id: " + std::to_string(this->id) + " from saved displays.", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Removing display with id [{}] from saved displays.", this->id), vsid::DebugLevel::Menu); sharedPlugin->deleteScreen(this->id); } - else messageHandler->writeMessage("ERROR", "Could not remove display id: " + std::to_string(this->id) + - " from vSID as vSID is already destroyed. Code: " + ERROR_DSP_REMOVE); + else vsid::Logger::log(vsid::LogLevel::Error, std::format("Could not remove display id [{}] from vSID as vSID is already destroyed. Code: {}", + this->id, ERROR_DSP_REMOVE)); //delete this; } @@ -78,8 +82,8 @@ void vsid::Display::OnRefresh(HDC hDC, int Phase) { if (!messageHandler->genErrorsContains(ERROR_CONF_DISPLAY)) { - messageHandler->writeMessage("ERROR", "[Range] Missing config section during display refresh: " + - std::string(e.what()) + ". Code: " + ERROR_CONF_DISPLAY); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[Range] Missing config section during display refresh: {}. Code: {}", + std::string(e.what()), ERROR_CONF_DISPLAY)); messageHandler->addGenError(ERROR_CONF_DISPLAY); } } @@ -359,8 +363,9 @@ void vsid::Display::OnRefresh(HDC hDC, int Phase) { if (!messageHandler->genErrorsContains(ERROR_DSP_COUNTICAO + mMenu.getTitle())) { - messageHandler->writeMessage("ERROR", "Failed to get ICAO from menu title " + - mMenu.getTitle() + " while counting startups. Code: " + ERROR_DSP_COUNTICAO); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to get ICAO from menu title [{}] while counting startups. Code: {}", + mMenu.getTitle(), ERROR_DSP_COUNTICAO)); + messageHandler->addGenError(ERROR_DSP_COUNTICAO + mMenu.getTitle()); } } @@ -396,8 +401,9 @@ void vsid::Display::OnRefresh(HDC hDC, int Phase) { if (!messageHandler->genErrorsContains(ERROR_DSP_COUNTRMICAO + mMenu.getTitle())) { - messageHandler->writeMessage("ERROR", "Failed to retrieve icao from menu " + mMenu.getTitle() + - " during departure count check. Code: " + ERROR_DSP_COUNTRMICAO); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to retrieve icao from menu [{}] during departure count check. Code: {}", + mMenu.getTitle(), ERROR_DSP_COUNTRMICAO)); + messageHandler->addGenError(ERROR_DSP_COUNTRMICAO + mMenu.getTitle()); } } @@ -511,10 +517,10 @@ void vsid::Display::OnClickScreenObject(int ObjectType, const char* sObjectId, P } else { - messageHandler->writeMessage("DEBUG", "menus doesn't contain " + std::string(sObjectId) + " elems are:", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Menus doesn't contain [{}]. Elements are:", std::string(sObjectId))); for (auto &[title, _] : this->menues) { - messageHandler->writeMessage("DEBUG", "menu title: " + title, vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("menu title [{}]", title), vsid::DebugLevel::Menu); } } @@ -543,8 +549,8 @@ void vsid::Display::OnClickScreenObject(int ObjectType, const char* sObjectId, P } else { - messageHandler->writeMessage("ERROR", "Couldn't close menu, because menu title couldn't be extracted from button " + - std::string(sObjectId) + ". Code: " + ERROR_DSP_BTNEXTTITLE); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Couldn't close menu, because menu title couldn't be extracted from button [{}]. Code: {}", + std::string(sObjectId), ERROR_DSP_BTNEXTTITLE)); } } } @@ -567,7 +573,7 @@ bool vsid::Display::OnCompileCommand(const char* sCommandLine) { if (!sharedPlugin->getActiveApts().contains(params[2])) { - messageHandler->writeMessage("INFO", "[" + params[2] + "] is not an active airport. Cannot open menu."); + vsid::Logger::log(vsid::LogLevel::Info, std::format("[{}] is not an active airport. Cannot open menu.", params[2])); return true; } @@ -581,7 +587,7 @@ bool vsid::Display::OnCompileCommand(const char* sCommandLine) if (std::string(sCommandLine) == ".vsid display config") { - messageHandler->writeMessage("INFO", "Zoom-Level: " + std::to_string(this->getZoomLevel())); + vsid::Logger::log(vsid::LogLevel::Info, std::format("Zoom-Level [{}]", this->getZoomLevel())); return true; } return false; @@ -589,13 +595,13 @@ bool vsid::Display::OnCompileCommand(const char* sCommandLine) void vsid::Display::OnAirportRunwayActivityChanged() { - messageHandler->writeMessage("DEBUG", "[MENU] Activity Changed()", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, "[MENU] Runway Activity Changed()", vsid::DebugLevel::Menu); if (this->menues.empty()) return; if (std::shared_ptr sharedPlugin = this->plugin.lock()) { - messageHandler->writeMessage("DEBUG", "[MENU] Shared Ptr valid.", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, "[MENU] Shared Ptr valid.", vsid::DebugLevel::Menu, true); // re-create mainmenu @@ -605,7 +611,7 @@ void vsid::Display::OnAirportRunwayActivityChanged() for (const auto&[title,menu] : this->menues) { - messageHandler->writeMessage("DEBUG", "[" + title + "] is checked on runway change", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] is checked on runway change", title), vsid::DebugLevel::Menu); if (title == std::string("mainmenu")) { CPoint topLeft = this->menues["mainmenu"].topLeft(); @@ -615,19 +621,11 @@ void vsid::Display::OnAirportRunwayActivityChanged() } else if (title.find("startupmenu_") != std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + title + "] storing startup menu", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] storing startup menu", title), vsid::DebugLevel::Menu); this->reopenStartup.insert({title, { menu.topLeft(), menu.getParent(), menu.getRender() }}); } } - /*if (this->menues.contains("mainmenu")) - { - CPoint topLeft = this->menues["mainmenu"].topLeft(); - top = topLeft.y; - left = topLeft.x; - render = this->menues["mainmenu"].getRender(); - }*/ - this->removeMenu("mainmenu"); this->openMainMenu(top, left, render); @@ -638,7 +636,7 @@ void vsid::Display::OnAirportRunwayActivityChanged() { try { - messageHandler->writeMessage("DEBUG", "[" + title + "] reopening startup menu", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] reopening startup menu", title), vsid::DebugLevel::Menu); std::string apt = vsid::utils::split(title, '_').at(1); if (!sharedPlugin->getActiveApts().contains(apt)) continue; @@ -647,8 +645,7 @@ void vsid::Display::OnAirportRunwayActivityChanged() } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Failed to get apt ICAO while re-opening startup menu \"" + title + - "\". Code: " + ERROR_DSP_REOPENICAO); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to get apt ICAO while re-opening startup menu [{}]. Code: {}", title, ERROR_DSP_REOPENICAO)); } } @@ -656,7 +653,7 @@ void vsid::Display::OnAirportRunwayActivityChanged() this->reopenStartup.clear(); } } - else messageHandler->writeMessage("ERROR", "Couldn't update active airports for screen as plugin couldn't be accessed. Code: " + ERROR_DSP_PLUGACCESS); + else vsid::Logger::log(vsid::LogLevel::Error, "Couldn't update active airports for screen as plugin couldn't be accessed. Code: {}" + ERROR_DSP_PLUGACCESS, vsid::DebugLevel::Menu); } void vsid::Display::openMainMenu(int top, int left, bool render) @@ -690,7 +687,7 @@ void vsid::Display::openMainMenu(int top, int left, bool render) for (auto& [title, apt] : this->plugin.lock()->getActiveApts()) { - messageHandler->writeMessage("DEBUG", "Button add for apt: " + title); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Add airport button for [{}]", title), vsid::DebugLevel::Menu, true); newMenu.addButton(MENU_BUTTON, "apt_" + title, newMenu.getArea(), title, 20, 20, 400, { 5, 5, 5, 5 }); } @@ -738,8 +735,7 @@ void vsid::Display::openStartupMenu(const std::string apt, const std::string par this->menues.insert({ title, std::move(newMenu) }); } - else messageHandler->writeMessage("ERROR", "Tried to create startup menu for [" + apt + - "] but plugin couldn't be accessed. Code: " + ERROR_DSP_MENUSUCREATE); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Tried to create startup menu for [{}] but plugin couldn't be accessed. Code: {}", apt, ERROR_DSP_MENUSUCREATE)); } void vsid::Display::removeMenu(const std::string &title) @@ -752,15 +748,13 @@ void vsid::Display::removeMenu(const std::string &title) } this->menues.erase(title); } - else messageHandler->writeMessage("ERROR", "Called to remove menu [" + title + - "] but it wasn't found in the menues list. Code: " + ERROR_DSP_RMMENU); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Called to remove menu [{}] but it wasn't found in the menues list. Code: {}", title, ERROR_DSP_RMMENU)); } void vsid::Display::closeMenu(const std::string &title) { if (this->menues.contains(title)) this->menues[title].toggleRender(); - else messageHandler->writeMessage("ERROR", "Couldn't close menu " + title + - " because it is not in the menu list. Code: " + ERROR_DSP_RMMENU); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Couldn't close menu [{}] because it is not in the menu list. Code: {}", title, ERROR_DSP_RMMENU)); } EuroScopePlugIn::CPosition vsid::Display::calculateIndicatorMeterOffset(double lat, double lon, double offset, double deg) diff --git a/eseparser.cpp b/eseparser.cpp index 3240034..1c524c7 100644 --- a/eseparser.cpp +++ b/eseparser.cpp @@ -2,15 +2,18 @@ #include "eseparser.h" #include "flightplan.h" +#include "logger.h" + +#include void vsid::EseParser::parseEse(const std::filesystem::path& path) { - messageHandler->writeMessage("DEBUG", "Ese path to parse: \"" + path.string() + "\"", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Debug, "Path to .ese for parsing: " + path.string(), vsid::DebugLevel::Conf); std::ifstream in(path); if (!in) { - messageHandler->writeMessage("ERROR", "Failed to open .ese file in path: " + path.string()); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to open .ese file in path: " + path.string()); return; } @@ -87,11 +90,9 @@ void vsid::EseParser::line(Section s, std::string_view l) { if (visLat.empty() || visLon.empty()) { - messageHandler->writeMessage("WARNING", "Empty coordinate string found for ATC station \"" + atcVec.at(0) + - "\" vis point (lat: \"" + visLat + "\" / lon: \"" + visLon + "\"! Skipping coordinate."); - - messageHandler->writeMessage("DEBUG", "[ESE] empty vispoint lat (\"" + visLat + "\" / lon (\"" + visLon + - "\" in line : " + std::string(l), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(vsid::LogLevel::Warning, std::format("Empty coordinate string found for ATC station [{}] vis point (lat [{}] lon [{}]! Skipping coordinate.", + atcVec.at(0), visLat, visLon)); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[ESE] vis point in line : {}", l), vsid::DebugLevel::Conf); ++idx; continue; @@ -141,7 +142,7 @@ void vsid::EseParser::line(Section s, std::string_view l) } catch (std::out_of_range& e) { - messageHandler->writeMessage("ERROR", "Failed to parse ATC: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, "Failed to parse ATC: " + std::string(e.what())); } break; @@ -160,13 +161,10 @@ void vsid::EseParser::line(Section s, std::string_view l) auto [sid, trans] = vsid::fplnhelper::splitTransition(currSid); - messageHandler->writeMessage("DEBUG", "[ESE] Parsing SID \"" + currSid + "\" - sid: " + sid + " / trans : " + trans, vsid::MessageHandler::DebugArea::Dev); - - //const bool lastIsDigit = vsid::utils::lastIsDigit(sid); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Parsing SID [{}] - sid: [{}] / trans : [{}]", currSid, sid, trans), vsid::DebugLevel::Ese, true); vsid::SectionTransition sectionTrans("", std::nullopt, std::nullopt); - vsid::SectionSID sectionSid("", "", '\0', std::nullopt, "", sectionTrans, ""); - + vsid::SectionSID sectionSid("", "", '\0', std::nullopt, "", sectionTrans, ""); if (!sid.empty()) { @@ -213,17 +211,17 @@ void vsid::EseParser::line(Section s, std::string_view l) sectionSid.trans = std::move(sectionTrans); - messageHandler->writeMessage("DEBUG", "[ESE] Stored value: [" + sectionSid.base + sectionSid.number + - ((sectionSid.desig) ? std::string(1, *sectionSid.desig) : "") + - "] and trans: [" + sectionSid.trans.base + ((sectionSid.trans.number) ? std::string(1, *sectionSid.trans.number) : "") + - ((sectionSid.trans.desig) ? std::string(1, *sectionSid.trans.desig) : "") + "]", - vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Stored SID [{}{}{}] and transition: [{}{}{}]", + sectionSid.base, sectionSid.number, (sectionSid.desig) ? std::string(1, *sectionSid.desig) : "", + sectionSid.trans.base, (sectionSid.trans.number) ? std::string(1, *sectionSid.trans.number) : "", + (sectionSid.trans.desig) ? std::string(1, *sectionSid.trans.desig) : ""), + vsid::DebugLevel::Ese, true); this->sectionSids_.emplace(std::move(sectionSid)); } catch (const std::out_of_range& e) { - messageHandler->writeMessage("ERROR", "Failed to parse SID: " + std::string(e.what()) + " in line: " + std::string(l)); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to parse SID [{}] in .ese line [{}]", e.what(), l)); } break; @@ -239,10 +237,10 @@ void vsid::EseParser::exit(Section s) switch (s) { case Section::Positions: - messageHandler->writeMessage("INFO", "Parsed " + std::to_string(this->sectionAtc_.size()) + " atc stations."); + vsid::Logger::log(vsid::LogLevel::Info, std::format("Parsed {} atc stations.", this->sectionAtc_.size())); break; case Section::SidsStars: - messageHandler->writeMessage("INFO", "Parsed " + std::to_string(this->sectionSids_.size()) + " SIDs."); + vsid::Logger::log(vsid::LogLevel::Info, std::format("Parsed {} SIDs.", this->sectionSids_.size())); break; case Section::Unknown: diff --git a/flightplan.cpp b/flightplan.cpp index 4fb7397..a2cf278 100644 --- a/flightplan.cpp +++ b/flightplan.cpp @@ -4,6 +4,9 @@ #include "utils.h" #include "messageHandler.h" #include "constants.h" +#include "logger.h" + +#include std::vector vsid::fplnhelper::clean(const EuroScopePlugIn::CFlightPlan &FlightPlan, std::string filedSidWpt) { @@ -24,8 +27,8 @@ std::vector vsid::fplnhelper::clean(const EuroScopePlugIn::CFlightP } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Error during cleaning of route at first entry. ADEP: " + origin + - " with route \"" + vsid::utils::join(filedRoute) + "\". Code: " + ERROR_FPLN_CLNFIRST); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[{}] Error during cleaning of route at first entry. ADEP [{}] with route [{}]. Code: {}", + callsign, origin, vsid::utils::join(filedRoute), ERROR_FPLN_CLNFIRST)); } } @@ -44,8 +47,8 @@ std::vector vsid::fplnhelper::clean(const EuroScopePlugIn::CFlightP } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Error during cleaning of route. Cleaning was continued after false entry. ADEP: " + origin + - " with route \"" + vsid::utils::join(filedRoute) + "\". Code: " + ERROR_FPLN_CLNSPDLVL); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[{}] Error during cleaning of route. Cleaning was continued after false entry. " + "ADEP [{}] with route [{}]. Code: {}", callsign, origin, vsid::utils::join(filedRoute), ERROR_FPLN_CLNSPDLVL)); } if (*it == filedSidWpt) break; it = filedRoute.erase(it); @@ -63,8 +66,9 @@ std::vector vsid::fplnhelper::clean(const EuroScopePlugIn::CFlightP } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Error during cleaning of route. Cleaning was continued after false entry. ADEP: " + origin + - " with route \"" + vsid::utils::join(filedRoute) + "\". Code: " + ERROR_FPLN_CLNSPDLVL); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[{}] Error during cleaning of route. Cleaning was continued " + "after false entry. ADEP [{}] with route [{}]. Code: {}", + callsign, origin, vsid::utils::join(filedRoute), ERROR_FPLN_CLNSPDLVL)); } if (*it != origin) break; it = filedRoute.erase(it); @@ -73,9 +77,9 @@ std::vector vsid::fplnhelper::clean(const EuroScopePlugIn::CFlightP if (filedRoute.size() == 0 && vsid::utils::split(fplnData.GetRoute(), ' ').size() != 0) { + vsid::Logger::log(vsid::LogLevel::Warning, std::format("[{}] did not clean route as cleaning resulted in an empty route " + "(possible error in the filed route). Returning original route.", callsign)); - messageHandler->writeMessage("WARNING", "[" + callsign + - "] did not clean route as cleaning resulted in an empty route (possible error in the filed route). Returning original route."); return vsid::utils::split(fplnData.GetRoute(), ' '); } @@ -96,8 +100,7 @@ std::string vsid::fplnhelper::getTransition(const EuroScopePlugIn::CFlightPlan& if (std::find(route.begin(), route.end(), base) == route.end()) continue; return trans.base + trans.number + trans.designator; } - messageHandler->writeMessage("DEBUG", "[" + std::string(FlightPlan.GetCallsign()) + - "] no matching transition wpt found", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] no matching transition wpt found", FlightPlan.GetCallsign()), vsid::DebugLevel::Sid); return ""; // fallback if no transition could be matched } @@ -159,8 +162,9 @@ std::pair vsid::fplnhelper::getAtcBlock(const EuroScop { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_ATCBLOCK)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get ATC block. First route entry: " + - filedRoute.at(0) + ". Code: " + ERROR_FPLN_ATCBLOCK); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[{}] Failed to get ATC block. First route entry [{}]. Code: {}", + callsign, filedRoute.at(0), ERROR_FPLN_ATCBLOCK)); + messageHandler->addFplnError(callsign, ERROR_FPLN_ATCBLOCK); } } @@ -233,11 +237,9 @@ std::string vsid::fplnhelper::getEquip(const EuroScopePlugIn::CFlightPlan& Fligh /* default state - if an aircraft is known rnav capable skip checks */ if (rnav.contains(FlightPlan.GetFlightPlanData().GetAircraftFPType())) { - messageHandler->writeMessage("DEBUG", "[" + callsign + - "] found in RNAV list. Returning \"SDE2E3FGIJ1RWY\"", vsid::MessageHandler::DebugArea::Sid); - + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] found in RNAV list. Returning [SDE2E3FGIJ1RWY]", callsign), vsid::DebugLevel::Sid); return "SDE2E3FGIJ1RWY"; - } + } else if (vecEquip.size() >= 2) { vecEquip = vsid::utils::split(vecEquip.at(1), '/'); @@ -248,17 +250,15 @@ std::string vsid::fplnhelper::getEquip(const EuroScopePlugIn::CFlightPlan& Fligh } catch (std::out_of_range) { - messageHandler->writeMessage("DEBUG", "[" + callsign + - "] failed to get equipment, Nothing will be returned.", vsid::MessageHandler::DebugArea::Sid); - + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] failed to get equipment, Nothing will be returned.", callsign), vsid::DebugLevel::Sid); return ""; } } else if (cap != ' ') { - messageHandler->writeMessage("DEBUG", "[" + callsign + - "] failed to get equipment, falling back to capability checking. Reported equipment \"" + - equip + "\". Reported capability \"" + cap + "\"", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] failed to get equipment, falling back to capability checking. " + "Reported equipment [{}]. Reported capability [{}]", + callsign, equip, cap), vsid::DebugLevel::Sid); std::map faaToIcao = { // X disabled due to too many occurences with fplns that are RNAV capable @@ -279,8 +279,7 @@ std::string vsid::fplnhelper::getEquip(const EuroScopePlugIn::CFlightPlan& Fligh } else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] failed to get equipment or capabilities. Returning empty equipment", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] failed to get equipment or capabilities. Returning empty equipment", callsign), vsid::DebugLevel::Sid); return ""; } } @@ -312,7 +311,7 @@ std::string vsid::fplnhelper::getPbn(const EuroScopePlugIn::CFlightPlan& FlightP void vsid::fplnhelper::saveFplnInfo(const std::string& callsign, vsid::Fpln fplnInfo, std::map& savedFplnInfo) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] saving flight plan info for possible reconnection.", vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] saving flight plan info for possible reconnection.", callsign), vsid::DebugLevel::Fpln); savedFplnInfo[callsign] = std::move(fplnInfo); savedFplnInfo[callsign].sid = {}; @@ -332,12 +331,13 @@ bool vsid::fplnhelper::restoreFplnInfo(const std::string& callsign, std::mapwriteMessage("DEBUG", "[" + callsign + "] successfully restored.", vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] flight plan info successfully restored.", callsign), vsid::DebugLevel::Fpln); return true; } else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] failed to restore from saved info.", vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] failed to restore flight plan info. Info is stored, " + "but callsign no longer in processed", callsign), vsid::DebugLevel::Fpln); return false; } } @@ -368,11 +368,14 @@ bool vsid::fplnhelper::restoreIC(const vsid::Fpln& fplnInfo, EuroScopePlugIn::CF { int initialClimb = (fplnInfo.customSid.initialClimb > fplnData.GetFinalAltitude()) ? fplnData.GetFinalAltitude() : fplnInfo.customSid.initialClimb; + if (!cad.SetClearedAltitude(initialClimb)) { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_SETALT_RESET)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - failed to set altitude. Code: " + ERROR_FPLN_SETALT_RESET); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[{}] - failed to set altitude using custom SID. Code: {}", + callsign, ERROR_FPLN_SETALT_RESET)); + messageHandler->addFplnError(callsign, ERROR_FPLN_SETALT_RESET); } return false; @@ -387,11 +390,14 @@ bool vsid::fplnhelper::restoreIC(const vsid::Fpln& fplnInfo, EuroScopePlugIn::CF { int initialClimb = (fplnInfo.sid.initialClimb > fplnData.GetFinalAltitude()) ? fplnData.GetFinalAltitude() : fplnInfo.sid.initialClimb; + if (!cad.SetClearedAltitude(initialClimb)) { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_SETALT_RESET)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - failed to set altitude. Code: " + ERROR_FPLN_SETALT_RESET); + vsid::Logger::log(vsid::LogLevel::Error, std::format("[{}] - failed to set altitude using SID. Code: {}", + callsign, ERROR_FPLN_SETALT_RESET)); + messageHandler->addFplnError(callsign, ERROR_FPLN_SETALT_RESET); } return false; diff --git a/menu.cpp b/menu.cpp index 983a4a5..779a4db 100644 --- a/menu.cpp +++ b/menu.cpp @@ -35,7 +35,7 @@ vsid::Menu::Menu(int type, std::string title, std::string parent, int top, int l this->addButton(MENU_BUTTON_CLOSE, this->title + "_close", this->topBar, "", 5, 5, 0, { 5, 5, 5, 5 }); - messageHandler->writeMessage("DEBUG", "Creating menu " + title, vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Creating menu [{}]", title), vsid::DebugLevel::Menu, true); } void vsid::Menu::addText(int type, std::string title, const CRect &base, std::string txt, int minWidth, int height, int weight, Spacing margin, @@ -43,12 +43,12 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st { if (this->texts.contains(title)) { - messageHandler->writeMessage("ERROR", "Trying to add text \"" + title + "\" to menu \"" + this->title + - "\". Report as an error. Code: " + ERROR_MEN_TXTADD); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Trying to add text [{}] to menu [{}]. Report as an error. Code: {}", + title, this->title, ERROR_MEN_TXTADD), vsid::DebugLevel::Menu); return; } - messageHandler->writeMessage("DEBUG", "Creating new text \"" + title + "\"", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Creating new text [{}]", title), vsid::DebugLevel::Menu, true); vsid::Text newText = { type, title, base, txt, minWidth, height, weight, margin, relElem, render, textColor, bg }; @@ -71,15 +71,13 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st newText.tablePos = { maxRow + 1, 0 }; } - messageHandler->writeMessage("DEBUG", "Text [" + title + "] maxRow: " + std::to_string(maxRow) + - " - maxCol: " + std::to_string(maxCol), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] maxRow: {} - maxCol: {}", title, maxRow, maxCol), vsid::DebugLevel::Menu, true); try { auto [row, col] = newText.tablePos; - messageHandler->writeMessage("DEBUG", "Text [" + title + "] row: " + std::to_string(row) + - " - col: " + std::to_string(col), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] row: {} - col: {}", title, row, col), vsid::DebugLevel::Menu, true); if (row == 0) { @@ -92,7 +90,8 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st if (this->texts.contains(onLeft)) { - messageHandler->writeMessage("DEBUG", "Text [" + title + "] onLeft: " + onLeft + " contained in table", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] in row 0 left neighbor [{}] contained in table", + title, onLeft), vsid::DebugLevel::Menu, true); newText.area.left = this->texts[onLeft].area.left + newText.margin.left; } } @@ -105,8 +104,8 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st { newText.area.top = this->texts[onTop].area.bottom + newText.margin.top; - messageHandler->writeMessage("DEBUG", "Text [" + title + "] .top: " + std::to_string(newText.area.top) + - " based on [" + onTop + "] .bottom: " + std::to_string(this->texts[onTop].area.bottom), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] .top [{}] based on [{}] .bottom: [{}]", + title, newText.area.top, onTop, this->texts[onTop].area.bottom), vsid::DebugLevel::Menu, true); } if (col == 0) newText.area.left = base.left + newText.margin.left; @@ -116,7 +115,8 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st if (this->texts.contains(onLeft)) { - messageHandler->writeMessage("DEBUG", "Text [" + title + "] onLeft: " + onLeft + " contained in table", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] left neighbor [{}] contained in table", + title, onLeft), vsid::DebugLevel::Menu, true); newText.area.left = this->texts[onLeft].area.left + newText.margin.left; } } @@ -124,8 +124,9 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Tried to access an invalid table position in menu \"" + - this->title + "\" working on new text: \"" + newText.title + "\". Code: " + ERROR_MENU_TXTINVTABPOS); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Tried to access an invalid table position in menu [{}] " + "working on new text [{}]. Code: {}", + this->title, newText.title, ERROR_MENU_TXTINVTABPOS)); return; } @@ -143,15 +144,17 @@ void vsid::Menu::addText(int type, std::string title, const CRect &base, std::st // insert into total text overview if (newText.title != "INVALID") this->texts.insert({ title, newText }); - else messageHandler->writeMessage("ERROR", "Trying to add text " + title + " of invalid type to menu " + - this->title + ". Code: " + ERROR_MEN_TXTINVTYPE); + + vsid::Logger::log(vsid::LogLevel::Error, std::format("Trying to add text [{}] of invalid type to menu [{}]. Code: {}", + title, this->title, ERROR_MEN_TXTINVTYPE), vsid::DebugLevel::Menu); } void vsid::Menu::removeText(const std::string& title) { if (this->texts.contains(title)) { - messageHandler->writeMessage("DEBUG", "Removing " + title + " from " + this->title, vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Removing text [{}] from menu [{}]", title, this->title), vsid::DebugLevel::Menu, true); + this->texts.erase(title); // update table @@ -183,12 +186,12 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: { if (this->buttons.contains(title)) { - messageHandler->writeMessage("ERROR", "Trying to add button \"" + title + "\" to menu \"" + this->title + - "\". Report as an error. Code: " + ERROR_MENU_BTNADD); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Trying to add button [{}] to menu [{}]. Report as an error. Code: {}", + title, this->title, ERROR_MENU_BTNADD)); return; } - messageHandler->writeMessage("DEBUG", "Creating new button \"" + title + "\"", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Creating new button [{}]", title), vsid::DebugLevel::Menu, true); vsid::Button newButton = { type, title, base, label, minWidth, height, weight, margin, relElem, render, textColor, bg, border }; @@ -212,15 +215,15 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: newButton.tablePos = { maxRow + 1, 0 }; } - messageHandler->writeMessage("DEBUG", "Button [" + title + "] maxRow: " + std::to_string(maxRow) + - " - maxCol: " + std::to_string(maxCol), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] maxRow: {} - maxCol: {}", + title, std::to_string(maxRow), std::to_string(maxCol)), vsid::DebugLevel::Menu, true ); try { auto [row, col] = newButton.tablePos; - messageHandler->writeMessage("DEBUG", "Button [" + title + "] row: " + std::to_string(row) + - " - col: " + std::to_string(col), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] row: {} - col: {}", + title, std::to_string(row), std::to_string(col)), vsid::DebugLevel::Menu, true); if (row == 0) { @@ -233,7 +236,9 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: if (this->texts.contains(onLeft)) { - messageHandler->writeMessage("DEBUG", "Button [" + title + "] onLeft: " + onLeft + " contained in table", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] in row 0 left neighbor [{}] contained in table", + title, onLeft), vsid::DebugLevel::Menu, true); + newButton.area.left = this->texts[onLeft].area.left + newButton.margin.left; } } @@ -246,8 +251,8 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: { newButton.area.top = this->texts[onTop].area.bottom + newButton.margin.top; - messageHandler->writeMessage("DEBUG", "Button [" + title + "] .top: " + std::to_string(newButton.area.top) + - " based on [" + onTop + "] .bottom: " + std::to_string(this->texts[onTop].area.bottom), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] .top [{}] based on [{}] .bottom [{}]", + title, std::to_string(newButton.area.top), onTop, std::to_string(this->texts[onTop].area.bottom)), vsid::DebugLevel::Menu, true); } if (col == 0) newButton.area.left = base.left + newButton.margin.left; @@ -257,7 +262,8 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: if (this->texts.contains(onLeft)) { - messageHandler->writeMessage("DEBUG", "Button [" + title + "] onLeft: " + onLeft + " contained in table", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] left neighbor [{}] contained in table", title, onLeft), vsid::DebugLevel::Menu, true); + newButton.area.left = this->texts[onLeft].area.left + newButton.margin.left; } } @@ -265,8 +271,8 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Tried to access an invalid table position in menu \"" + - this->title + "\" working on new text: \"" + newButton.title + "\". Code: " + ERROR_MENU_BTNINVTABPOS); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Tried to access an invalid table position in menu [{}] working on new text [{}]. Code: {}", + this->title, newButton.title, ERROR_MENU_BTNINVTABPOS)); return; } @@ -284,8 +290,8 @@ void vsid::Menu::addButton(int type, std::string title, const CRect& base, std:: // insert into total text overview if (newButton.title != "INVALID") this->buttons.insert({ title, newButton }); - else messageHandler->writeMessage("ERROR", "Trying to add button " + title + " of invalid type to menu " + - this->title + ". Code: " + ERROR_MEN_BTNINVTYPE); + else vsid::Logger::log(vsid::LogLevel::Error, std::format("Trying to add button [{}] of invalid type to menu [{}]. Code: {}", + title, this->title, ERROR_MEN_BTNINVTYPE)); } void vsid::Menu::resize(int top, int right, int bottom, int left) @@ -298,7 +304,7 @@ void vsid::Menu::resize(int top, int right, int bottom, int left) void vsid::Menu::update() { - messageHandler->writeMessage("DEBUG", "[" + this->title + "] Updating menu" , vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Updating menu", this->title), vsid::DebugLevel::Menu); HDC hDC = GetDC(NULL); CDC dc; @@ -323,7 +329,8 @@ void vsid::Menu::update() { for (auto [col, elem] : columnMap) { - messageHandler->writeMessage("DEBUG", "Text table [" + std::to_string(row) + "][" + std::to_string(col) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text table [{}][{}]", std::to_string(row), std::to_string(col)), vsid::DebugLevel::Menu, true); + if (this->texts.contains(elem)) { vsid::Text& txt = this->texts[elem]; @@ -347,7 +354,8 @@ void vsid::Menu::update() { txtSize = dc.GetTextExtent("99"); - messageHandler->writeMessage("DEBUG", "depcount update - size: " + std::to_string(txtSize.cx) + "/" + std::to_string(txtSize.cy), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("depcount update - txt size x[{}] y[{}]", + std::to_string(txtSize.cx), std::to_string(txtSize.cy)), vsid::DebugLevel::Menu, true); } else txtSize = dc.GetTextExtent(txt.txt.c_str()); @@ -358,7 +366,7 @@ void vsid::Menu::update() // auto [row, col] = txt.tablePos; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Updating text.", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Updating text.", txt.title), vsid::DebugLevel::Menu); // adjust text position based on neighbours @@ -374,12 +382,11 @@ void vsid::Menu::update() txt.area.top = txt.base.top + txt.margin.top; txt.area.bottom = txt.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjust to new .top [" + - std::to_string(txt.area.top) + "] based on main area", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .top [{}] based on main area", + txt.title, std::to_string(txt.area.top)), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] .top [" + std::to_string(txt.area.top) + "] matches main area .top [" + - std::to_string(txt.base.top) + "] + margin .top [" + std::to_string(txt.margin.top) + "] -> " + - std::to_string(txt.area.top) + " == " + std::to_string(txt.base.top + txt.margin.top), vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .top [{}] matches main area .top [{}] + margin .top [{}] -> {} == {}", + txt.title, txt.area.top, txt.base.top, txt.margin.top, txt.area.top, txt.base.top + txt.margin.top), vsid::DebugLevel::Menu, true); } else { @@ -393,13 +400,12 @@ void vsid::Menu::update() txt.area.top = this->texts[toTop].area.bottom + txt.margin.top; txt.area.bottom = txt.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjust to new .top [" + - std::to_string(txt.area.top) + "] based on above \"" + toTop + "\" .bottom [" + - std::to_string(this->texts[toTop].area.bottom) + "] + margin.top", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .top [{}] based on above [{}] .bottom [{}] + margin.top", + txt.title, txt.area.top, toTop, this->texts[toTop].area.bottom), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] .top [" + std::to_string(txt.area.top) + "] matches [" + toTop + "] .bottom [" + - std::to_string(this->texts[toTop].area.bottom) + "] + margin .top [" + std::to_string(txt.margin.top) + "] -> " + - std::to_string(txt.area.top) + " == " + std::to_string(this->texts[toTop].area.bottom + txt.margin.top), vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .top [{}] matches [{}] .bottom [{}] + margin .top [{}] -> {} == {}", + txt.title, txt.area.top, toTop, this->texts[toTop].area.bottom, txt.margin.top, + txt.area.top, this->texts[toTop].area.bottom + txt.margin.top), vsid::DebugLevel::Menu, true); } else if (this->buttons.contains(toTop)) { @@ -409,15 +415,14 @@ void vsid::Menu::update() txt.area.top = this->buttons[toTop].area.bottom + txt.margin.top; txt.area.bottom = txt.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjust to new .top [" + - std::to_string(txt.area.top) + "] based on above \"" + toTop + "\" .bottom [" + - std::to_string(this->buttons[toTop].area.bottom) + "] + margin.top", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .top [{}] based on above [{}] .bottom [{}] + margin.top", + txt.title, txt.area.top, toTop, this->buttons[toTop].area.bottom), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] .top [" + std::to_string(txt.area.top) + "] matches [" + toTop + "] .bottom [" + - std::to_string(this->buttons[toTop].area.bottom) + "] + margin .top [" + std::to_string(txt.margin.top) + "] -> " + - std::to_string(txt.area.top) + " == " + std::to_string(this->buttons[toTop].area.bottom + txt.margin.top), vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .top [{}] matches [{}] .bottom [{}] + margin .top [{}] -> {} == {}", + txt.title, txt.area.top, toTop, this->buttons[toTop].area.bottom, txt.margin.top, + txt.area.top, this->buttons[toTop].area.bottom + txt.margin.top), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] toTop text/button [" + toTop + "] was not found.", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] toTop text/button [{}] was not found.", txt.title, toTop), vsid::DebugLevel::Menu, true); } // adjust text position in columns @@ -430,11 +435,11 @@ void vsid::Menu::update() txt.area.left = txt.base.left + txt.margin.left; txt.area.right = txt.area.left + width; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjust to new .left [" + - std::to_string(txt.area.left) + "] based on main", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .left [{}] based on main", + txt.title, txt.area.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] .left [" + std::to_string(txt.area.left) + "] matches base .left [" + - std::to_string(txt.base.left) + "] + margin.left [" + std::to_string(txt.margin.left) + "]", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left [{}] matches base .left [{}] + margin.left [{}]", + txt.title, txt.area.left, txt.base.left, txt.margin.left), vsid::DebugLevel::Menu, true); } else { @@ -448,12 +453,11 @@ void vsid::Menu::update() txt.area.left = this->texts[toLeft].area.right + txt.margin.left; txt.area.right = txt.area.left + width; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjust to new .left [" + - std::to_string(txt.area.left) + "] based on left \"" + toLeft + "\" .right [" + - std::to_string(this->texts[toLeft].area.right) + " + margin.left", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .left [{}] based on left [{}] .right [{}] + margin.left [{}]", + txt.title, txt.area.left, toLeft, this->texts[toLeft].area.right, txt.margin.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] .left [" + std::to_string(txt.area.left) + "] matches [" + toLeft + "] .left [" + - std::to_string(txt.base.left) + "] + margin .left [" + std::to_string(txt.margin.left) + "]", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left [{}] matches [{}] .left [{}] + margin.left [{}]", + txt.title, txt.area.left, toLeft, txt.base.left, txt.margin.left), vsid::DebugLevel::Menu, true); } else if (this->buttons.contains(toLeft)) { @@ -463,20 +467,19 @@ void vsid::Menu::update() txt.area.left = this->buttons[toLeft].area.right + txt.margin.left; txt.area.right = txt.area.left + width; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjust to new .left [" + - std::to_string(txt.area.left) + "] based on left \"" + toLeft + "\" .right [" + - std::to_string(this->buttons[toLeft].area.right) + " + margin.left", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .left [{}] based on left [{}] .right [{}] + margin.left [{}]", + txt.title, txt.area.left, toLeft, this->buttons[toLeft].area.right, txt.margin.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + txt.title + "] .left [" + std::to_string(txt.area.left) + "] matches [" + toLeft + "] .left [" + - std::to_string(txt.base.left) + "] + margin .left [" + std::to_string(txt.margin.left) + "]", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left [{}] matches [{}] .left [{}] + margin.left [{}]", + txt.title, txt.area.left, toLeft, txt.base.left, txt.margin.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "toLeft text/button [" + toLeft + "] was not found", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("toLeft text/button [{}] was not found", toLeft), vsid::DebugLevel::Menu, true); } } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Failed to update [" + this->title + "] when updating text [" + - txt.title + "]. Code: " + ERROR_MENU_TXTUPDATE); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to update [{}] when updating text [{}]. Code: {}", + this->title, txt.title, ERROR_MENU_TXTUPDATE)); } // adjust base area right side based on margin @@ -487,8 +490,8 @@ void vsid::Menu::update() { newArea.right = txt.area.right + txt.margin.right; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjusting main area to new .right [" + - std::to_string(newArea.right) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjusting main area to new .right [{}]", + txt.title, std::to_string(newArea.right)), vsid::DebugLevel::Menu, true); } } @@ -500,12 +503,12 @@ void vsid::Menu::update() { newArea.bottom = txt.area.bottom + txt.margin.bottom; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjusting main area to new .bottom [" + - std::to_string(newArea.bottom) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjusting main area to new .bottom [{}]", + txt.title, newArea.bottom), vsid::DebugLevel::Menu, true); } else { - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] base area mismatch, base.bottom smaller", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] base area mismatch, base.bottom smaller", txt.title), vsid::DebugLevel::Menu, true); } } else if (txt.base.bottom > txt.area.bottom + txt.margin.bottom) @@ -514,12 +517,12 @@ void vsid::Menu::update() { newArea.bottom = txt.area.bottom + txt.margin.bottom; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjusting main area to new .bottom [" + - std::to_string(newArea.bottom) + "] (reducing base area)", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjusting main area to new .bottom [{}]) (reducing base area)", + txt.title, newArea.bottom), vsid::DebugLevel::Menu, true); } else { - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] base area mismatch, base.bottom greater", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] base area mismatch, base.bottom greater", txt.title), vsid::DebugLevel::Menu, true); } } @@ -532,8 +535,8 @@ void vsid::Menu::update() newTopBar.bottom = newArea.top; newTopBar.top = newTopBar.bottom - height; - messageHandler->writeMessage("DEBUG", "[topBar] Adjusting top bar area. New .bottom [" + std::to_string(newTopBar.bottom) + - "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Adjusting top bar area. New .bottom[{}]", + newTopBar.bottom), vsid::DebugLevel::Menu, true); } if (newBottomBar.top != newArea.bottom) @@ -543,8 +546,8 @@ void vsid::Menu::update() newBottomBar.top = newArea.bottom; newBottomBar.bottom = newBottomBar.top + height; - messageHandler->writeMessage("DEBUG", "[bottomBar] Adjusting bottom bar area. New .top [" + std::to_string(newTopBar.top) + - "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Adjusting bottom bar area. New .top [{}]", + newTopBar.top), vsid::DebugLevel::Menu, true); } // move txt area based on margin and re-adjusted base area @@ -556,8 +559,8 @@ void vsid::Menu::update() txt.area.top = txt.base.top + txt.margin.top; txt.area.bottom = txt.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + txt.title + "] Adjusting to changed base with new .top [" + - std::to_string(txt.area.top) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjusting to changed base with new .top [{}]", + txt.title, txt.area.top), vsid::DebugLevel::Menu, true); } // adjust right side of menu to the farthest @@ -591,8 +594,7 @@ void vsid::Menu::update() btn.area.right = btn.area.left + txtSize.cx; btn.area.bottom = btn.area.top + txtSize.cy; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Updating button. (" + std::to_string(row) + - "/" + std::to_string(col) + ")", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Updating button. row[{}] col[{}]", btn.title, row, col), vsid::DebugLevel::Menu, true); // adjust text position based on neighbours @@ -608,12 +610,12 @@ void vsid::Menu::update() btn.area.top = btn.base.top + btn.margin.top; btn.area.bottom = btn.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjust to new .top [" + - std::to_string(btn.area.top) + "] based on main area", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .top [{}]", + btn.title, btn.area.top), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + btn.title + "] .top [" + std::to_string(btn.area.top) + "] matches main area .top [" + - std::to_string(btn.base.top) + "] + margin .top [" + std::to_string(btn.margin.top) + "] -> " + - std::to_string(btn.area.top) + " == " + std::to_string(btn.base.top + btn.margin.top), vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .top [{}] matches main area .top [{}] + margin .top [{}] -> {} == {}", + btn.title, btn.area.top, btn.base.top, btn.margin.top, + btn.area.top, btn.base.top + btn.margin.top), vsid::DebugLevel::Menu, true); } else { @@ -627,13 +629,12 @@ void vsid::Menu::update() btn.area.top = this->texts[toTop].area.bottom + btn.margin.top; btn.area.bottom = btn.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjust to new .top [" + - std::to_string(btn.area.top) + "] based on above \"" + toTop + "\" .bottom [" + - std::to_string(this->texts[toTop].area.bottom) + "] + margin.top", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .top [{}] based on above [{}] .bottom [{}] + margin.top [{}]", + btn.title, btn.area.top, toTop, this->texts[toTop].area.bottom, btn.margin.top), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + btn.title + "] .top [" + std::to_string(btn.area.top) + "] matches [" + toTop + "] .bottom [" + - std::to_string(this->texts[toTop].area.bottom) + "] + margin .top [" + std::to_string(btn.margin.top) + "] -> " + - std::to_string(btn.area.top) + " == " + std::to_string(this->texts[toTop].area.bottom + btn.margin.top), vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .top [{}] matches [{}] .bottom [{}] + margin .top [{}] -> {} == {}", + btn.title, btn.area.top, toTop, this->texts[toTop].area.bottom, btn.margin.top, + btn.area.top, this->texts[toTop].area.bottom + btn.margin.top), vsid::DebugLevel::Menu, true); } else if (this->buttons.contains(toTop)) { @@ -643,15 +644,14 @@ void vsid::Menu::update() btn.area.top = this->buttons[toTop].area.bottom + btn.margin.top; btn.area.bottom = btn.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjust to new .top [" + - std::to_string(btn.area.top) + "] based on above \"" + toTop + "\" .bottom [" + - std::to_string(this->buttons[toTop].area.bottom) + "] + margin.top", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .top [{}] based on above [{}] .bottom [{}] + margin.top [{}]", + btn.title, btn.area.top, toTop, this->buttons[toTop].area.bottom, btn.margin.top), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + btn.title + "] .top [" + std::to_string(btn.area.top) + "] matches [" + toTop + "] .bottom [" + - std::to_string(this->buttons[toTop].area.bottom) + "] + margin .top [" + std::to_string(btn.margin.top) + "] -> " + - std::to_string(btn.area.top) + " == " + std::to_string(this->buttons[toTop].area.bottom + btn.margin.top), vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .top [{}] matches [{}] .bottom [{}] + margin .top [{}] -> {} == {}", + btn.title, btn.area.top, toTop, this->buttons[toTop].area.bottom, btn.margin.top, + btn.area.top, this->buttons[toTop].area.bottom + btn.margin.top), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "toTop text/button [" + toTop + "] was not found", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("toTop text/button [{}] was not found", toTop), vsid::DebugLevel::Menu, true); } // adjust text position in columns @@ -664,11 +664,11 @@ void vsid::Menu::update() btn.area.left = btn.base.left + btn.margin.left; btn.area.right = btn.area.left + width; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjust to new .left [" + - std::to_string(btn.area.left) + "] based on main", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .left [{}] based on main", + btn.title, btn.area.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + btn.title + "] .left [" + std::to_string(btn.area.left) + "] matches base .left [" + - std::to_string(btn.base.left) + "] + margin.left [" + std::to_string(btn.margin.left) + "]", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left [{}] matches base .left [{}] + margin.left [{}]", + btn.title, btn.area.left, btn.base.left, btn.margin.left), vsid::DebugLevel::Menu, true); } else { @@ -682,12 +682,11 @@ void vsid::Menu::update() btn.area.left = this->texts[toLeft].area.right + btn.margin.left; btn.area.right = btn.area.left + width; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjust to new .left [" + - std::to_string(btn.area.left) + "] based on left \"" + toLeft + "\" .right [" + - std::to_string(this->texts[toLeft].area.right) + " + margin.left", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .left [{}] based on left [{}] .right [{}] + margin.left [{}]", + btn.title, btn.area.left, toLeft, this->texts[toLeft].area.right, btn.margin.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + btn.title + "] .left [" + std::to_string(btn.area.left) + "] matches [" + toLeft + "] .left [" + - std::to_string(btn.base.left) + "] + margin .left [" + std::to_string(btn.margin.left) + "]", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left [{}] matches [{}] .left [{}] + margin.left [{}]", + btn.title, btn.area.left, toLeft, btn.base.left, btn.margin.left), vsid::DebugLevel::Menu, true); } else if (this->buttons.contains(toLeft)) { @@ -697,20 +696,19 @@ void vsid::Menu::update() btn.area.left = this->buttons[toLeft].area.right + btn.margin.left; btn.area.right = btn.area.left + width; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjust to new .left [" + - std::to_string(btn.area.left) + "] based on left \"" + toLeft + "\" .right [" + - std::to_string(this->buttons[toLeft].area.right) + "] + margin.left", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] Adjust to new .left [{}] based on left [{}] .right [{}] + margin.left [{}]", + btn.title, btn.area.left, toLeft, this->buttons[toLeft].area.right, btn.margin.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "[" + btn.title + "] .left [" + std::to_string(btn.area.left) + "] matches [" + toLeft + "] .left [" + - std::to_string(btn.base.left) + "] + margin .left [" + std::to_string(btn.margin.left) + "]", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left [{}] matches [{}] .left [{}] + margin.left [{}]", + btn.title, btn.area.left, toLeft, btn.base.left, btn.margin.left), vsid::DebugLevel::Menu, true); } - else messageHandler->writeMessage("DEBUG", "toLeft text [" + toLeft + "] was not found in texts", vsid::MessageHandler::DebugArea::Menu); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("toLeft text/button [{}] was not found in texts or buttons", toLeft), vsid::DebugLevel::Menu, true); } } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Failed to update [" + this->title + "] when updating button [" + - btn.title + "]. Code: " + ERROR_MENU_BTNUPDATE); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to update [{}] when updating button [{}]. Code: {}", + this->title, btn.title, ERROR_MENU_BTNUPDATE)); } // adjust base area right side based on margin @@ -721,8 +719,8 @@ void vsid::Menu::update() { newArea.right = btn.area.right + btn.margin.right; - messageHandler->writeMessage("DEBUG", "Adjusting main area to new .right [" + - std::to_string(newArea.right) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Adjusting main area to new .right [{}]", + newArea.right), vsid::DebugLevel::Menu, true); } } @@ -733,8 +731,8 @@ void vsid::Menu::update() { newArea.bottom = btn.area.bottom + btn.margin.bottom; - messageHandler->writeMessage("DEBUG", "Adjusting main area to new .bottom [" + - std::to_string(newArea.bottom) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Adjusting main area to new .bottom [{}]", + newArea.bottom), vsid::DebugLevel::Menu, true); } } @@ -747,8 +745,8 @@ void vsid::Menu::update() newTopBar.bottom = newArea.top; newTopBar.top = newTopBar.bottom - height; - messageHandler->writeMessage("DEBUG", "[topBar] Adjusting top bar area. New .bottom [" + std::to_string(newTopBar.bottom) + - "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Adjusting top bar area. New .bottom [{}]", + newTopBar.bottom), vsid::DebugLevel::Menu, true); } if (newBottomBar.top != newArea.bottom) @@ -758,8 +756,8 @@ void vsid::Menu::update() newBottomBar.top = newArea.bottom; newBottomBar.bottom = newBottomBar.top + height; - messageHandler->writeMessage("DEBUG", "[bottomBar] Adjusting bottom bar area. New .top [" + std::to_string(newTopBar.top) + - "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Adjusting bottom bar area. New .top [{}]", + newTopBar.top), vsid::DebugLevel::Menu, true); } // move btn area based on margin and re-adjusted base area @@ -771,8 +769,8 @@ void vsid::Menu::update() btn.area.top = btn.base.top + btn.margin.top; btn.area.bottom = btn.area.top + height; - messageHandler->writeMessage("DEBUG", "[" + btn.title + "] Adjusting to changed base with new .top [" + - std::to_string(btn.area.top) + "]", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}]] Adjusting to changed base with new .top [{}]", + btn.title, btn.area.top), vsid::DebugLevel::Menu, true); } // adjust right side of menu to the farthest @@ -809,7 +807,7 @@ void vsid::Menu::update() txt.area.right = txt.area.left + txtSize.cx; txt.area.bottom = txt.area.top + txtSize.cy; - messageHandler->writeMessage("DEBUG", "Updating top/bottom bar text " + txt.title, vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Updating top/bottom bar text {}", txt.title), vsid::DebugLevel::Menu, true); if (txt.type == MENU_TOP_BAR) { @@ -843,13 +841,11 @@ void vsid::Menu::update() newBottomBar.right = newTopBar.right; } - messageHandler->writeMessage("DEBUG", "[" + title + "] .left: " + std::to_string(txt.area.left) + " .right: " + - std::to_string(txt.area.right) + " .bottom: " + std::to_string(txt.area.bottom) + - " .top: " + std::to_string(txt.area.top), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left: {} .right: {} .bottom: {} .top: {}", + title, txt.area.left, txt.area.right, txt.area.bottom, txt.area.top), vsid::DebugLevel::Menu, true); - messageHandler->writeMessage("DEBUG", "[" + title + "]-BASE .left: " + std::to_string(txt.base.left) + " .right: " + - std::to_string(txt.base.right) + " .bottom: " + std::to_string(txt.base.bottom) + - " .top: " + std::to_string(txt.base.top), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}]]-BASE .left: {} .right: {} .bottom: {} .top: {}", + title, txt.base.left, txt.base.right, txt.base.bottom, txt.base.top), vsid::DebugLevel::Menu, true); txt.base = newTopBar; } @@ -894,13 +890,11 @@ void vsid::Menu::update() newTopBar.right = newTopBar.right; } - messageHandler->writeMessage("DEBUG", "[" + title + "] .left: " + std::to_string(txt.area.left) + " .right: " + - std::to_string(txt.area.right) + " .bottom: " + std::to_string(txt.area.bottom) + - " .top: " + std::to_string(txt.area.top), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] .left: {} .right: {} .bottom: {} .top: {}", + title, txt.area.left, txt.area.right, txt.area.bottom, txt.area.top), vsid::DebugLevel::Menu, true); - messageHandler->writeMessage("DEBUG", "[" + title + "]-BASE .left: " + std::to_string(txt.base.left) + " .right: " + - std::to_string(txt.base.right) + " .bottom: " + std::to_string(txt.base.bottom) + - " .top: " + std::to_string(txt.base.top), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}]]-BASE .left: {} .right: {} .bottom: {} .top: {}", + title, txt.base.left, txt.base.right, txt.base.bottom, txt.base.top), vsid::DebugLevel::Menu, true); txt.base = newBottomBar; diff --git a/menu.h b/menu.h index d0ae1c4..899289c 100644 --- a/menu.h +++ b/menu.h @@ -23,6 +23,7 @@ along with this program. If not, see . #pragma once #include "messageHandler.h" +#include "logger.h" #include "Windows.h" #include "afxwin.h" @@ -31,6 +32,7 @@ along with this program. If not, see . #include #include #include +#include namespace vsid { @@ -55,7 +57,7 @@ namespace vsid { type(type), title(title), base(base), txt(txt), minWidth(minWidth), height(height), weight(weight), margin(margin), relElem(relElem), render(render), textColor(textColor), bg(bg), tablePos(tablePos) { - messageHandler->writeMessage("DEBUG", "Text " + title + " was created", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] was created", title), vsid::DebugLevel::Menu); }; /** @@ -67,7 +69,7 @@ namespace vsid { weight(other.weight), margin(other.margin), relElem(other.relElem), render(other.render), textColor(other.textColor), bg(other.bg), tablePos(other.tablePos), area(other.area) { - messageHandler->writeMessage("DEBUG", "(copy) Text " + title + " was created", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("(copy) Text [{}] was created", title), vsid::DebugLevel::Menu); }; /** @@ -79,10 +81,10 @@ namespace vsid { minWidth(other.minWidth), height(other.height), weight(other.weight), margin(std::move(other.margin)), relElem(std::move(other.relElem)), render(other.render), textColor(other.textColor), bg(other.bg), tablePos(other.tablePos), area(std::move(other.area)) { - messageHandler->writeMessage("DEBUG", "(move) Text " + title + " was created", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("(move) Text [{}] was created", title), vsid::DebugLevel::Menu); }; - virtual ~Text() { messageHandler->writeMessage("DEBUG", "Text " + title + " was destroyed", vsid::MessageHandler::DebugArea::Menu); }; + virtual ~Text() { vsid::Logger::log(vsid::LogLevel::Debug, std::format("Text [{}] was destroyed", title), vsid::DebugLevel::Menu); }; int type; std::string title; @@ -121,7 +123,7 @@ namespace vsid { type(type), title(title), base(base), label(label), height(height), weight(weight), margin(margin), relElem(relElem), render(render), textColor(textColor), bg(bg), border(border), tablePos(tablePos) { - messageHandler->writeMessage("DEBUG", "Button " + title + " was created", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] was created", title), vsid::DebugLevel::Menu); }; /** @@ -133,7 +135,7 @@ namespace vsid { height(other.height), weight(other.weight), margin(other.margin), relElem(other.relElem), render(other.render), textColor(other.textColor), bg(other.bg), border(other.border), tablePos(other.tablePos), area(other.area) { - messageHandler->writeMessage("DEBUG", "(copy) Button " + title + " was created", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("(copy) Button [{}] was created", title), vsid::DebugLevel::Menu); }; /** @@ -145,10 +147,10 @@ namespace vsid { height(other.height), weight(other.weight), margin(std::move(other.margin)), relElem(std::move(other.relElem)), render(other.render), textColor(other.textColor), bg(other.bg), border(other.border), tablePos(std::move(other.tablePos)), area(std::move(other.area)) { - messageHandler->writeMessage("DEBUG", "(move) Button " + title + " was created", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("(move) Button [{}] was created", title), vsid::DebugLevel::Menu); }; - virtual ~Button() { messageHandler->writeMessage("DEBUG", "Button " + title + " was destroyed", vsid::MessageHandler::DebugArea::Menu); }; + virtual ~Button() { vsid::Logger::log(vsid::LogLevel::Debug, std::format("Button [{}] was destroyed", title), vsid::DebugLevel::Menu); }; int type; std::string title; @@ -185,7 +187,7 @@ namespace vsid { // default Menu() : type(0), title(""), parent(""), area(), topBar(), bottomBar(), render(false), maxCol(1), border(defaultBorder), bg(defaultBg) { - messageHandler->writeMessage("DEBUG", "Creating menu (default Constructor)", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, "Creating menu (default Constructor)", vsid::DebugLevel::Menu); }; // standard Menu(int type, std::string title, std::string parent, int top, int left, int minWidth, int minHeight, bool render = false, int maxCol = 1, @@ -195,7 +197,7 @@ namespace vsid { bottomBar(other.bottomBar), render(other.render), maxCol(other.maxCol), border(other.border), bg(other.bg), texts(other.texts), buttons(other.buttons), table(other.table), submenues(other.submenues) { - messageHandler->writeMessage("DEBUG", "Creating menu (copy Constructor): \"" + title + "\"", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Creating menu (copy Constructor): [{}]", title), vsid::DebugLevel::Menu); }; // move Menu(vsid::Menu&& other) noexcept : type(other.type), title(std::move(other.title)), parent(std::move(other.parent)), area(std::move(other.area)), @@ -203,9 +205,9 @@ namespace vsid { bg(other.bg), texts(std::move(other.texts)), buttons(std::move(other.buttons)), table(other.table), submenues(std::move(other.submenues)) { - messageHandler->writeMessage("DEBUG", "Creating menu (move Constructor): \"" + title + "\"", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Creating menu (move Constructor): [{}]", title), vsid::DebugLevel::Menu); }; - virtual ~Menu() { messageHandler->writeMessage("DEBUG", "Deleting menu \"" + title + "\"", vsid::MessageHandler::DebugArea::Menu); }; + virtual ~Menu() { vsid::Logger::log(vsid::LogLevel::Debug, std::format("Deleting menu [{}]", title), vsid::DebugLevel::Menu); }; /** * @brief adds a text to the menu diff --git a/timeHandler.cpp b/timeHandler.cpp index 1bb044a..1e03fce 100644 --- a/timeHandler.cpp +++ b/timeHandler.cpp @@ -2,6 +2,9 @@ #include "timeHandler.h" #include "messageHandler.h" +#include "logger.h" +#include + bool vsid::time::isActive(const std::string& timezone, const int start, const int end) { try @@ -26,7 +29,7 @@ bool vsid::time::isActive(const std::string& timezone, const int start, const in } catch (std::runtime_error& e) { - messageHandler->writeMessage("ERROR", "Timezone failed - " + std::string(e.what()) + ": " + timezone); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Timezone failed - {}: {}", e.what(), timezone)); } return false; } \ No newline at end of file diff --git a/utils.cpp b/utils.cpp index 8a7ac2d..5edea8c 100644 --- a/utils.cpp +++ b/utils.cpp @@ -1,8 +1,10 @@ #include "pch.h" #include "utils.h" +#include "logger.h" #include #include +#include std::string vsid::utils::ltrim(const std::string& string) { @@ -146,7 +148,7 @@ double vsid::utils::toDeg(const std::string& coord) { if (coord.empty()) { - messageHandler->writeMessage("WARNING", "Empty coordinate string found! Skipping coordinate."); + vsid::Logger::log(vsid::LogLevel::Warning, "Empty coordinate string found! Skipping coordinate."); return 0.0; } @@ -156,7 +158,7 @@ double vsid::utils::toDeg(const std::string& coord) try { if (dms.size() < 4) - throw std::out_of_range("Coordinate string \"" + coord + "\" does not contain enough parts for DMS conversion!"); + throw std::out_of_range(std::format("Coordinate string [{}] does not contain enough parts for DMS conversion!", coord)); multi = (dms.at(0).find('S') != std::string::npos || dms.at(0).find('W') != std::string::npos) ? -1 : 1; @@ -168,14 +170,14 @@ double vsid::utils::toDeg(const std::string& coord) } catch (std::out_of_range& e) { - messageHandler->writeMessage("ERROR", "Out of bounds while calculating coordinate: " + coord + ". " + e.what()); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Out of bounds while calculating coordinate [{}]. {}", coord, e.what())); } catch (const std::invalid_argument& e) { - messageHandler->writeMessage("ERROR", "Invalid number format in coord " + coord + ". " + e.what()); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Invalid number format in coord [{}]. {}", coord, e.what())); } - messageHandler->writeMessage("WARNING", "Fallback state for \"" + coord + "\"! Failed to calculate. DMS will be set to 0.0"); + vsid::Logger::log(vsid::LogLevel::Warning, std::format("Fallback state for [{}]! Failed to calculate. DMS will be set to 0.0", coord)); return 0.0; } diff --git a/vSIDPlugin.cpp b/vSIDPlugin.cpp index 647517f..ef800e1 100644 --- a/vSIDPlugin.cpp +++ b/vSIDPlugin.cpp @@ -9,21 +9,21 @@ #include #include -#include #include "display.h" #include "airport.h" #include "crashhandler.h" // DEV -#include - #include // for debugging in detectPlugins() // END DEV vsid::VSIDPlugin* vsidPlugin; // pointer needed for ES vsid::VSIDPlugin::VSIDPlugin() : EuroScopePlugIn::CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE, pluginName.c_str(), pluginVersion.c_str(), pluginAuthor.c_str(), pluginCopyright.c_str()) { + vsid::Logger::initialize(); // initialize logger + vsid::Logger::setLogDevOnly(this->configParser.logDevOnly); + this->detectPlugins(); this->configParser.loadMainConfig(); this->configParser.loadGrpConfig(); @@ -33,7 +33,7 @@ vsid::VSIDPlugin::VSIDPlugin() : EuroScopePlugIn::CPlugIn(EuroScopePlugIn::COMPA /* takes over pointer control of vsidPlugin - no deletion needed for unloading*/ this->shared = std::shared_ptr(this); - messageHandler->setLevel("INFO"); + // messageHandler->setLevel("INFO"); #dev - new logger RegisterTagItemType("SID", TAG_ITEM_VSID_SIDS); RegisterTagItemFunction("Set/Reset suggested SID", TAG_FUNC_VSID_SIDS_AUTO); @@ -79,7 +79,7 @@ vsid::VSIDPlugin::VSIDPlugin() : EuroScopePlugIn::CPlugIn(EuroScopePlugIn::COMPA UpdateActiveAirports(); // preload rwy settings if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0) - messageHandler->writeMessage("ERROR", "Failed to init curl_global"); + vsid::Logger::log(LogLevel::Error, "Failed to init curl_global"); else this->curlInit = true; DisplayUserMessage("Message", "vSID", std::string("Version " + pluginVersion + " loaded").c_str(), true, true, false, false, false); @@ -87,7 +87,7 @@ vsid::VSIDPlugin::VSIDPlugin() : EuroScopePlugIn::CPlugIn(EuroScopePlugIn::COMPA vsid::VSIDPlugin::~VSIDPlugin() { - messageHandler->writeMessage("DEBUG", "VSIDPlugin destroyed.", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, "VSIDPlugin destroyed.", DebugLevel::Gen); }; /* @@ -158,9 +158,8 @@ std::string vsid::VSIDPlugin::findSidWpt(EuroScopePlugIn::CFlightPlan FlightPlan { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_SIDWPT)) { - messageHandler->writeMessage("ERROR", "[" + callsign + - "] Failed to split waypoint during SID waypoint checking. Waypoint was: " + wpt + - ". Code: " + ERROR_FPLN_SIDWPT); + vsid::Logger::log(LogLevel::Error, std::format("[{}] Failed to split waypoint during SID waypoint checking. Waypoint [{}]. Code: {}", + callsign, wpt, ERROR_FPLN_SIDWPT)); messageHandler->addFplnError(callsign, ERROR_FPLN_SIDWPT); } @@ -198,8 +197,8 @@ std::string vsid::VSIDPlugin::findSidWpt(EuroScopePlugIn::CFlightPlan FlightPlan { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_SIDWPT)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get the waypoint of a waypoint" - " and speed/level group. Waypoint is: " + wpt + ". Code: " + ERROR_FPLN_SIDWPT); + vsid::Logger::log(LogLevel::Error, std::format("[{}] Failed to get the waypoint of a waypoint and speed/level group. Waypoint [{}]. Code: {}", + callsign, wpt, ERROR_FPLN_SIDWPT)); messageHandler->addFplnError(callsign, ERROR_FPLN_SIDWPT); } @@ -233,7 +232,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (!this->activeAirports.contains(icao)) { - messageHandler->writeMessage("DEBUG", "[" + icao + "] is not an active airport. Skipping all SID checks", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] is not an active airport. Skipping all SID checks", icao), DebugLevel::Sid); + return vsid::Sid(); } @@ -255,9 +255,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (customRuleActive) // #evaluate - arrrwy check for areas below ~ 325 { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] [" + icao + - "] Custom rules active. Checking for avbl areas and possible arr as dep rwys.", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}] Custom rules active. Checking for avbl areas and possible arr as dep rwys.", + callsign, icao), DebugLevel::Sid); std::map customRules = this->activeAirports[icao].customRules; @@ -359,7 +358,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Checking SID \"" + currSid.idName() + "\"", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Checking SID [{}]", callsign, currSid.idName()), DebugLevel::Sid); // skip if SID needs active arr rwys @@ -376,10 +375,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because not all of the required arr Rwys are active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because not all of the required arr Rwys are active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -392,10 +389,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because none of the required arr rwys are active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because none of the required arr rwys are active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -412,10 +407,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because all of the forbidden arr Rwys are active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because all of the forbidden arr Rwys are active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -428,10 +421,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because at least one of the forbidden arr rwys is active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because at least one of the forbidden arr rwys is active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -453,10 +444,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because not all of the required dep Rwys are active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because not all of the required dep Rwys are active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -469,10 +458,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because none of the required dep rwys are active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because none of the required dep rwys are active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -489,10 +476,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because all of the forbidden dep Rwys are active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because all of the forbidden dep Rwys are active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -505,10 +490,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because at least one of the forbidden dep rwys is active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because at least one of the forbidden dep rwys is active", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -541,14 +524,11 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, break; } } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] [" + icao + "] available rwys (merged if arrAsDep in active area or rwy set by atc): " + - vsid::utils::join(depRwys), - vsid::MessageHandler::DebugArea::Sid - ); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] [" + icao + "] Skipped ATC RWYs : \"" + - vsid::utils::join(skipAtcRWY) + "\" / skipped SID RWY: \"" + - vsid::utils::join(skipSidRWY) + "\"", vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}] available rwys (merged if arrAsDep in active area or rwy set by atc): {}", + callsign, icao, vsid::utils::join(depRwys)), DebugLevel::Sid); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}] Skipped ATC RWYs [{}] | Skipped SID RWY [{}]", + callsign, icao, vsid::utils::join(skipAtcRWY), vsid::utils::join(skipSidRWY)), DebugLevel::Sid); // skip if custom rules are active but the current sid has no rule or has a rule but this is not active @@ -556,10 +536,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, this->activeAirports[icao].customRules.contains(currSid.customRule) && !this->activeAirports[icao].customRules[currSid.customRule]) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + - currSid.idName() + "\" because the SID custom rule is not active.", + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because the SID custom rule is not active.", + callsign, currSid.idName()), DebugLevel::Sid); - vsid::MessageHandler::DebugArea::Sid); continue; } @@ -567,9 +546,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (currSid.wingType.find(fplnData.GetAircraftType()) == std::string::npos && fplnData.GetAircraftType() != '?') { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because wing type \"" + fplnData.GetAircraftType() + "\" doesn't match.", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because wing type [{}] doesn't match.", + callsign, currSid.idName(), fplnData.GetAircraftType()), DebugLevel::Sid); continue; } @@ -585,9 +563,10 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { if (equip.size() > 1 && equip.find_first_of("ABGRI") == std::string::npos && pbn == "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because RNAV ('A', 'B', 'G', 'R' or 'I') is required, but not found in equipment \"" + - equip + "\" and PBN is empty", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because RNAV ('A', 'B', 'G', 'R' or 'I') " + "is required, but not found in equipment [{}] and PBN is empty", + callsign, currSid.idName(), equip), DebugLevel::Sid); + validEquip = false; continue; } @@ -596,19 +575,20 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { if (equip.size() < 2 && pbn == "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because only NON-RNAV is allowed, but equipment \"" + equip + - "\" has less than 2 entry and PBN is empty", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because only NON-RNAV is allowed, but equipment " + "[{}] has less than 2 entries and PBN is empty", + callsign, currSid.idName(), equip), DebugLevel::Sid); + validEquip = false; continue; } - /*if (equip.find_first_of("GRI") != std::string::npos || equip == "" || pbn != "")*/ if (equip.find_first_of("GRI") != std::string::npos || pbn != "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because only NON-RNAV is allowed, but RNAV ('G', 'R' or 'I') was found in equipment \"" + equip + - "\" or equipment was empty and PBN is not empty", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because only NON-RNAV is allowed, but RNAV ('G', 'R' or 'I') " + "was found in equipment [{}] or PBN is not empty", + callsign, currSid.idName(), equip), DebugLevel::Sid); + validEquip = false; continue; } @@ -619,17 +599,17 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { if (sidEquip.second && equip.find(sidEquip.first) == std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because equipment \"" + sidEquip.first + "\" is mandatory but was not found in equipment \"" + equip + "\"", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because equipment [{}] is mandatory but was not found in equipment [{}]", + callsign, currSid.idName(), sidEquip.first, equip), DebugLevel::Sid); + validEquip = false; continue; } if (!sidEquip.second && equip.find(sidEquip.first) != std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because equipment \"" + sidEquip.first + "\" is forbidden but was found in equipment \"" + equip + "\"", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because equipment [{}] is forbidden but was found in equipment [{}]", + callsign, currSid.idName(), sidEquip.first, equip), DebugLevel::Sid); + validEquip = false; continue; } @@ -650,9 +630,10 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (!transMatch) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() - + "\" because none of the transitions found in the route", - vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because none of the transitions found in the route", + callsign, currSid.idName()), DebugLevel::Sid); + + continue; } } @@ -660,10 +641,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (!customRuleActive && currSid.customRule != "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because no rule is active and the SID has a rule configured", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because no rule is active and the SID has a rule configured", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } @@ -686,10 +666,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, else return false; // warning for wrong config in next area check to prevent doubling })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because all areas are inactive but one is set in the SID", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because all areas are inactive but one is set in the SID", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } @@ -708,15 +687,14 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } else { - messageHandler->writeMessage("WARNING", "Area \"" + sidArea + "\" not in config for " + icao + ". Check your config."); + vsid::Logger::log(LogLevel::Warning, std::format("Area [{}] not in config for [{}]. Check your config.", sidArea, icao)); + return false; } // fallback })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because the plane is not in one of the active areas", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because the plane is not in one of the active areas", + callsign, currSid.idName()), DebugLevel::Sid); continue; } } @@ -724,10 +702,10 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, // skip if lvp ops are active but SID is not configured for lvp ops and lvp is not disabled for SID if (this->activeAirports[icao].settings["lvp"] && !currSid.lvp && currSid.lvp != -1) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because LVP is active and SID is not configured for LVP or LVP check is not disabled for SID", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because LVP is active and SID is not configured for LVP " + "or LVP check is not disabled for SID", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } @@ -735,10 +713,10 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (!this->activeAirports[icao].settings["lvp"] && currSid.lvp && currSid.lvp != -1) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because LVP is inactive and SID is configured for LVP or LVP check is not disabled for SID", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because LVP is inactive and SID is configured for LVP " + "or LVP check is not disabled for SID", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } @@ -746,10 +724,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (!rwyMatch) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" due to a RWY mismatch between SID rwy and active DEP rwy", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because of a RWY mismatch between SID rwy and active DEP rwy", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } @@ -758,10 +735,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (currSid.engineType != "" && currSid.engineType.find(fplnData.GetEngineType()) == std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because of a mismatch in engineType", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because of a mismatch in engineType", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } else if (currSid.engineType != "") @@ -778,11 +754,10 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, return type.second && !currSid.acftType.contains(fplnData.GetAircraftFPType()); })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because of a mismatch in aircraft type (type is set to false" + - " or type is set to true but plane is not of the type)", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because of a mismatch in aircraft type " + "(type is set to false or type is set to true but plane is not of the type)", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } else if (!currSid.acftType.empty()) @@ -793,10 +768,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, // skip if SID has engineNumber requirement and acft doesn't match if (!vsid::utils::containsDigit(currSid.engineCount, fplnData.GetEngineNumber())) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because of a mismatch in engine number", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because of a mismatch in engine number", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } else if (currSid.engineCount > 0) @@ -807,9 +781,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, // skip if SID has WTC requirement and acft doesn't match if (currSid.wtc != "" && currSid.wtc.find(fplnData.GetAircraftWtc()) == std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because of mismatch in WTC", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because of mismatch in WTC", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } else if (currSid.wtc != "") @@ -835,9 +809,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } if (!mtowMatch) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because of MTOW", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because of MTOW", + callsign, currSid.idName()), DebugLevel::Sid); + continue; } else restriction = true; @@ -849,9 +823,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { if (currSid.dest.contains(dest) && !currSid.dest[dest]) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because destination \"" + - dest + "\" is not allowed", vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because destination [{}] is not allowed", + callsign, currSid.idName(), dest), DebugLevel::Sid); + continue; } else if (!currSid.dest.contains(dest) && std::any_of(currSid.dest.begin(), currSid.dest.end(), [](const std::pair& sidDest) @@ -859,9 +833,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, return sidDest.second; })) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because destination \"" + - dest + "\" was not found for this SID and the SID has mandatory destinations", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because destination [{}] was not found for this SID and the SID has mandatory destinations", + callsign, currSid.idName(), dest), DebugLevel::Sid); + continue; } @@ -882,10 +856,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { startPos = std::find(filedRoute.begin(), filedRoute.end(), route.at(0)); - if (startPos == filedRoute.end()) messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping SID \"" + - currSid.idName() + "\" route checking for " + vsid::utils::join(route, ' ') + - " because first mandatory wpt " + route.at(0) + - " was not found in route", vsid::MessageHandler::DebugArea::Sid); + if (startPos == filedRoute.end()) + vsid::Logger::log(LogLevel::Debug, std::format("[{}] skipping SID [{}] route checking for [{}] because first mandatory wpt [{}] was not found in route", + callsign, currSid.idName(), vsid::utils::join(route, ' '), route.at(0)), DebugLevel::Sid); messageHandler->removeFplnError(callsign, ERROR_FPLN_ALLOWROUTE); } @@ -893,8 +866,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_ALLOWROUTE)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get first position for allowed route in SID " + - currSid.idName() + " checking SID route \"" + vsid::utils::join(route, ' ') + "\". Code: " + ERROR_FPLN_ALLOWROUTE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] Failed to get first position for allowed route in SID [{}] checking SID route [{}]. Code: {}", + callsign, currSid.idName(), vsid::utils::join(route, ' '), ERROR_FPLN_ALLOWROUTE)); + messageHandler->addFplnError(callsign, ERROR_FPLN_ALLOWROUTE); } } @@ -922,8 +896,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, continue; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] checking mand. wpt " + wpt + - " vs. " + *it, vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] checking mand. wpt [{}] vs [{}]", callsign, wpt, *it), DebugLevel::Sid, true); + if (wpt == *it) { allowSkip = false; @@ -933,8 +907,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } else if (allowSkip) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping wpt " + *it + - " as skipping is allowed", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] skipping wpt [{}] as skipping is allowed", callsign, *it), DebugLevel::Sid); lastMatch = false; it++; startPos++; @@ -942,8 +915,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] mismatch between mand. wpt " + - wpt + " vs. " + *it + ". Aborting", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] mismatch between mand. wpt [{}] vs [{}]", callsign, wpt, *it), DebugLevel::Sid); lastMatch = false; stopRoute = true; break; @@ -953,16 +925,15 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (lastMatch) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] mand. route in " + currSid.idName() + - " was found. Accepting.", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] mand. route in [{}] was found. Accepting.", callsign, currSid.idName()), DebugLevel::Sid); validRoute = true; break; } } if (!validRoute) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping SID \"" + - currSid.idName() + "\" because none of the allowed routes matched", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] skipping SID [{}] because none of the allowed routes matched", callsign, + currSid.idName()), DebugLevel::Sid); continue; } @@ -982,8 +953,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (startPos == filedRoute.end()) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepting SID " + - currSid.idName() + " because first waypoint of denied route wasn't found", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] accepting SID [{}] because first waypoint of denied route wasn't found", + callsign, currSid.idName()), DebugLevel::Sid); messageHandler->removeFplnError(callsign, ERROR_FPLN_DENYROUTE); @@ -994,8 +965,9 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_DENYROUTE)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to get first position for denied route in SID " + - currSid.idName() + " checking SID route \"" + vsid::utils::join(route, ' ') + "\". Code: " + ERROR_FPLN_DENYROUTE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] Failed to get first position for denied route in SID {} checking SID route [{}]. Code: {}", + callsign, currSid.idName(), vsid::utils::join(route, ' '), ERROR_FPLN_DENYROUTE)); + messageHandler->addFplnError(callsign, ERROR_FPLN_DENYROUTE); } } @@ -1023,8 +995,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, continue; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] checking forb. wpt " + wpt + - " vs. " + *it, vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] checking forb. wpt [{}] vs [{}]", callsign, wpt, *it), DebugLevel::Sid, true); + if (wpt == *it) { allowSkip = false; @@ -1034,8 +1006,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } else if (allowSkip) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping wpt " + *it + - " as it is allowed", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] skipping wpt [{}] as it is allowed", callsign, *it), DebugLevel::Sid); lastMatch = false; it++; @@ -1044,8 +1015,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, } else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] mismatch between forb. wpt " + - wpt + " vs. " + *it + ". Aborting", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] mismatch between forb. wpt [{}] vs. [{}]", callsign, wpt, *it), DebugLevel::Sid); lastMatch = false; stopRoute = true; break; @@ -1062,13 +1032,12 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (invalidRoute) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] skipping SID \"" + - currSid.idName() + "\" because a denied route matched", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] skipping SID [{}] because a denied route matched", callsign, currSid.idName()), DebugLevel::Sid); continue; } - else messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepting SID \"" + - currSid.idName() + "\" because no denied route matched", vsid::MessageHandler::DebugArea::Sid); + else + vsid::Logger::log(LogLevel::Debug, std::format("[{}] accepting SID [{}] because no denied route matched", callsign, currSid.idName()), DebugLevel::Sid); } } @@ -1077,9 +1046,8 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, (currSid.timeFrom != -1 || currSid.timeTo != -1) ) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + "\" because time is set and not active", - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because time is set and not active", callsign, currSid.idName()), DebugLevel::Sid); + continue; } @@ -1087,9 +1055,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (currSid.pilotfiled && currSid.name() != fplnData.GetSidName()) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" as pilot filed only. Filed SID: " + fplnData.GetSidName(), vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] as pilot filed only. Filed SID [{}]", callsign, currSid.idName(), fplnData.GetSidName()), DebugLevel::Sid); continue; } @@ -1097,8 +1063,7 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, // if a SID has the special prio "0" return an empty SID for forced manual selection if (currSid.prio == 0) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] special prio value '0' detected. Returning empty SID for forced manual mode", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] special prio value '0' detected. Returning empty SID for forced manual mode", callsign), DebugLevel::Sid); if (this->processed.contains(callsign)) this->processed[callsign].validEquip = true; return vsid::Sid(); @@ -1106,18 +1071,14 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, if (currSid.prio == 99) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because prio is 99 (manual only SID)", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because prio is 99 (manual only SID)", callsign, currSid.idName()), DebugLevel::Sid); continue; } if (currSid.prio > prio) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Skipping SID \"" + currSid.idName() + - "\" because prio is higher", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping SID [{}] because prio is higher", callsign, currSid.idName()), DebugLevel::Sid); continue; } @@ -1128,15 +1089,15 @@ vsid::Sid vsid::VSIDPlugin::processSid(EuroScopePlugIn::CFlightPlan& FlightPlan, prio = currSid.prio; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Setting SID \"" + setSid.idName() + "\"", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Setting SID [{}]", callsign, setSid.idName()), DebugLevel::Sid); // if the last valid SID fails due to equipment return a special "EQUIP" sid to also handle yet unprocessed fplns // reset in processFlightplan() if (!validEquip && setSid.empty()) { setSid.base = "EQUIP"; - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Re-Setting special SID base 'EQUIP' as the last possible SID failed due to equipment checks", - vsid::MessageHandler::DebugArea::Sid); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Re-Setting special SID base 'EQUIP' as the last possible SID failed due to equipment checks", callsign), DebugLevel::Sid); } return(setSid); @@ -1162,8 +1123,9 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_ADEPINACTIVE)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] ADEP [" + icao + - "] is not an active airport. Aborting processing. Code: " + ERROR_FPLN_ADEPINACTIVE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] ADEP [{}] is not an active airport. Aborting processing. Code: {}", + callsign, icao, ERROR_FPLN_ADEPINACTIVE)); + messageHandler->addFplnError(callsign, ERROR_FPLN_ADEPINACTIVE); } @@ -1179,8 +1141,7 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla fpln = this->processed[callsign]; resetIC = true; - messageHandler->writeMessage("DEBUG", "[" + callsign + "] re-syncing req and states for reconnected flight plan.", - vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] re-syncing req and states for reconnected flight plan.", callsign), DebugLevel::Fpln); // sync requests - sync function requires fpln to be known in one of the lists @@ -1188,9 +1149,9 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla { std::string newScratch = ".VSID_REQ_" + fpln.request + "/" + std::to_string(fpln.reqTime); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] syncing " + fpln.request + - " with scratch. New: \"" + newScratch + "\" | Old: \"" + FlightPlan.GetControllerAssignedData().GetScratchPadString() + "\"", vsid::MessageHandler::DebugArea::Req - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] syncing [{}] with scratch. New [{}] | Old [{}]", callsign, + fpln.request, newScratch, FlightPlan.GetControllerAssignedData().GetScratchPadString()), DebugLevel::Req); + this->addSyncQueue(callsign, newScratch, FlightPlan.GetControllerAssignedData().GetScratchPadString()); } @@ -1243,15 +1204,16 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla */ else if (atcRwy != "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] processing SID without atcRWY (atcRWY present, will be next check)", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] processing SID without atcRWY (atcRWY present, will be next check)", callsign), DebugLevel::Sid); sidSuggestion = this->processSid(FlightPlan); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] processing SID with atcRWY (for customSuggestion): " + atcRwy, vsid::MessageHandler::DebugArea::Sid); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] processing SID with atcRWY (for customSuggestion) [{}]", callsign, atcRwy), DebugLevel::Sid); sidCustomSuggestion = this->processSid(FlightPlan, atcRwy); } /* default state */ else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] processing SID without atcRWY", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] processing SID without atcRWY", callsign), DebugLevel::Sid); sidSuggestion = this->processSid(FlightPlan); } @@ -1313,15 +1275,15 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla if (rwy != "") setRwy = rwy; else { - messageHandler->writeMessage("DEBUG", "Fall back to ES dep rwy for [" + callsign + "] in fpln processing for sidSuggestion", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("Fall back to ES dep rwy for [{}] in fpln processing for sidSuggestion", callsign), DebugLevel::Sid); + setRwy = fplnData.GetDepartureRwy(); } } catch (std::out_of_range) // old remains - might be removed #checkforremoval { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to check RWY in sidSuggestion. Check config " + - icao + " for SID \"" + sidSuggestion.idName() + "\". RWY value is: " + vsid::utils::join(sidSuggestion.rwys)); + vsid::Logger::log(LogLevel::Error, std::format("[{}] Failed to check RWY in sidSuggestion. Check config [{}] for SID [{}]. RWY value is [{}]", callsign, + icao, sidSuggestion.idName(), vsid::utils::join(sidSuggestion.rwys))); } } else if (sidCustomSuggestion.base != "") @@ -1356,15 +1318,15 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla if (rwy != "") setRwy = rwy; else { - messageHandler->writeMessage("DEBUG", "Fall back to ES dep rwy for [" + callsign + "] in fpln processing for sidCustomSuggestion", - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("Fall back to ES dep rwy for [{}] in fpln processing for sidCustomSuggestion", callsign), DebugLevel::Sid); + setRwy = fplnData.GetDepartureRwy(); } } catch (std::out_of_range) // old remains - might be removed #checkforremoval { - messageHandler->writeMessage("ERROR", "[" + callsign + "] Failed to check RWY in sidCustomSuggestion. Check config " + - icao + " for SID \"" + sidCustomSuggestion.idName() + "\". RWY value is: " + vsid::utils::join(sidCustomSuggestion.rwys)); + vsid::Logger::log(LogLevel::Error, std::format("[{}] Failed to check RWY in sidCustomSuggestion. Check config [{}] for SID [{}]. RWY value is [{}]", callsign, + icao, sidCustomSuggestion.idName(), vsid::utils::join(sidCustomSuggestion.rwys))); } } @@ -1425,14 +1387,16 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla this->processed[callsign].noFplnUpdate = true; if (!fplnData.SetRoute(vsid::utils::join(filedRoute).c_str())) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to change flight plan! Code: " + ERROR_FPLN_SETROUTE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to change flight plan! Code: {}", callsign, ERROR_FPLN_SETROUTE)); + this->processed[callsign].noFplnUpdate = false; } //else this->processed[callsign].noFplnUpdate = true; if (!fplnData.AmendFlightPlan()) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to amend flight plan! Code: " + ERROR_FPLN_AMEND); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}", callsign, ERROR_FPLN_AMEND)); + this->processed[callsign].noFplnUpdate = false; } else @@ -1450,7 +1414,7 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla int initialClimb = (sidSuggestion.initialClimb > fplnData.GetFinalAltitude()) ? fplnData.GetFinalAltitude() : sidSuggestion.initialClimb; if (!cad.SetClearedAltitude(initialClimb)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - failed to set altitude. Code: " + ERROR_FPLN_SETALT); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - failed to set altitude. Code: {}", callsign, ERROR_FPLN_SETALT)); } } else if (sidCustomSuggestion.base != "" && sidCustomSuggestion.initialClimb) @@ -1458,7 +1422,7 @@ void vsid::VSIDPlugin::processFlightplan(EuroScopePlugIn::CFlightPlan& FlightPla int initialClimb = (sidCustomSuggestion.initialClimb > fplnData.GetFinalAltitude()) ? fplnData.GetFinalAltitude() : sidCustomSuggestion.initialClimb; if (!cad.SetClearedAltitude(initialClimb)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - failed to set altitude. Code: " + ERROR_FPLN_SETALT); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - failed to set altitude. Code: {}", callsign, ERROR_FPLN_SETALT)); } } @@ -1484,8 +1448,7 @@ void vsid::VSIDPlugin::removeFromRequests(const std::string& callsign, const std ++jt; continue; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] erasing from request \"" + it->first + - "\" at [" + icao + "]", vsid::MessageHandler::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] erasing from request [{}] at [{}]", callsign, it->first, icao), DebugLevel::Req); if (this->processed.contains(callsign)) { @@ -1508,8 +1471,7 @@ void vsid::VSIDPlugin::removeFromRequests(const std::string& callsign, const std ++jt; continue; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] erasing from rwy request \"" + type + "\" at [" + icao + "] in rwy \"" + - it->first + "\"", vsid::MessageHandler::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] erasing from rwy request [{}] at [{}]", callsign, type, icao), DebugLevel::Req); if (this->processed.contains(callsign)) { @@ -1531,7 +1493,7 @@ void vsid::VSIDPlugin::syncReq(EuroScopePlugIn::CFlightPlan& FlightPlan) std::string callsign = FlightPlan.GetCallsign(); std::string adep = FlightPlan.GetFlightPlanData().GetOrigin(); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] calling request sync.", vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] calling request sync.", callsign), DebugLevel::Req); if (!this->processed.contains(callsign) || !this->activeAirports.contains(adep)) return; @@ -1658,7 +1620,8 @@ bool vsid::VSIDPlugin::outOfVis(EuroScopePlugIn::CFlightPlan& FlightPlan) void vsid::VSIDPlugin::processSPQueue() { if (queueInProcess || this->syncQueue.empty()) return; - messageHandler->writeMessage("DEBUG", "Started sync processing queue...", vsid::MessageHandler::DebugArea::Dev); + + vsid::Logger::log(LogLevel::Debug, "Started sync processing queue...", DebugLevel::Dev, true); queueInProcess = true; @@ -1674,8 +1637,7 @@ void vsid::VSIDPlugin::processSPQueue() it = this->syncQueue.erase(it); continue; } - - messageHandler->writeMessage("DEBUG", "[" + callsign + "] queue processing... total msg queue size: " + std::to_string(it->second.size()), vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] queue processing... total msg queue size [{}]", callsign, it->second.size()), DebugLevel::Dev, true); if (this->spReleased.contains(callsign) && this->spReleased[callsign]) { @@ -1695,13 +1657,13 @@ void vsid::VSIDPlugin::processSPQueue() it->second.erase(it->second.begin(), it->second.begin() + pos); } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] #1 (Queue) sync released... " + ((this->spReleased[callsign]) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] #1 (Queue) sync released... [{}]", callsign, (this->spReleased[callsign]) ? "TRUE" : "FALSE"), DebugLevel::Dev, true); this->spReleased[callsign] = false; spWorkerActive = true; // reset on received update - messageHandler->writeMessage("DEBUG", "[" + callsign + "] (Queue) scratch pad sending scratch. New: \"" + - scratchPair.first + "\" | Old: " + scratchPair.second + "\"", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] (Queue) scratch pad sending scratch. New [{}] | Old [{}]", callsign, + scratchPair.first, scratchPair.second), DebugLevel::Dev); FlightPlan.GetControllerAssignedData().SetScratchPadString(vsid::utils::trim(scratchPair.first).c_str()); FlightPlan.GetControllerAssignedData().SetScratchPadString(vsid::utils::trim(scratchPair.second).c_str()); @@ -1712,11 +1674,11 @@ void vsid::VSIDPlugin::processSPQueue() } else if (this->spReleased.contains(callsign) && !this->spReleased[callsign]) // #dev - sync - remove (only debugging) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] #2 (Queue) sync released... " + ((this->spReleased[callsign]) ? "TRUE" : "FALSE"), vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] #2 (Queue) sync released... [{}]", callsign, (this->spReleased[callsign]) ? "TRUE" : "FALSE"), DebugLevel::Dev, true); } else if (!spReleased.contains(callsign)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] (Queue) release check not found...", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] (Queue) release check not found...", callsign), DebugLevel::Dev, true); this->spReleased.erase(callsign); it = this->syncQueue.erase(it); @@ -1725,7 +1687,7 @@ void vsid::VSIDPlugin::processSPQueue() if (it->second.size() == 0) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] no more messages in queue. Removing... ", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] no more messages in queue. Removing...", callsign), DebugLevel::Dev); it = this->syncQueue.erase(it); this->spReleased.erase(callsign); continue; @@ -1734,7 +1696,8 @@ void vsid::VSIDPlugin::processSPQueue() ++it; } queueInProcess = false; - messageHandler->writeMessage("DEBUG", "Finished sync processing queue...", vsid::MessageHandler::DebugArea::Dev); + + vsid::Logger::log(LogLevel::Debug, "Finished sync processing queue...", DebugLevel::Dev); } void vsid::VSIDPlugin::loadEse() @@ -1743,13 +1706,15 @@ void vsid::VSIDPlugin::loadEse() if (vSidConfig.is_null()) { - messageHandler->writeMessage("ERROR", "Failed to parse main config. (Critical!)"); + vsid::Logger::log(LogLevel::Error, "Failed to parse main config. (Critical!)"); + return; } if (!vSidConfig.contains("esePath")) { - messageHandler->writeMessage("ERROR", "Config value esePath is missing. (Critical!)."); + vsid::Logger::log(LogLevel::Error, "Config value esePath is missing. (Critical!)"); + return; } @@ -1775,13 +1740,13 @@ void vsid::VSIDPlugin::loadEse() if (fullEsePath.empty()) { - messageHandler->writeMessage("ERROR", "Couldn't find .ese file. Checked in: " + basePath.lexically_normal().string()); + vsid::Logger::log(LogLevel::Error, std::format("Couldn't find .ese file. Checked in [{}]", basePath.lexically_normal().string())); return; } } catch (std::filesystem::filesystem_error& e) { - messageHandler->writeMessage("ERROR", "Failed to validate ese path: " + std::string(e.what())); + vsid::Logger::log(LogLevel::Error, std::format("Failed to validate ese path [{}]", e.what())); } @@ -1797,14 +1762,16 @@ void vsid::VSIDPlugin::addOrSetSquawk(const std::string& callsign, bool forceTS) { if (this->topskyLoaded && (forceTS || this->getConfigParser().preferTopsky)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] calling TS Squawk func", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] calling TS Squawk func", callsign), DebugLevel::Func); + this->callExtFunc(callsign.c_str(), "TopSky plugin", EuroScopePlugIn::TAG_ITEM_TYPE_CALLSIGN, callsign.c_str(), "TopSky plugin", 667, POINT(), RECT()); this->lastSquawkTP = std::chrono::utc_clock::now(); } else if (this->ccamsLoaded) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] calling CCAMS Squawk func", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] calling CCAMS Squawk func", callsign), DebugLevel::Func); + this->callExtFunc(callsign.c_str(), "CCAMS", EuroScopePlugIn::TAG_ITEM_TYPE_CALLSIGN, callsign.c_str(), "CCAMS", 871, POINT(), RECT()); this->lastSquawkTP = std::chrono::utc_clock::now(); @@ -1816,12 +1783,14 @@ void vsid::VSIDPlugin::addOrSetSquawk(const std::string& callsign, bool forceTS) if (it == this->squawkQueue.end()) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] not in squawk list. Adding to it", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] not in squawk list. Adding it at the end", callsign), DebugLevel::Fpln); + this->squawkQueue.push_back(callsign); } else if (it != this->squawkQueue.end() && it != this->squawkQueue.begin()) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] in squawk list. Moving to front", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] already in squawk list. Moving to front", callsign), DebugLevel::Fpln); + this->squawkQueue.splice(this->squawkQueue.begin(), this->squawkQueue, it); } } @@ -1831,8 +1800,6 @@ bool vsid::VSIDPlugin::atcFreqMatch(const EuroScopePlugIn::CController& other, c { if (other.GetPrimaryFrequency() != local.freq) { - /*messageHandler->writeMessage("DEBUG", "[FREQ Match] other (" + std::string(other.GetCallsign()) + "): " + std::to_string(other.GetPrimaryFrequency()) + - " is NOT local (section ATC): " + std::to_string(local.freq), vsid::MessageHandler::DebugArea::Dev);*/ return false; } @@ -1850,8 +1817,9 @@ bool vsid::VSIDPlugin::atcFreqMatch(const EuroScopePlugIn::CController& other, c { if (!messageHandler->genErrorsContains(ERROR_ATC_ICAOSPLIT_FREQ_OTH + "_" + atcCallsign)) { - messageHandler->writeMessage("ERROR", "Failed to get ICAO part of other controller callsign \"" + atcCallsign + - "\" in Freq match check. Code: " + ERROR_ATC_ICAOSPLIT_FREQ_OTH); + vsid::Logger::log(LogLevel::Error, std::format("Failed to get ICAO part of other controller callsign [{}] in Freq match check. Code: {}", atcCallsign, + ERROR_ATC_ICAOSPLIT_FREQ_OTH)); + messageHandler->addGenError(ERROR_ATC_ICAOSPLIT_FREQ_OTH + "_" + atcCallsign); } } @@ -1865,23 +1833,25 @@ bool vsid::VSIDPlugin::atcFreqMatch(const EuroScopePlugIn::CController& other, c { if (!messageHandler->genErrorsContains(ERROR_ATC_ICAOSPLIT_FREQ_MY + "_" + myCallsign)) { - messageHandler->writeMessage("ERROR", "Failed to get ICAO part of my controller callsign \"" + myCallsign + - "\" in Freq match check. Code: " + ERROR_ATC_ICAOSPLIT_FREQ_MY); + vsid::Logger::log(LogLevel::Error, std::format("Failed to get ICAO part of my controller callsign [{}] in Freq match check. Code: {}", myCallsign, + ERROR_ATC_ICAOSPLIT_FREQ_MY)); + messageHandler->addGenError(ERROR_ATC_ICAOSPLIT_FREQ_MY + "_" + myCallsign); } } if (atcIcao && myIcao && *atcIcao == *myIcao && other.GetFacility() == local.facility) { - messageHandler->writeMessage("DEBUG", "[FREQ Match] other: " + atcCallsign + "(" + std::to_string(other.GetPrimaryFrequency()) + - ") IS local: " + myCallsign + "(" + std::to_string(local.freq) + ")", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[FREQ Match] other: {}({}) IS local: {}({})", atcCallsign, other.GetPrimaryFrequency(), + myCallsign, local.freq), DebugLevel::Atc); return true; } if (other.GetFacility() != local.facility) // #dev - debugging purpose { - messageHandler->writeMessage("DEBUG", "[FREQ Match] other fac: " + atcCallsign + "(" + std::to_string(other.GetFacility()) + - ") is NOT local fac: " + myCallsign + "(" + std::to_string(local.facility) + ")", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[FREQ Match] other fac: {}({}) is NOT local fac: {}({})", atcCallsign, other.GetFacility(), + myCallsign, local.facility), DebugLevel::Atc, true); + return false; } @@ -1901,11 +1871,12 @@ EuroScopePlugIn::CRadarScreen* vsid::VSIDPlugin::OnRadarScreenCreated(const char this->screenId++; this->radarScreens.insert({ this->screenId, std::make_shared(this->screenId, this->shared, sDisplayName) }); - messageHandler->writeMessage("DEBUG", "Screen created with id: " + std::to_string(this->screenId), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("Screen created with id [{}]", this->screenId), DebugLevel::Menu); + for (auto [id, screen] : this->radarScreens) { - messageHandler->writeMessage("DEBUG", "radarScreens id: " + std::to_string(id) + " screen valid: " + - ((this->radarScreens.at(id)) ? "true" : "false"), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("radarScreens id [{}] | screen valid [{}]", id, (this->radarScreens.at(id) ? "TRUE" : "FALSE")), + DebugLevel::Menu, true); } try @@ -1915,8 +1886,8 @@ EuroScopePlugIn::CRadarScreen* vsid::VSIDPlugin::OnRadarScreenCreated(const char } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Failed to return Radar Screen with id: " + std::to_string(this->screenId) + - ". Code: " + ERROR_DSP_SCREENCREATE); + vsid::Logger::log(LogLevel::Error, std::format("Failed to return Radar Screen with id [{}]. Code: {}", this->screenId, ERROR_DSP_SCREENCREATE)); + return nullptr; } @@ -1934,8 +1905,8 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, if (!fpln.IsValid()) { - messageHandler->writeMessage("ERROR", "Couldn't process flight plan as it was reported invalid (technical invalid). Code: " + - ERROR_FPLN_INVALID); + vsid::Logger::log(LogLevel::Error, std::format("Couldn't process flight plan as it was reported invalid (technical invalid) " + "OnFunctionCall. Code: {}", ERROR_FPLN_INVALID)); return; } @@ -2063,12 +2034,14 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, this->processed[callsign].noFplnUpdate = true; if (!fplnData.SetRoute(vsid::utils::join(filedRoute).c_str())) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to change flight plan! Code: " + ERROR_FPLN_SETROUTE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to change flight plan! Code: {}", callsign, ERROR_FPLN_SETROUTE)); + this->processed[callsign].noFplnUpdate = false; } if (!fplnData.AmendFlightPlan()) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to amend flight plan! Code: " + ERROR_FPLN_AMEND); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}", callsign, ERROR_FPLN_AMEND)); + this->processed[callsign].noFplnUpdate = false; } else @@ -2089,26 +2062,25 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, } catch (std::out_of_range) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] failed to retrieve rwy from selected SID: " + - sItemString, vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Error, std::format("[{}] failed to retrieve rwy from selected SID [{}]", callsign, sItemString)); }; } else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] couldn't retrieve rwy from selected SID (no rwy present in SID): " + - sItemString, vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Error, std::format("[{}] couldn't retrieve rwy from selected SID (no rwy present in SID) [{}]", callsign, sItemString)); } } if (depRWY != "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Calling manual SID with rwy : " + depRWY, vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Calling manual SID with rwy [{}]", callsign, depRWY), DebugLevel::Sid); + this->processFlightplan(fpln, false, depRWY, validDepartures[sItemString]); } else { - messageHandler->writeMessage("ERROR", "[" + callsign + "] didn't receive runway for selected SID " + - sItemString + " and didn't process. Code: " + ERROR_FPLN_SIDMAN_RWY); + vsid::Logger::log(LogLevel::Error, std::format("[{}] didn't receive runway for selected SID [{}] and didn't process. Code: {}", + callsign, sItemString, ERROR_FPLN_SIDMAN_RWY)); } } // FlightPlan->flightPlan.GetControllerAssignedData().SetFlightStripAnnotation(0, sItemString) // test on how to set annotations (-> exclusive per plugin) @@ -2270,14 +2242,14 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, if (!fplnData.SetRoute(vsid::utils::join(filedRoute).c_str())) { - messageHandler->writeMessage("ERROR", "[" + std::string(fpln.GetCallsign()) + "] - Failed to change flight plan! Code: " + - ERROR_FPLN_SETROUTE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to change flight plan! Code: {}", callsign, ERROR_FPLN_SETROUTE)); + this->processed[callsign].noFplnUpdate = false; } if (!fplnData.AmendFlightPlan()) { - messageHandler->writeMessage("ERROR", "[" + std::string(fpln.GetCallsign()) + "] - Failed to amend flight plan! Code: " + - ERROR_FPLN_AMEND); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}",callsign, ERROR_FPLN_AMEND)); + this->processed[callsign].noFplnUpdate = false; } } @@ -2315,7 +2287,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, { if (!fpln.GetControllerAssignedData().SetClearedAltitude(alt[sItemString])) { - messageHandler->writeMessage("ERROR", "Failed to set cleared altitude. Code: " + ERROR_FPLN_SETALT); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to set cleared altitude. Code: {}", callsign, ERROR_FPLN_SETALT)); } } } @@ -2360,20 +2332,20 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, if (!fplnData.SetRoute(vsid::utils::join(filedRoute).c_str())) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to change flight plan! Code: " + ERROR_FPLN_SETROUTE); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to change flight plan! Code: {}", callsign, ERROR_FPLN_SETROUTE)); } if (!vsid::fplnhelper::findRemarks(fpln, "VSID/RWY")) { if (!vsid::fplnhelper::addRemark(fpln, "VSID/RWY")) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to set remarks! Code: " + ERROR_FPLN_REMARKSET); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to set remarks! Code: {}", callsign, ERROR_FPLN_REMARKSET)); } } if (!fplnData.AmendFlightPlan()) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to amend flight plan! Code: " + ERROR_FPLN_AMEND); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}", callsign, ERROR_FPLN_AMEND)); } else if (this->activeAirports[adep].settings["auto"] && this->processed.contains(callsign)) // #checkforremoval - .contains check now above FunctionID block { @@ -2399,7 +2371,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, { if (!this->activeAirports.contains(adep)) { - messageHandler->writeMessage("WARNING", "[" + callsign + "] - Airport " + adep + " not active, can't process request!"); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] Airport [{}] not active, can't process request!", callsign, adep)); return; } if (strlen(sItemString) == 0) @@ -2432,7 +2404,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, } catch (std::out_of_range&) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] failed to split RWY from request: " + sItemString); + vsid::Logger::log(LogLevel::Error, std::format("[{}] failed to split RWY from request [{}]", callsign, sItemString)); return; } } @@ -2445,7 +2417,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, if (!isRwyReq && !isFplRwyReq && this->processed[callsign].request == req) // all req other than rwq requests { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] no rwy req and stored req matches current req", vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] no rwy req and stored req matches current req", callsign), vsid::DebugLevel::Req); if (this->activeAirports[adep].requests.contains(req)) { @@ -2453,7 +2425,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, { if (reqCallsign == callsign) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] already in request list: " + req, vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] already in request list [{}]", callsign, req), vsid::DebugLevel::Req); return; } } @@ -2461,7 +2433,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, } else if (isRwyReq && isFplRwyReq && this->processed[callsign].request.find(req)) // both current and stored req are rwy req and a (partial) match { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] rwy req and stored req (partial) matches current req", vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] rwy req and stored req (partial) matches current req", callsign), vsid::DebugLevel::Req); if (this->activeAirports[adep].rwyrequests.contains(req)) { @@ -2471,8 +2443,8 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, { if (reqCallsign == callsign) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] already in request list: " + req + " for rwy: " + reqRwy, - vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] already in request list [{}] for rwy [{}]", callsign, req, reqRwy), + vsid::DebugLevel::Req); return; } } @@ -2481,8 +2453,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, } else if (!isRwyReq && isFplRwyReq && this->processed[callsign].request.find(req)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] has rwy request and current non-rwy req (partial) matches", - vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] has rwy request and current non-rwy req (partial) matches", callsign), vsid::DebugLevel::Req); if (this->activeAirports[adep].rwyrequests.contains(req)) { @@ -2504,7 +2475,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, } else if (isRwyReq && !isFplRwyReq && this->processed[callsign].request == req) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] has no rwy req, but current req is a rwy req", vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] has no rwy req, but current req is a rwy req", callsign), vsid::DebugLevel::Req); if (this->activeAirports[adep].requests.contains(req)) { @@ -2512,7 +2483,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, { if (reqCallsign != callsign) continue; - messageHandler->writeMessage("DEBUG", "[" + callsign + "] found in req list: " + req + ". Storing time.", vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] found in req list [{}]. Storing time.", callsign, req), vsid::DebugLevel::Req); now = reqTime; break; @@ -2522,7 +2493,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, if (vsid::fplnhelper::getAtcBlock(fpln).second.empty()) { - messageHandler->writeMessage("WARNING", "[" + callsign + "] no departure runway found in flight plan for request: " + req + ". Not setting the request!"); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] no departure runway found in flight plan for request [{}]. Not setting the request!", callsign, req)); return; } @@ -2634,7 +2605,7 @@ void vsid::VSIDPlugin::OnFunctionCall(int FunctionId, const char * sItemString, if (FunctionId == TAG_FUNC_VSID_TSSQUAWK) { if (this->topskyLoaded) this->addOrSetSquawk(callsign, true); - else messageHandler->writeMessage("ERROR", "TopSky auto-assign squawk called, but TopSky was not detected."); + else vsid::Logger::log(LogLevel::Error, "TopSky auto-assign squawk called, but TopSky was not detected."); } if (FunctionId == TAG_FUNC_VSID_HOV) @@ -2800,16 +2771,16 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur fplnData.IsAmended()) ) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] not yet processed, calling processFlightplan with atcRwy: " + - blockRwy + ((!checkOnly) ? " and setting the fpln." : " and only checking the fpln"), - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] not yet processed, calling processFlightplan with atcRwy [{}] {}", + callsign, blockRwy, (!checkOnly) ? "and setting the fpln." : "and only checking the fpln"), vsid::DebugLevel::Sid); + this->processFlightplan(FlightPlan, checkOnly, blockRwy); } else { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] not yet processed, calling processFlightplan without atcRwy" + - ((!checkOnly) ? " and setting the fpln." : " and only checking the fpln"), - vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] not yet processed, calling processFlightplan without atcRwy {}", + callsign, (!checkOnly) ? "and setting the fpln." : "and only checking the fpln"), vsid::DebugLevel::Sid); + this->processFlightplan(FlightPlan, checkOnly); } @@ -2836,7 +2807,7 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur } } if (!validWpt) strcpy_s(sItemString, 16, ""); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] airborne and atc.first is no SID: \"" + blockSid + "\"", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] airborne and atc.first [{}] is no SID", callsign, blockSid), vsid::DebugLevel::Sid, true); } // processed flight plans are managed above - this is for already airborne flight plans after connecting @@ -2844,7 +2815,7 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur { *pRGB = this->configParser.getColor("customSidSuggestion"); strcpy_s(sItemString, 16, blockSid.c_str()); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] airborne and unknown. SID: \"" + blockSid + "\"", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] airborne and unknown. SID [{}]", callsign, blockSid), vsid::DebugLevel::Sid, true); } } } @@ -3083,8 +3054,7 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur this->processed[callsign].remarkChecked = true; if (this->processed[callsign].atcRWY) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepted RWY because remarks are found.", - vsid::MessageHandler::DebugArea::Rwy); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] accepted RWY because remarks are found.", callsign), vsid::DebugLevel::Rwy); } } else if (atcBlock.first == fplnData.GetOrigin() && @@ -3092,8 +3062,7 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur fplnData.IsAmended() ) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepted RWY because FPLN is amended and ICAO is found", - vsid::MessageHandler::DebugArea::Rwy); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] accepted RWY because FPLN is amended and ICAO is found", callsign), vsid::DebugLevel::Rwy); this->processed[callsign].atcRWY = true; } else if (!this->processed[callsign].atcRWY && @@ -3102,9 +3071,9 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur atcBlock.first == this->processed[callsign].customSid.name()) ) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepted RWY because SID/RWY is found \"" + atcBlock.first + "/" + atcBlock.second + - "\" SID: \"" + this->processed[callsign].sid.name() + "\" Custom SID: \"" + this->processed[callsign].customSid.name() + "\"", - vsid::MessageHandler::DebugArea::Rwy); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] accepted RWY because SID/RWY is found [{}/{}]. SID [{}] | Custom SID [{}]", + callsign, atcBlock.first, atcBlock.second, this->processed[callsign].sid.name(), this->processed[callsign].customSid.name()), vsid::DebugLevel::Rwy); + this->processed[callsign].atcRWY = true; } else if (!this->processed[callsign].atcRWY && @@ -3113,9 +3082,9 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur (fplnData.IsAmended() || FlightPlan.GetClearenceFlag()) ) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] accepted RWY because no ICAO is found and other than configured SID is found " - " and " + ((fplnData.IsAmended()) ? " fpln is amended" : "") + - ((FlightPlan.GetClearenceFlag() ? " clearance flag set" : "")), vsid::MessageHandler::DebugArea::Rwy); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] accepted RWY because no ICAO is found and other than configured SID is found and {}", + callsign, (fplnData.IsAmended()) ? " fpln is amended" : "", (FlightPlan.GetClearenceFlag() ? " clearance flag set" : "")), vsid::DebugLevel::Rwy); + this->processed[callsign].atcRWY = true; } @@ -3172,10 +3141,10 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_CONF_RWYMENU)) { - messageHandler->writeMessage("ERROR", "Failed to get RWY in the RWY menu. Check config " + - this->activeAirports[fplnData.GetOrigin()].icao + " for SID \"" + - this->processed[callsign].sid.idName() + "\". RWY value is: " + - vsid::utils::join(this->processed[callsign].sid.rwys)); + vsid::Logger::log(LogLevel::Error, std::format("Failed to get RWY in the RWY menu. Check config [{}] for SID [{}]. RWY value is [{}]", + this->activeAirports[fplnData.GetOrigin()].icao, this->processed[callsign].sid.idName(), + vsid::utils::join(this->processed[callsign].sid.rwys)), vsid::DebugLevel::Rwy); + messageHandler->addFplnError(callsign, ERROR_CONF_RWYMENU); } } @@ -3212,8 +3181,9 @@ void vsid::VSIDPlugin::OnGetTagItem(EuroScopePlugIn::CFlightPlan FlightPlan, Eur { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_REQSPLIT)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] failed to split stored request (" + request + - ") on tagItem update. Code: " + ERROR_FPLN_REQSPLIT); + vsid::Logger::log(LogLevel::Error, std::format("[{}] failed to split stored request [{}] on tagItem update. Code: {}", + callsign, request, ERROR_FPLN_REQSPLIT)); + messageHandler->addFplnError(callsign, ERROR_FPLN_REQSPLIT); } } @@ -3511,7 +3481,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { if (command.size() == 1) { - messageHandler->writeMessage("INFO", "Available commands: " + /*messageHandler->writeMessage("INFO", "Available commands: " "version / " "auto [icao] - activate automode for icao - sets force mode if lower atc online /" "area [icao] [areaname] - toggle area for icao /" @@ -3521,15 +3491,18 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) "req icao - lists request list entries / " "req icao reset [listname] - resets all request lists or specified list / " "reload [ese] - reloads the main config or the ese file / " - "Debug - toggle debug mode"); + "Debug - toggle debug mode"); #dev - new logger*/ + vsid::Logger::log(LogLevel::Info, "Available commands: version / auto [icao] - activate automode for icao - sets force mode if lower atc online / area [icao] [areaname] - toggle area for icao / rule [icao] [rulename] - toggle rule for icao / night [icao] - toggle night mode for icao / lvp [icao] - toggle lvp ops for icao / req icao - lists request list entries / req icao reset [listname] - resets all request lists or specified list / reload [ese] - reloads the main config or the ese file / Debug - toggle debug mode"); return true; } if (vsid::utils::tolower(command[1]) == "version") { - messageHandler->writeMessage("INFO", "vSID Version " + pluginVersion + - " loaded. Using nlohmann json (" + std::to_string(NLOHMANN_JSON_VERSION_MAJOR) + "." + - std::to_string(NLOHMANN_JSON_VERSION_MINOR) + "." + std::to_string(NLOHMANN_JSON_VERSION_PATCH) + - "). Using libcurl (" + curl_version() + ")"); + vsid::Logger::log(LogLevel::Info, std::format("vSID Version {} loaded. Using nlohmann json ({}.{}.{}). Using libcurl ({})", + pluginVersion, + NLOHMANN_JSON_VERSION_MAJOR, + NLOHMANN_JSON_VERSION_MINOR, + NLOHMANN_JSON_VERSION_PATCH, + curl_version())); return true; } // debugging only @@ -3537,12 +3510,12 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { for (auto &elem : this->removeProcessed) { - messageHandler->writeMessage("DEBUG", "[" + elem.first + "] being removed at: " + vsid::time::toFullString(elem.second.first) + - " and is disconnected " + ((elem.second.second) ? "YES" : "NO"), vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] being removed at [{}] and is disconnected [{}]", elem.first, + vsid::time::toFullString(elem.second.first), (elem.second.second) ? "YES" : "NO")); } if (this->removeProcessed.size() == 0) { - messageHandler->writeMessage("DEBUG", "Removed list empty", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, "Removed list empty", vsid::DebugLevel::Dev); } return true; } @@ -3561,9 +3534,9 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) std::string status = (rule.second) ? "ON" : "OFF"; ss << rule.first << ": " << status << " "; } - messageHandler->writeMessage(airport.first + " Rules", ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Rules [{}]", airport.first, ss.str())); } - else messageHandler->writeMessage(airport.first + " Rules", "No rules configured"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] Rules: No rules configured", airport.first)); } } else if (command.size() >= 3 && this->activeAirports.contains(vsid::utils::toupper(command[2]))) @@ -3579,9 +3552,9 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) std::string status = (rule.second) ? "ON " : "OFF "; ss << rule.first << ": " << status; } - messageHandler->writeMessage(icao + " Rules", ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Rules [{}]", icao, ss.str())); } - else messageHandler->writeMessage(icao + " Rules", "No rules configured"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] Rules: No rules configured", icao)); } else if (command.size() == 4) { @@ -3589,7 +3562,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (this->activeAirports[icao].customRules.contains(rule)) { this->activeAirports[icao].customRules[rule] = !this->activeAirports[icao].customRules[rule]; - messageHandler->writeMessage(icao + " Rule", rule + " " + (this->activeAirports[icao].customRules[rule] ? "ON" : "OFF")); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Rule [{}] [{}]", icao, rule, (this->activeAirports[icao].customRules[rule] ? "ON" : "OFF"))); std::erase_if(this->processed, [&](const std::pair& pFpln) { @@ -3617,16 +3590,16 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) EuroScopePlugIn::CFlightPlan FlightPlan = FlightPlanSelect(fpln.first.c_str()); auto atcBlock = vsid::fplnhelper::getAtcBlock(FlightPlan); - messageHandler->writeMessage("DEBUG", "[" + fpln.first + "] rechecking due to rule change.", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] rechecking due to rule change.", fpln.first), vsid::DebugLevel::Sid); if (atcBlock.second != "") this->processFlightplan(FlightPlan, true, atcBlock.second); else this->processFlightplan(FlightPlan, true); } } - else messageHandler->writeMessage(icao + " " + command[3], "Rule is unknown"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] [{}]: Rule is unknown", icao, command[3])); } } - else messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " not in active airports"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] not in active airports", vsid::utils::toupper(command[2]))); return true; } else if (vsid::utils::tolower(command[1]) == "lvp") @@ -3642,7 +3615,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) it++; if (it != this->activeAirports.end()) ss << " / "; } - messageHandler->writeMessage("INFO", ss.str()); + vsid::Logger::log(LogLevel::Info, ss.str()); } else if (command.size() == 3) { @@ -3651,20 +3624,21 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"]) { this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"] = 0; - messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " LVP: " + - ((this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"]) ? "ON" : "OFF") - ); + + vsid::Logger::log(LogLevel::Info, std::format("[{}] LVP [{}]", vsid::utils::toupper(command[2]), + (this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"] ? "ON" : "OFF"))); } else { this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"] = 1; - messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " LVP: " + - ((this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"]) ? "ON" : "OFF") - ); + + vsid::Logger::log(LogLevel::Info, std::format("[{}] LVP [{}]", vsid::utils::toupper(command[2]), + (this->activeAirports[vsid::utils::toupper(command[2])].settings["lvp"] ? "ON" : "OFF"))); + } this->UpdateActiveAirports(); } - else messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " is not in active airports"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] is not in active airports", vsid::utils::toupper(command[2]))); } return true; } @@ -3681,7 +3655,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) it++; if (it != this->activeAirports.end()) ss << " / "; } - messageHandler->writeMessage("INFO", ss.str()); + vsid::Logger::log(LogLevel::Info, ss.str()); } else if (command.size() == 3) { @@ -3695,12 +3669,12 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { this->activeAirports[vsid::utils::toupper(command[2])].settings["time"] = 1; } - messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " Time Mode: " + - ((this->activeAirports[vsid::utils::toupper(command[2])].settings["time"]) ? "ON" : "OFF") - ); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Time Mode [{}]", vsid::utils::toupper(command[2]), + (this->activeAirports[vsid::utils::toupper(command[2])].settings["time"] ? "ON" : "OFF"))); + this->UpdateActiveAirports(); } - else messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " is not in active airports"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] is not in active airports", vsid::utils::toupper(command[2]))); } return true; } @@ -3712,8 +3686,8 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) // DEV for (EuroScopePlugIn::CController ctr = this->ControllerSelectFirst(); ctr.IsValid(); ctr = this->ControllerSelectNext(ctr)) { - messageHandler->writeMessage("DEBUG", "[ControllerSelect] Callsign: " + std::string(ctr.GetCallsign()) + - "; SI: " + std::string(ctr.GetPositionId()), vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[ControllerSelect] Callsign [{}]; SI [{}]", ctr.GetCallsign(), + ctr.GetPositionId()), vsid::DebugLevel::Atc, true); } // END DEV @@ -3723,12 +3697,12 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) } catch (std::out_of_range) { - messageHandler->writeMessage("ERROR", "Failed to get own ATC ICAO for automode. Code: " + ERROR_CMD_ATCICAO); + vsid::Logger::log(LogLevel::Error, "Failed to get own ATC ICAO for automode. Code: " + ERROR_CMD_ATCICAO); } if (!ControllerMyself().IsController()) { - messageHandler->writeMessage("ERROR", "Automode not available for observer"); + vsid::Logger::log(LogLevel::Error, "Automode not available for observer"); return true; } if (command.size() == 2) @@ -3740,14 +3714,13 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { if (ControllerMyself().GetFacility() >= 2 && ControllerMyself().GetFacility() <= 4 && atcIcao != it->second.icao) { - messageHandler->writeMessage("DEBUG", "[" + it->second.icao + "] Skipping auto mode because own ATC ICAO does not match", vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping auto mode because own ATC ICAO does not match", it->second.icao), vsid::DebugLevel::Atc); continue; } else if (ControllerMyself().GetFacility() > 4 && !it->second.appSI.contains(atcSI) && atcIcao != it->second.icao) { - messageHandler->writeMessage("DEBUG", "[" + it->second.icao + "] Skipping auto mode because own SI is not in apt appSI or own ATC ICAO does not match", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping auto mode because own SI is not in apt appSI " + "or own ATC ICAO does not match", it->second.icao), vsid::DebugLevel::Atc); continue; } if (!it->second.settings["auto"] && it->second.controllers.size() == 0) @@ -3766,14 +3739,22 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) } else if(!it->second.settings["auto"]) { - messageHandler->writeMessage("INFO", "[" + it->first + "] Cannot activate automode. Lower or same level controller online."); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Cannot activate automode. Lower or same level controller online.", it->first)); + + std::ostringstream ss; + + for (const auto& [apt, atc] : it->second.controllers) // #dev - debugging auto mode enabling + { + ss << atc.si << " (" << apt << ") "; + } + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Controllers: {}", it->first, ss.str()), vsid::DebugLevel::Atc, true); continue; } } if (counter > 0) { - messageHandler->writeMessage("INFO", ss.str()); + vsid::Logger::log(LogLevel::Info, ss.str()); // remove processed flight plans if they're not cleared or if the set rwy is not part of depRwys anymore @@ -3785,14 +3766,14 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) EuroScopePlugIn::CFlightPlanData fplnData = fpln.GetFlightPlanData(); std::string adep = fplnData.GetOrigin(); - messageHandler->writeMessage("DEBUG", "[" + std::string(fpln.GetCallsign()) + "] for erase on auto mode activation", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] for erase on auto mode activation", std::string(fpln.GetCallsign())), vsid::DebugLevel::Dev, true); if (this->activeAirports.contains(adep) && this->activeAirports[adep].settings["auto"] && !fpln.GetClearenceFlag() && !fplnInfo.atcRWY ) { - messageHandler->writeMessage("DEBUG", "[" + std::string(fpln.GetCallsign()) + "] erased on auto mode activation", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] erased on auto mode activation", std::string(fpln.GetCallsign())), vsid::DebugLevel::Dev, true); vsid::fplnhelper::saveFplnInfo(callsign, fplnInfo, this->savedFplnInfo); @@ -3802,7 +3783,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) } ); } - else messageHandler->writeMessage("INFO", "No new automode. Check .vsid auto status for active ones."); + else vsid::Logger::log(LogLevel::Info, "No new automode. Check .vsid auto status for active ones."); } else if (command.size() > 2 && vsid::utils::tolower(command[2]) == "status") { @@ -3817,8 +3798,10 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) counter++; } } - if (counter > 0) messageHandler->writeMessage("INFO", ss.str()); - else messageHandler->writeMessage("INFO", "No active automode."); + if (counter > 0) + vsid::Logger::log(LogLevel::Info, ss.str()); + else + vsid::Logger::log(LogLevel::Info, "No active automode."); } else if (command.size() > 2 && vsid::utils::tolower(command[2]) == "off") { @@ -3826,7 +3809,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { it->second.settings["auto"] = false; } - messageHandler->writeMessage("INFO", "Automode OFF for all airports."); + vsid::Logger::log(LogLevel::Info, "Automode OFF for all airports."); } else if (command.size() > 2) { @@ -3837,21 +3820,22 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { if (ControllerMyself().GetFacility() >= 2 && ControllerMyself().GetFacility() <= 4 && atcIcao != *it) { - messageHandler->writeMessage("DEBUG", "[" + *it + "] Skipping force auto mode because own ATC ICAO does not match", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping force auto mode because own ATC ICAO does not match", *it), + vsid::DebugLevel::Atc); + continue; } else if (ControllerMyself().GetFacility() > 4 && !this->activeAirports[*it].appSI.contains(atcSI) && atcIcao != *it) { - messageHandler->writeMessage("DEBUG", "[" + *it + "] Skipping force auto mode because own SI is not in apt appSI or own ATC ICAO does not match", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping force auto mode because own SI is not in apt appSI or " + "own ATC ICAO does not match", *it), vsid::DebugLevel::Atc); + continue; } this->activeAirports[*it].settings["auto"] = !this->activeAirports[*it].settings["auto"]; - messageHandler->writeMessage("INFO", *it + " automode is: " + ((this->activeAirports[*it].settings["auto"]) ? "ON" : "OFF")); + + vsid::Logger::log(LogLevel::Info, std::format("[{}] automode [{}]", *it, (this->activeAirports[*it].settings["auto"]) ? "ON" : "OFF")); if (this->activeAirports[*it].settings["auto"]) { @@ -3883,7 +3867,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) this->activeAirports[*it].forceAuto = false; } } - else messageHandler->writeMessage("INFO", "[" + *it + "] not in active airports. Cannot set automode"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] not in active airports. Cannot set automode", *it)); } } return true; @@ -3902,9 +3886,9 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) std::string status = (area.second.isActive) ? "ON" : "OFF"; ss << area.first << ": " << status << " "; } - messageHandler->writeMessage(apt.first + " Areas", ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Areas [{}]", apt.first, ss.str())); } - else messageHandler->writeMessage(apt.first + " Areas", "No area settings configured"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] Areas: No area settings configured", apt.first)); } } else if (command.size() >= 3 && this->activeAirports.contains(vsid::utils::toupper(command[2]))) @@ -3920,9 +3904,9 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) std::string status = (area.second.isActive) ? "ON " : "OFF "; ss << area.first << ": " << status; } - messageHandler->writeMessage(icao + " Areas", ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Areas [{}]", icao, ss.str())); } - else messageHandler->writeMessage(icao + " Areas", "No area settings configured"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] Areas: No area settings configured", icao)); } else if (command.size() == 4) { @@ -3935,7 +3919,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) el.second.isActive = true; ss << el.first << ": " << ((el.second.isActive) ? "ON " : "OFF "); } - messageHandler->writeMessage(icao + " Areas", ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] Areas [{}]", icao, ss.str())); } else if (!this->activeAirports[icao].areas.empty() && area == "OFF") { @@ -3945,16 +3929,16 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) el.second.isActive = false; ss << el.first << ": " << ((el.second.isActive) ? "ON " : "OFF "); } - messageHandler->writeMessage(icao + " Areas", ss.str()); + + vsid::Logger::log(LogLevel::Info, std::format("[{}] Areas [{}]", icao, ss.str())); } else if (this->activeAirports[icao].areas.contains(area)) { this->activeAirports[icao].areas[area].isActive = !this->activeAirports[icao].areas[area].isActive; - messageHandler->writeMessage(icao + " Area", area + " " + - (this->activeAirports[icao].areas[area].isActive ? "ON" : "OFF") - ); + + vsid::Logger::log(LogLevel::Info, std::format("[{}] Area [{}] [{}]", icao, area, (this->activeAirports[icao].areas[area].isActive ? "ON" : "OFF"))); } - else messageHandler->writeMessage(icao + " " + command[3], "Area is unknown"); + else vsid::Logger::log(LogLevel::Info, std::format("[{}] [{}] Area is unknown", icao, command[3])); std::erase_if(this->processed, [&](const std::pair& pFpln) { @@ -3980,7 +3964,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { EuroScopePlugIn::CFlightPlan FlightPlan = FlightPlanSelect(callsign.c_str()); auto atcBlock = vsid::fplnhelper::getAtcBlock(FlightPlan); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Rechecking due to area change.", vsid::MessageHandler::DebugArea::Sid); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Rechecking due to area change.", callsign), vsid::DebugLevel::Sid); if (atcBlock.second != "" && FlightPlan.IsValid()) { @@ -3990,22 +3974,23 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) } } } - else messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " not in active airports"); + // else messageHandler->writeMessage("INFO", vsid::utils::toupper(command[2]) + " not in active airports"); #dev - new logger + else vsid::Logger::log(LogLevel::Info, std::format("[{}] not in active airports", command[2])); return true; } else if (vsid::utils::tolower(command[1]) == "sync") { if (!ControllerMyself().IsController()) { - messageHandler->writeMessage("ERROR", "Flight plan syncing not available for observers!"); + vsid::Logger::log(LogLevel::Error, "Flight plan syncing not available for observers!"); return true; } - messageHandler->writeMessage("DEBUG", "Syncinc all requests.", vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, "Syncing all requests.", vsid::DebugLevel::Sync); for (auto& [callsign, fpln] : this->processed) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] sync processing...", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] sync processing...", callsign), vsid::DebugLevel::Sync); EuroScopePlugIn::CFlightPlan FlightPlan = FlightPlanSelect(callsign.c_str()); if (!FlightPlan.IsValid()) continue; @@ -4027,7 +4012,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (this->activeAirports.contains(adep)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] calling sync state.", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] calling sync state.", callsign), vsid::DebugLevel::Sync); this->syncStates(FlightPlan); } @@ -4035,7 +4020,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (this->activeAirports.contains(ades)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] syncing ctlf.", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] syncing ctlf.", callsign), vsid::DebugLevel::Sync); std::string newScratch = ".VSID_CTL_" + std::string((fpln.ctl) ? "TRUE" : "FALSE"); @@ -4046,11 +4031,11 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (this->activeAirports.contains(adep)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] syncing intersection.", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] syncing intersection.", callsign), vsid::DebugLevel::Sync); if (std::string intersection = fpln.intsec.first; intersection != "") { - std::string newScratch = ".VSID_INT_" + intersection + "_" + ((fpln.intsec.second) ? "TRUE" : "FALSE"); + std::string newScratch = std::format(".VSID_INT_{}_{})", intersection, (fpln.intsec.second) ? "TRUE" : "FALSE"); this->addSyncQueue(callsign, newScratch, FlightPlan.GetControllerAssignedData().GetScratchPadString()); } @@ -4066,7 +4051,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (!this->activeAirports.contains(icao)) { - messageHandler->writeMessage("WARNING", icao + " not in active airports. Cannot check for requests"); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] not in active airports. Cannot check for requests", icao)); return true; } @@ -4083,7 +4068,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (it != req.second.end()) ss << ", "; } if (ss.str().size() == 0) ss << "No requests."; - messageHandler->writeMessage("INFO", "[" + icao + "] " + req.first + " requests: " + ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] [{}] requests [{}]", icao, req.first, ss.str())); ss.str(""); ss.clear(); } @@ -4099,7 +4084,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (it != rwyReq.end()) ss << ", "; } if (ss.str().size() == 0) ss << "No requests."; - messageHandler->writeMessage("INFO", "[" + icao + "] " + req.first + " (" + rwy + ")" + " requests: " + ss.str()); + vsid::Logger::log(LogLevel::Info, std::format("[{}] [{}] (rwy {}) requests [{}]", icao, req.first, rwy, ss.str())); ss.str(""); ss.clear(); } @@ -4115,9 +4100,10 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (reqList.size() != 0) failedReset = true; } - if (!failedReset) messageHandler->writeMessage("INFO", icao + - " all requests have been cleared."); - else messageHandler->writeMessage("INFO", icao + " failed to reset requests."); + if (!failedReset) + vsid::Logger::log(LogLevel::Info, std::format("[{}] all requests have been cleared.", icao)); + else + vsid::Logger::log(LogLevel::Info, std::format("[{}] failed to reset requests.", icao)); } else if (command.size() == 5 && vsid::utils::tolower(command[3]) == "reset") { @@ -4125,17 +4111,18 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (!this->activeAirports[icao].requests.contains(req)) { - messageHandler->writeMessage("INFO", "Unknown request queue \"" + req + "\""); + vsid::Logger::log(LogLevel::Info, std::format("Unknown request queue [{}]", req)); return true; } else this->activeAirports[icao].requests[req].clear(); - if (this->activeAirports[icao].requests[req].size() == 0) messageHandler->writeMessage("INFO", icao + - " request queue \"" + req + "\" reset"); - else messageHandler->writeMessage("INFO", icao + " request queue \"" + req + "\" failed to reset"); + if (this->activeAirports[icao].requests[req].size() == 0) + vsid::Logger::log(LogLevel::Info, std::format("[{}] request queue [{}] reset", icao, req)); + else + vsid::Logger::log(LogLevel::Info, std::format("[{}] request queue [{}] failed to reset", icao, req)); } } - else messageHandler->writeMessage("INFO", "Missing parameters for request command"); + else vsid::Logger::log(LogLevel::Info, "Missing parameters for request command"); return true; } @@ -4147,12 +4134,12 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) if (messageHandler->getLevel() != vsid::MessageHandler::Level::Debug) { messageHandler->setLevel("DEBUG"); - messageHandler->writeMessage("INFO", "DEBUG MODE: ON"); + vsid::Logger::log(LogLevel::Info, "DEBUG MODE: ON"); } else { messageHandler->setLevel("INFO"); - messageHandler->writeMessage("INFO", "DEBUG MODE: OFF"); + vsid::Logger::log(LogLevel::Info, "DEBUG MODE: OFF"); } return true; } @@ -4162,7 +4149,7 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) { messageHandler->setLevel("DEBUG"); messageHandler->setDebugArea(vsid::utils::toupper(command[2])); - messageHandler->writeMessage("INFO", "DEBUG MODE: ON"); + vsid::Logger::log(LogLevel::Info, "DEBUG MODE: ON"); } else if (vsid::utils::toupper(command[2]) == "STATUS") @@ -4177,47 +4164,70 @@ bool vsid::VSIDPlugin::OnCompileCommand(const char* sCommandLine) else if (messageHandler->getDebugArea() == vsid::MessageHandler::DebugArea::Dev) area = "DEV"; ss << " - Area is: " << area; - messageHandler->writeMessage("INFO", ss.str()); + vsid::Logger::log(LogLevel::Info, ss.str()); } else if (messageHandler->setDebugArea(vsid::utils::toupper(command[2]))) { - messageHandler->writeMessage("INFO", "DEBUG AREA: " + vsid::utils::toupper(command[2])); + vsid::Logger::log(LogLevel::Info, std::format("DEBUG AREA: {}", vsid::utils::toupper(command[2]))); } - else messageHandler->writeMessage("INFO", "Unknown Debug Level"); + else vsid::Logger::log(LogLevel::Info, "Unknown Debug Area"); return true; - } + } + } + else if (vsid::utils::tolower(command[1]) == "newdebug") + { + vsid::Logger::toggleConsole(); + + return true; + } + else if (vsid::utils::tolower(command[1]) == "log") + { + if (command.size() == 3) + { + if (vsid::utils::tolower(command[2]) == "dev") + vsid::Logger::setLogDevOnly(!vsid::Logger::getLogDevOnly()); + + vsid::Logger::log(LogLevel::Info, std::format("Log development messages: {}", (vsid::Logger::getLogDevOnly()) ? "ON" : "OFF")); + } + + return true; } else if (vsid::utils::tolower(command[1]) == "reload") { if (command.size() == 2) { - messageHandler->writeMessage("INFO", "Reloading main config..."); + vsid::Logger::log(LogLevel::Info, "Reloading main config..."); this->configParser.loadMainConfig(); } else if (command.size() == 3 && vsid::utils::tolower(command[2]) == "ese") { this->loadEse(); } - + return true; } else if (vsid::utils::tolower(command[1]) == "ghversion") { if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0) { - messageHandler->writeMessage("ERROR", "Failed to init curl_global"); + vsid::Logger::log(LogLevel::Error, "Failed to init curl_global"); return true; - } + } vsid::version::checkForUpdates(this->getConfigParser().notifyUpdate, vsid::version::parseSemVer(pluginVersion)); curl_global_cleanup(); - + + return true; + } + else if (vsid::utils::tolower(command[1]) == "atc") + { + return true; } else { - messageHandler->writeMessage("INFO", "Unknown command"); + vsid::Logger::log(LogLevel::Info, "Unknown command"); return true; } } @@ -4238,7 +4248,7 @@ void vsid::VSIDPlugin::OnFlightPlanFlightPlanDataUpdate(EuroScopePlugIn::CFlight if (this->processed.contains(callsign)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] flight plan updated", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] flight plan updated", callsign), vsid::DebugLevel::Fpln, true); //// check for the last updates to auto disable auto mode if needed //if (this->activeAirports[fplnData.GetOrigin()].settings["auto"]) @@ -4298,7 +4308,7 @@ void vsid::VSIDPlugin::OnFlightPlanFlightPlanDataUpdate(EuroScopePlugIn::CFlight { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_REMARKRMV)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to remove remarks! Code: " + ERROR_FPLN_REMARKRMV); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to remove remarks! Code: {}", callsign, ERROR_FPLN_REMARKRMV)); messageHandler->addFplnError(callsign, ERROR_FPLN_REMARKRMV); } @@ -4311,7 +4321,7 @@ void vsid::VSIDPlugin::OnFlightPlanFlightPlanDataUpdate(EuroScopePlugIn::CFlight { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_AMEND)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to amend flight plan! Code: " + ERROR_FPLN_AMEND); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}", callsign, ERROR_FPLN_AMEND)); messageHandler->addFplnError(callsign, ERROR_FPLN_AMEND); } @@ -4325,10 +4335,11 @@ void vsid::VSIDPlugin::OnFlightPlanFlightPlanDataUpdate(EuroScopePlugIn::CFlight // if we want to suppress an update that happened and skip sid checking // #evaluate needs further checking - this the right position? now several flightplanupdates again if (this->processed[callsign].noFplnUpdate) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] nofplnUpdate true. Disabling.", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] nofplnUpdate true. Disabling.", callsign), vsid::DebugLevel::Dev, true); this->processed[callsign].noFplnUpdate = false; - messageHandler->writeMessage("DEBUG", "[" + callsign + "] nofplnUpdate after disabling " + ((this->processed[callsign].noFplnUpdate) ? "TRUE" : "FALSE"), - vsid::MessageHandler::DebugArea::Dev); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] nofplnUpdate after disabling {}", callsign, ((this->processed[callsign].noFplnUpdate) ? "TRUE" : "FALSE")), + vsid::DebugLevel::Dev, true); return; } @@ -4336,9 +4347,9 @@ void vsid::VSIDPlugin::OnFlightPlanFlightPlanDataUpdate(EuroScopePlugIn::CFlight if (atcBlock.first == adep && atcBlock.second != "" && this->activeAirports.contains(adep)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] fpln updated, calling processFlightplan with atcRwy : " + atcBlock.second, - vsid::MessageHandler::DebugArea::Sid - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] fpln updated, calling processFlightplan with atcRwy [{}]", callsign, atcBlock.second), + vsid::DebugLevel::Sid); + this->processFlightplan(FlightPlan, true, atcBlock.second); // update possible rwy requests @@ -4429,16 +4440,21 @@ void vsid::VSIDPlugin::OnFlightPlanFlightPlanDataUpdate(EuroScopePlugIn::CFlight } atcSid = sid; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] fpln updated, calling processFlightplan with atcRwy : " + + /*messageHandler->writeMessage("DEBUG", "[" + callsign + "] fpln updated, calling processFlightplan with atcRwy : " + atcBlock.second + " and atcSid : " + atcSid.name(), - vsid::MessageHandler::DebugArea::Sid); + vsid::MessageHandler::DebugArea::Sid); #dev - new logger*/ + vsid::Logger::log(LogLevel::Debug, std::format("[{}] fpln updated, calling processFlightplan with atcRwy : {} and atcSid : {}", + callsign, atcBlock.second, atcSid.name()), + vsid::DebugLevel::Sid); this->processFlightplan(FlightPlan, true, atcBlock.second, atcSid); } else if(this->activeAirports.contains(adep)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] fpln updated, calling processFlightplan without atcRwy", + /*messageHandler->writeMessage("DEBUG", "[" + callsign + "] fpln updated, calling processFlightplan without atcRwy", vsid::MessageHandler::DebugArea::Sid - ); + ); #dev - new logger*/ + vsid::Logger::log(LogLevel::Debug, std::format("[{}] fpln updated, calling processFlightplan without atcRwy", callsign), + vsid::DebugLevel::Sid); this->processFlightplan(FlightPlan, true); } } @@ -4457,16 +4473,27 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_SCRATCH_PAD_STRING) { - if (spWorkerActive) + std::string scratchpad = vsid::utils::toupper(cad.GetScratchPadString()); + + if (lastScratchCS == callsign && lastScratchMsg == scratchpad) return; // #dev - new scratchpad skipping + else { - messageHandler->writeMessage("DEBUG", "SP sync worker active. Skipping current scratch evaluation", vsid::MessageHandler::DebugArea::Dev); - spWorkerActive = false; - return; + vsid::Logger::log(LogLevel::Debug, std::format("Scratchpad changed since last update. Processing scratchpad. Old CS [{}]. New CS [{}]. Old Msg [{}]. New Msg [{}]", + lastScratchCS, callsign, lastScratchMsg, scratchpad), vsid::DebugLevel::Dev, true); + + lastScratchCS = callsign; + lastScratchMsg = scratchpad; } - std::string scratchpad = vsid::utils::toupper(cad.GetScratchPadString()); + if (spWorkerActive) // #dev - new scratchpad skipping - only toggling workerActive as long as other skip is enabled + { + //messageHandler->writeMessage("DEBUG", "SP sync worker active. Skipping current scratch evaluation", vsid::MessageHandler::DebugArea::Dev); #dev - new logger + // vsid::Logger::log(LogLevel::Debug, "SP sync worker active. Skipping current scratch evaluation", vsid::DebugLevel::Dev); + spWorkerActive = false; + // return; + } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] Scratchpad entry : " + scratchpad, vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Scratchpad [{}]", callsign, scratchpad), vsid::DebugLevel::Dev); // set clearance flag @@ -4522,7 +4549,8 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: std::string atc = scratchpad.substr(pos + toFind.size(), scratchpad.size()); if (ControllerMyself().GetCallsign() != atc) { - messageHandler->writeMessage("WARNING", "[" + callsign + "] assigned SID \"" + FlightPlan.GetFlightPlanData().GetSidName() + "\" by " + atc); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] assigned SID [{}] by [{}]", callsign, + FlightPlan.GetFlightPlanData().GetSidName(), atc)); } } @@ -4561,7 +4589,7 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: std::string toFind = ".VSID_REQ_"; size_t pos = scratchpad.find(toFind); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] found \".vsid_req_\" in scratch: " + scratchpad, vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] found \".vsid_req_\" in scratch [{}]", callsign, scratchpad), vsid::DebugLevel::Req); try { @@ -4576,7 +4604,8 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: } catch (std::out_of_range&) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] failed to split req type (" + reqType + ") in scratch pad update. Stopping setting request!"); + vsid::Logger::log(LogLevel::Error, std::format("[{}] failed to split req type [{}] in scratch pad update. " + "Stopping setting request!", callsign, reqType)); return; } } @@ -4604,15 +4633,13 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: this->processed[callsign].reqTime = -1; } - messageHandler->writeMessage("DEBUG", "[" + callsign + "] removing from requests in: " + - it->first, vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] removing from requests in [{}]", callsign, it->first), vsid::DebugLevel::Req); jt = it->second.erase(jt); } if (it->first == reqType) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] (equal reqType) setting in requests in: " + - it->first, vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] (equal reqType) setting in requests in [{}]", callsign, it->first), vsid::DebugLevel::Req); it->second.insert({ callsign, reqTime }); @@ -4642,17 +4669,16 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: this->processed[callsign].request = ""; this->processed[callsign].reqTime = -1; } - - messageHandler->writeMessage("DEBUG", "[" + callsign + "] removing from rwy requests in: " + - type + "/" + it->first, vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] removing from rwy requests in [{}/{}]", callsign, + type, it->first), vsid::DebugLevel::Req); jt = it->second.erase(jt); } } if (type == reqType && !fplnRwy.empty()) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] setting in rwy requests in: " + - type + "/" + std::string(FlightPlan.GetFlightPlanData().GetDepartureRwy()), vsid::MessageHandler::DebugArea::Req); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] setting in rwy requests in [{}/{}]", callsign, type, + fplnRwy), vsid::DebugLevel::Req); rwys[fplnRwy].insert({ callsign, reqTime }); @@ -4664,10 +4690,12 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: } } else if (isRwyReq && type == reqType && fplnRwy.empty()) - messageHandler->writeMessage("WARNING", "[" + callsign + "] to be set in runway requests, but runway hasn't been set in the flight plan."); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] to be set in runway requests, but runway hasn't been set in the flight plan.", callsign)); } } - else messageHandler->writeMessage("DEBUG", "[" + callsign + "] apt " + adep + " is not an active airport in req setting", vsid::MessageHandler::DebugArea::Dev); + else + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}] is not an active airport in req setting", callsign, + adep), vsid::DebugLevel::Dev); messageHandler->removeFplnError(callsign, ERROR_FPLN_REQSET); } @@ -4675,7 +4703,8 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_REQSET)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] failed to set the request"); + vsid::Logger::log(LogLevel::Error, std::format("[{}] failed to set the request. Code: {}", callsign, ERROR_FPLN_REQSET)); + messageHandler->addFplnError(callsign, ERROR_FPLN_REQSET); } } @@ -4703,7 +4732,8 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_INTSET)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] failed to set the intersection. Code: " + ERROR_FPLN_INTSET); + vsid::Logger::log(LogLevel::Error, std::format("[{}] failed to set the intersection. Code: {}", callsign, ERROR_FPLN_INTSET)); + messageHandler->addFplnError(callsign, ERROR_FPLN_INTSET); } } @@ -4734,7 +4764,7 @@ void vsid::VSIDPlugin::OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn: if (DataType == EuroScopePlugIn::CTR_DATA_TYPE_CLEARENCE_FLAG) //#dev updating sync release for ES clearance flag as it is not seen in scratch pad { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] received clearance flag update", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] received clearance flag update", callsign), vsid::DebugLevel::Dev); if (this->spReleased.contains(callsign)) this->updateSPSyncRelease(callsign); } @@ -4847,7 +4877,7 @@ void vsid::VSIDPlugin::OnFlightPlanDisconnect(EuroScopePlugIn::CFlightPlan Fligh if (this->processed.contains(callsign)) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] disconnected from the network.", vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] disconnected from the network.", callsign), vsid::DebugLevel::Fpln); vsid::fplnhelper::saveFplnInfo(callsign, this->processed[callsign], this->savedFplnInfo); @@ -4898,7 +4928,8 @@ void vsid::VSIDPlugin::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_AMEND)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to amend flight plan! - #FFDU"); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}", callsign, ERROR_FPLN_AMEND)); + messageHandler->addFplnError(callsign, ERROR_FPLN_AMEND); } } @@ -4916,7 +4947,7 @@ void vsid::VSIDPlugin::OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget { if (adep != ades && adep != "") { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] arrived. Removing from processed.", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] arrived. Removing from processed.", callsign), vsid::DebugLevel::Fpln); if (this->savedFplnInfo.contains(callsign)) this->savedFplnInfo.erase(callsign); this->processed.erase(callsign); @@ -4945,8 +4976,9 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C { if (!messageHandler->genErrorsContains(ERROR_ATC_ICAOSPLIT + "_" + atcCallsign)) { - messageHandler->writeMessage("ERROR", "Failed to get ICAO part of controller callsign \"" + atcCallsign + - "\" in ATC update. Code: " + ERROR_ATC_ICAOSPLIT); + vsid::Logger::log(LogLevel::Error, std::format("Failed to get ICAO part of controller callsign [{}] in ATC update. Code: {}", + atcCallsign, ERROR_ATC_ICAOSPLIT)); + messageHandler->addGenError(ERROR_ATC_ICAOSPLIT + "_" + atcCallsign); } } @@ -4961,8 +4993,8 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C { atcSI = sAtc.si; - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] match found in parsed stations. Setting SI: " + atcSI, - vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] match found in parsed stations. Setting SI [{}]", + atcCallsign, atcSI), vsid::DebugLevel::Atc); break; } @@ -4971,34 +5003,28 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C if (!Controller.IsController()) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Skipping ATC because it is not a controller.", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping ATC because it is not a controller.", + atcCallsign), vsid::DebugLevel::Atc); + return; } if (atcCallsign.find("ATIS") != std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Adding ATIS to ignore list.", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Adding ATIS to ignore list.", atcCallsign), vsid::DebugLevel::Atc); this->ignoreAtc.insert(atcSI); return; } if (atcCallsign.ends_with("FMP")) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Skipping FMP station.", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping FMP station.", atcCallsign), vsid::DebugLevel::Atc); return; } if (atcFreq < 0.1 || atcFreq > 199.0) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Skipping ATC because the freq. is invalid (" + std::to_string(atcFreq) + ").", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping ATC because the freq is invalid [{}].", atcCallsign, atcFreq), vsid::DebugLevel::Atc); return; } @@ -5006,18 +5032,15 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C { if (!std::all_of(atcSI.begin(), atcSI.end(), [](char c) { return std::isdigit(static_cast(c)); })) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Adding SI to ignore list because the facility is below 2 (usually FIS)", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Adding SI to ignore list because the facility is below 2 (usually FIS).", atcCallsign), vsid::DebugLevel::Atc); this->ignoreAtc.insert(atcSI); return; } - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Skipping ATC because the facility is below 2 (usually FIS) and SI cannot be stored (SI: " + atcSI + ").", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping ATC because the facility is below 2 (usually FIS) and SI [{}] cannot be stored.", + atcCallsign, atcSI), vsid::DebugLevel::Atc); return; } @@ -5027,8 +5050,8 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C if (this->atcSiFailCounter.contains(atcCallsign)) this->atcSiFailCounter[atcCallsign]++; else this->atcSiFailCounter[atcCallsign] = 1; - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Skipping ATC because the SI is empty. Failed SI count: " + - std::to_string(this->atcSiFailCounter[atcCallsign]), vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping ATC because the SI is empty. Failed SI count [{}]", + atcCallsign, this->atcSiFailCounter[atcCallsign]), vsid::DebugLevel::Atc); return; } @@ -5037,19 +5060,18 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C if (this->atcSiFailCounter.contains(atcCallsign)) this->atcSiFailCounter[atcCallsign]++; else this->atcSiFailCounter[atcCallsign] = 1; - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Skipping ATC because the SI contains a number (SI: " + atcSI + - "). Failed SI count: " + std::to_string(this->atcSiFailCounter[atcCallsign]), vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Skipping ATC because the SI contains a number [{}]. Failed SI count [{}]", + atcCallsign, atcSI, this->atcSiFailCounter[atcCallsign]), vsid::DebugLevel::Atc); if (this->atcSiFailCounter[atcCallsign] == 10) - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Failed to get valid SI after 10 attempts. No more evaluation.", - vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Failed to get valid SI after 10 attempts. No more evaluation.", + atcCallsign), vsid::DebugLevel::Atc); return; } else if (this->atcSiFailCounter.contains(atcCallsign)) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] removing from SI Fail Counter after SI is valid (SI: " + atcSI + ")", - vsid::MessageHandler::DebugArea::Atc); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] removing from SI Fail Counter after SI [{}] is valid.", atcCallsign, atcSI), vsid::DebugLevel::Atc); this->atcSiFailCounter.erase(atcCallsign); } @@ -5078,9 +5100,7 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C } if (ignore) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Adding ATC to ignore list", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Adding ATC to ignore list.", atcCallsign), vsid::DebugLevel::Atc); this->ignoreAtc.insert(atcSI); return; } @@ -5094,9 +5114,8 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C { this->activeAirports[atcIcao].controllers[atcSI] = { atcSI, atcFac, atcFreq }; this->actAtc[atcSI] = vsid::utils::join(atcIcaos, ','); - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] Adding ATC to active ATC list", - vsid::MessageHandler::DebugArea::Atc - ); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] Adding ATC to active ATC list.", atcCallsign), vsid::DebugLevel::Atc); } if (this->activeAirports[atcIcao].settings["auto"] && @@ -5104,9 +5123,7 @@ void vsid::VSIDPlugin::OnControllerPositionUpdate(EuroScopePlugIn::CController C this->activeAirports[atcIcao].hasLowerAtc(atcMyself)) { this->activeAirports[atcIcao].settings["auto"] = false; - messageHandler->writeMessage("INFO", "Disabling auto mode for " + - atcIcao + ". " + atcCallsign + " now online." - ); + vsid::Logger::log(LogLevel::Info, std::format("Disabling auto mode for [{}]. [{}] now online.", atcIcao, atcCallsign), vsid::DebugLevel::Atc); } } } @@ -5120,30 +5137,24 @@ void vsid::VSIDPlugin::OnControllerDisconnect(EuroScopePlugIn::CController Contr { if (this->activeAirports[this->actAtc[atcSI]].controllers.contains(atcSI)) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] disconnected. Removing from ATC list for " + this->actAtc[atcSI], - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] disconnected. Removing from ATC list for [{}].", atcCallsign, + this->actAtc[atcSI]), vsid::DebugLevel::Atc); this->activeAirports[this->actAtc[atcSI]].controllers.erase(atcSI); } - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] disconnected. Removing from general active ATC list", - vsid::MessageHandler::DebugArea::Atc - ); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] disconnected. Removing from general active ATC list.", atcCallsign), vsid::DebugLevel::Atc); this->actAtc.erase(atcSI); } if (this->ignoreAtc.contains(atcSI)) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] disconnected. Removing from ignore list" + this->actAtc[atcSI], - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] disconnected. Removing from ignore list.", atcCallsign), vsid::DebugLevel::Atc); this->ignoreAtc.erase(atcSI); } if (this->atcSiFailCounter.contains(atcCallsign)) { - messageHandler->writeMessage("DEBUG", "[" + atcCallsign + "] disconnected. Removing from SI fail counter list.", - vsid::MessageHandler::DebugArea::Atc - ); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] disconnected. Removing from SI fail counter list.", atcCallsign), vsid::DebugLevel::Atc); this->atcSiFailCounter.erase(atcCallsign); } } @@ -5162,7 +5173,7 @@ void vsid::VSIDPlugin::OnAirportRunwayActivityChanged() void vsid::VSIDPlugin::UpdateActiveAirports() { - messageHandler->writeMessage("INFO", "Updating airports..."); + vsid::Logger::log(LogLevel::Info, "Updating airports...", vsid::DebugLevel::Conf); this->savedSettings.clear(); this->savedRules.clear(); this->savedAreas.clear(); @@ -5236,7 +5247,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (this->activeAirports.size() > 0) { this->configParser.loadAirportConfig(this->activeAirports, this->savedRules, this->savedSettings, this->savedAreas, this->savedRequests, this->savedRwyRequests); - messageHandler->writeMessage("DEBUG", "Checking .ese file for SID mastering...", vsid::MessageHandler::DebugArea::Conf); + + vsid::Logger::log(LogLevel::Debug, "Checking .ese file for SID mastering...", vsid::DebugLevel::Conf); //************************************ // temp storage for OID mismatches @@ -5270,10 +5282,10 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (!sid.collapsedBaseMatch(sectionSid.base)) { - messageHandler->writeMessage("DEBUG", "[" + sid.base + "] sid collapsed didn't match [" + sectionSid.base + "]", vsid::MessageHandler::DebugArea::Dev); continue; } - else messageHandler->writeMessage("DEBUG", "[" + sid.base + "] sid collapsed matched [" + sectionSid.base + "]", vsid::MessageHandler::DebugArea::Dev); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] sid collapsed matched [{}]", sid.base, sectionSid.base), vsid::DebugLevel::Dev); } if (sid.designator != (sectionSid.desig ? std::string(1, *sectionSid.desig) : "")) continue; if (!vsid::utils::contains(sid.rwys, sectionSid.rwy)) continue; @@ -5284,8 +5296,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() { sid.number = sectionSid.number; - messageHandler->writeMessage("DEBUG", "[" + sid.base + sid.number + sid.designator + "] (ID: " + sid.id + - ") mastered. Master rwy: " + sectionSid.rwy, vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{} (ID: {})] mastered. Master rwy [{}]", + sid.base + sid.number + sid.designator, sid.id, sectionSid.rwy), vsid::DebugLevel::Conf); } else if (sid.number != "" && sid.number != std::string(1, sectionSid.number) && sid.allowDiffNumbers) { @@ -5294,10 +5306,9 @@ void vsid::VSIDPlugin::UpdateActiveAirports() std::string oldNumber = sid.number; // debugging value sid.number = sectionSid.number; - messageHandler->writeMessage("DEBUG", "[" + sid.base + sid.number + sid.designator + "] (ID: " + sid.id + - ") overwritten old number (" + oldNumber + ") with " + sid.number + ". RWYs matched and diff numbers allowed." + - " Master rwy: " + sectionSid.rwy, - vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{} (ID: {})] overwritten old number [{}] with [{}]. RWYs matched " + "and diff numbers allowed. Master rwy [{}]", + sid.base + sid.number + sid.designator, sid.id, oldNumber, sid.number, sectionSid.rwy), vsid::DebugLevel::Conf); } } else if (!sid.number.empty()) // health check for possible errors in .ese config @@ -5310,17 +5321,17 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (vsid::utils::trim(sid.base + sid.number + sid.designator) == vsid::utils::trim(sectionSid.base + sectionSid.number + sectionSid.desig.value_or(' '))) { - messageHandler->writeMessage("DEBUG", "[MIL SID] " + - sid.base + sid.number + sid.designator + " equal: " + - sectionSid.base + sectionSid.number + sectionSid.desig.value_or(' '), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[MIL SID] [{}] equal [{}]", + sid.base + sid.number + sid.designator, sectionSid.base + sectionSid.number + sectionSid.desig.value_or(' ')), + vsid::DebugLevel::Conf); incompOIDs[sectionSid.apt][sid.base + sid.number + sid.designator] = true; } else { - messageHandler->writeMessage("DEBUG", "[MIL SID] " + - sid.base + sid.number + sid.designator + " NOT equal: " + - sectionSid.base + sectionSid.number + sectionSid.desig.value_or(' '), vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[MIL SID] [{}] NOT equal: [{}]", + sid.base + sid.number + sid.designator, sectionSid.base + sectionSid.number + sectionSid.desig.value_or(' ')), + vsid::DebugLevel::Dev, true); } continue; @@ -5334,13 +5345,13 @@ void vsid::VSIDPlugin::UpdateActiveAirports() } catch (const std::invalid_argument& e) { - messageHandler->writeMessage("ERROR", "Collapsing SID [" + sid.idName() + "] caused an error while collapsing base for section SID [" + - sectionSid.base + "]. Error: " + e.what()); + vsid::Logger::log(LogLevel::Error, std::format("Collapsing SID [{}] caused an error while collapsing base for section SID [{}]. Error: {}", + sid.idName(), sectionSid.base, e.what())); } catch (const std::out_of_range& e) { - messageHandler->writeMessage("ERROR", "Collapsing SID [" + sid.idName() + "] caused an error while collapsing base for section SID [" + - sectionSid.base + "]. Error: " + e.what()); + vsid::Logger::log(LogLevel::Error, std::format("Collapsing SID [{}] caused an error while collapsing base for section SID [{}]. Error: {}", + sid.idName(), sectionSid.base, e.what())); } if (currNumber == -1) continue; @@ -5348,23 +5359,24 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (currNumber > newNumber || (currNumber == 1 && newNumber == 9)) { - messageHandler->writeMessage("WARNING", "[" + sectionSid.apt + "] Check your .ese - file for " + sid.base + "?" + sid.designator + " SID! Already set number : " + - std::to_string(currNumber) + " (ID: " + sid.id + "). Now found additional number: " + std::to_string(newNumber) + - " - (Runway: " + sectionSid.rwy + "). Skipping additional number (is lower or before restarting count) due to possible sectore file error!"); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] Check your .ese - file for [{}?{}] SID! Already set number [{} (ID: {})]. " + "Now found additional number [{} - (Runway: {})]. Skipping additional number (is lower or before restarting count) due to " + "possible sector file error!", sectionSid.apt, sid.base, sid.designator, currNumber, sid.id, newNumber, sectionSid.rwy)); } else if (currNumber < newNumber || (newNumber == 1 && currNumber == 9)) { - messageHandler->writeMessage("WARNING", "[" + sectionSid.apt + "] Check your .ese-file for " + sid.base + "?" + sid.designator + " SID! Already set number: " + - std::to_string(currNumber) + " (ID: " + sid.id + "). Now found additional number: " + std::to_string(newNumber) + - " - (Runway: " + sectionSid.rwy + ") . Setting additional number (is higher or after restarting count) due to possible sectore file error!"); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] Check your.ese - file for [{}?{}] SID!Already set number [{} (ID: {})]. " + "Now found additional number [{} - (Runway: {})]. Setting additional number (is higher or after restarting count) due to " + "possible sector file error!", + sectionSid.apt, sid.base, sid.designator, currNumber, sid.id, newNumber, sectionSid.rwy)); sid.number = std::to_string(newNumber); } else if (currNumber != newNumber) { - messageHandler->writeMessage("WARNING", "[" + sectionSid.apt + "] Check your .ese-file for " + sid.base + "?" + sid.designator + " SID! Already set number: " + - std::to_string(currNumber) + " (ID: " + sid.id + "). Now found additional number: " + std::to_string(newNumber) + - " - (Runway: " + sectionSid.rwy + ") . Setting additional number as it couldn't be determined which one is more likely to be correct!"); + vsid::Logger::log(LogLevel::Warning, std::format("[{}] Check your.ese - file for [{}?{}] SID!Already set number [{} (ID: {})]. " + "Now found additional number [{} - (Runway: {})]. Setting additional number as it couldn't be determined which one is more " + "likely to be correct!", sectionSid.apt, sid.base, sid.designator, currNumber, sid.id, newNumber, sectionSid.rwy)); sid.number = std::to_string(newNumber); } @@ -5372,10 +5384,12 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (!sid.transition.empty() && sectionSid.trans.base != "") { - messageHandler->writeMessage("DEBUG", "Checking SID [" + sectionSid.base + sectionSid.number + - ((sectionSid.desig) ? std::string(1, *sectionSid.desig) : "") + "] with transition [" + sectionSid.trans.base + - ((sectionSid.trans.number) ? std::string(1, *sectionSid.trans.number) : "") + - ((sectionSid.trans.desig) ? std::string(1, *sectionSid.trans.desig) : "") + "].", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("Checking SID [{}{}{}] with transition [{}{}{}].", + sectionSid.base, sectionSid.number, + (sectionSid.desig) ? std::string(1, *sectionSid.desig) : "", + sectionSid.trans.base, + (sectionSid.trans.number) ? std::string(1, *sectionSid.trans.number) : "", + (sectionSid.trans.desig) ? std::string(1, *sectionSid.trans.desig) : "")); for (auto& [transBase, trans] : sid.transition) { @@ -5391,18 +5405,17 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (!sid.collapsedBaseMatch(sectionSid.trans.base, transBase)) { - messageHandler->writeMessage("DEBUG", "[" + transBase + "] trans collapsed didn't match [" + sectionSid.trans.base + "]", vsid::MessageHandler::DebugArea::Dev); continue; } - else messageHandler->writeMessage("DEBUG", "[" + transBase + "] trans collapsed matched [" + sectionSid.trans.base + "]", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] trans collapsed matched [{}]", + transBase, sectionSid.trans.base), vsid::DebugLevel::Conf); } if (trans.designator != (sectionSid.trans.desig ? std::string(1, *sectionSid.trans.desig) : "")) continue; if (trans.number != "") // #refactor .number to char { - messageHandler->writeMessage("DEBUG", "[" + sid.base + ((sid.number != "") ? sid.number : "?") + - sid.designator + "] (ID: " + sid.id + ") transition [" + trans.base + - trans.number + trans.designator + "] already mastered. Skipping current transition number: " + - ((sectionSid.trans.number) ? std::string(1, *sectionSid.trans.number) : ""), vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}{}{}] (ID: {}) transition [{}{}{}] already mastered. Skipping current transition number: {}", + sid.base, sid.number, sid.designator, sid.id, trans.base, trans.number, trans.designator, + (sectionSid.trans.number ? std::string(1, *sectionSid.trans.number) : "")), vsid::DebugLevel::Conf); continue; } @@ -5411,9 +5424,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() { trans.number = *sectionSid.trans.number; - messageHandler->writeMessage("DEBUG", "[" + sid.base + ((sid.number != "") ? sid.number : "?") + - sid.designator + "] (ID: " + sid.id + ") mastered transition [" + trans.base + - trans.number + trans.designator + "]", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}{}{}] (ID: {}) mastered transition [{}{}{}]", sid.base, + sid.number, sid.designator, sid.id, trans.base, trans.number, trans.designator), vsid::DebugLevel::Conf); break; } @@ -5421,9 +5433,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() { trans.number = "-1"; // dummy value for wpt transitions - messageHandler->writeMessage("DEBUG", "[" + sid.base + ((sid.number != "") ? sid.number : "?") + - sid.designator + "] (ID: " + sid.id + ") mastered transition [" + trans.base + - trans.number + trans.designator + "] (dummy number)", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}{}{}] (ID: {}) mastered transition [{}{}{}]", sid.base, + sid.number, sid.designator, sid.id, trans.base, trans.number, trans.designator), vsid::DebugLevel::Conf); break; } @@ -5452,7 +5463,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() } } - if (mismatchCount > 0) messageHandler->writeMessage("WARNING", ss.str()); + if (mismatchCount > 0) + vsid::Logger::log(LogLevel::Warning, ss.str()); ss.clear(); } @@ -5528,8 +5540,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() for (std::pair>& incompSidPair : incompSids) { - messageHandler->writeMessage("WARNING", "Check config for [" + incompSidPair.first + - "] - Could not master sids with .sct or .ese file: " + vsid::utils::join(incompSidPair.second, ',')); + vsid::Logger::log(LogLevel::Warning, std::format("Check config for [{}] - Could not master sids with .ese file [{}]", + incompSidPair.first, vsid::utils::join(incompSidPair.second, ','))); for (const std::string& incompSid : incompSidPair.second) { @@ -5540,8 +5552,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() if (incompTrans.contains(incompSidPair.first) && incompTrans[incompSidPair.first].contains(it->base + it->number + it->designator) && it->transition.size() == 0) { - messageHandler->writeMessage("DEBUG", "[" + incompSidPair.first + "] [" + it->waypoint + it->number + it->designator + - "] (ID: " + it->id + ") lost all transitions and erased", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}{}{}] (ID: {}) lost all transitions and erased", + incompSidPair.first, it->waypoint, it->number, it->designator, it->id), vsid::DebugLevel::Conf); it = this->activeAirports[incompSidPair.first].sids.erase(it); continue; @@ -5553,24 +5565,21 @@ void vsid::VSIDPlugin::UpdateActiveAirports() { if (std::string("0123456789").find_first_of(it->number) != std::string::npos) { - messageHandler->writeMessage("DEBUG", "[" + incompSidPair.first + "] [" + it->waypoint + it->number + it->designator + - "] (ID: " + it->id + ") has a number. Skipping removal (other SID with same base failed to master)", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}{}{}] (ID: {}) has a number. Skipping removal (other SID with same base failed to master)", + incompSidPair.first, it->waypoint, it->number, it->designator, it->id), vsid::DebugLevel::Conf); ++it; continue; } if (!it->transition.empty()) { - messageHandler->writeMessage("DEBUG", "[" + incompSidPair.first + "] [" + it->waypoint + - ((it->number != "") ? it->number : "?") + it->designator + "] (ID: " + it->id + - ") incompatible and erased. Transition present, double check them for validity.", - vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}{}{}] (ID: {}) incompatible and erased. Transition present, double check them for validity.", + incompSidPair.first, it->waypoint, it->number, it->designator, it->id), vsid::DebugLevel::Conf); } else { - messageHandler->writeMessage("DEBUG", "[" + incompSidPair.first + "] [" + it->waypoint + - ((it->number != "") ? it->number : "?") + it->designator + "] (ID: " + it->id + - ") incompatible and erased. No transition present.", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}{}{}] (ID: {}) incompatible and erased. No transition present.", + incompSidPair.first, it->waypoint, it->number, it->designator, it->id), vsid::DebugLevel::Conf); } it = this->activeAirports[incompSidPair.first].sids.erase(it); @@ -5579,8 +5588,8 @@ void vsid::VSIDPlugin::UpdateActiveAirports() } else if(it->number == "" && it->base == incompSid) { - messageHandler->writeMessage("DEBUG", "[" + incompSidPair.first + "] [" + it->base + - "] (ID: " + it->id + ") (base only) incompatible and erased", vsid::MessageHandler::DebugArea::Conf); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] [{}] (ID: {}) (base only) incompatible and erased", + incompSidPair.first, it->base, it->id), vsid::DebugLevel::Conf); it = this->activeAirports[incompSidPair.first].sids.erase(it); continue; @@ -5592,13 +5601,11 @@ void vsid::VSIDPlugin::UpdateActiveAirports() for (auto& [icao, sidMap] : incompTrans) { - messageHandler->writeMessage("WARNING", "Check config for [" + icao + - "] - Could not master following SIDs with transitions: "); + vsid::Logger::log(LogLevel::Warning, std::format("Check config for [{}] - Could not master following SIDs with transitions: ", icao)); for (auto& [sidName, transitions] : sidMap) { - messageHandler->writeMessage("WARNING", "SID [" + sidName + - "]: " + vsid::utils::join(transitions, ',')); + vsid::Logger::log(LogLevel::Warning, std::format("SID [{}] [{}]", sidName, vsid::utils::join(transitions, ','))); } } @@ -5613,7 +5620,7 @@ void vsid::VSIDPlugin::UpdateActiveAirports() } } - messageHandler->writeMessage("INFO", "Airports updated. [" + std::to_string(this->activeAirports.size()) + "] active."); + vsid::Logger::log(LogLevel::Info, std::format("Airports updated. [{}] active.", this->activeAirports.size())); } void vsid::VSIDPlugin::OnTimer(int Counter) @@ -5633,6 +5640,13 @@ void vsid::VSIDPlugin::OnTimer(int Counter) // catch (std::out_of_range) {} // no error reporting, we just do nothing //} + std::vector esLogs = vsid::Logger::fetchEsMsgs(); + + for (const auto& msg : esLogs) + { + this->DisplayUserMessage("vSID", "vSID", msg.c_str(), true, true, true, false, false); + } + // get info msgs printed to the chat area of ES std::pair msg = messageHandler->getMessage(); @@ -5676,18 +5690,20 @@ void vsid::VSIDPlugin::OnTimer(int Counter) { std::string callsign = this->squawkQueue.front(); - messageHandler->writeMessage("DEBUG", "[" + callsign + "] working on squawk queue", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] working on squawk queue", callsign), vsid::DebugLevel::Dev); if (this->topskyLoaded && this->getConfigParser().preferTopsky) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] calling TS Squawk func", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] calling TS Squawk func", callsign), vsid::DebugLevel::Dev); + this->callExtFunc(callsign.c_str(), "TopSky plugin", EuroScopePlugIn::TAG_ITEM_TYPE_CALLSIGN, callsign.c_str(), "TopSky plugin", 667, POINT(), RECT()); this->lastSquawkTP = std::chrono::utc_clock::now(); } else if (this->ccamsLoaded) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] calling CCAMS Squawk func", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] calling CCAMS Squawk func", callsign), vsid::DebugLevel::Dev); + this->callExtFunc(callsign.c_str(), "CCAMS", EuroScopePlugIn::TAG_ITEM_TYPE_CALLSIGN, callsign.c_str(), "CCAMS", 871, POINT(), RECT()); this->lastSquawkTP = std::chrono::utc_clock::now(); @@ -5712,7 +5728,8 @@ void vsid::VSIDPlugin::OnTimer(int Counter) { if (!this->removeProcessed.contains(it->first)) { - messageHandler->writeMessage("DEBUG", "[" + it->first + "] is invalid. Removal in 1 min.", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] is invalid. Removal in 1 min.", it->first), vsid::DebugLevel::Fpln); + auto now = std::chrono::utc_clock::now() + std::chrono::minutes{ 1 }; this->removeProcessed[it->first] = { now, true }; // assume fpln is disconnected for some reason, might come back } @@ -5724,8 +5741,9 @@ void vsid::VSIDPlugin::OnTimer(int Counter) if(this->outOfVis(fpln)) { - messageHandler->writeMessage("DEBUG", "[" + it->first + "] is further away than my range of NM " + - std::to_string(ControllerMyself().GetRange()), vsid::MessageHandler::DebugArea::Dev); + + vsid::Logger::log(LogLevel::Debug, std::format("[{}] is further away than my range of NM [{}]", + it->first, ControllerMyself().GetRange()), vsid::DebugLevel::Fpln); this->removeProcessed.erase(it->first); this->savedFplnInfo.erase(it->first); @@ -5741,7 +5759,8 @@ void vsid::VSIDPlugin::OnTimer(int Counter) { if (!messageHandler->getFplnErrors(callsign).contains(ERROR_FPLN_AMEND)) { - messageHandler->writeMessage("ERROR", "[" + callsign + "] - Failed to amend flight plan! - #FFDU"); + vsid::Logger::log(LogLevel::Error, std::format("[{}] - Failed to amend flight plan! Code: {}", callsign, ERROR_FPLN_AMEND)); + messageHandler->addFplnError(callsign, ERROR_FPLN_AMEND); } @@ -5770,7 +5789,7 @@ void vsid::VSIDPlugin::OnTimer(int Counter) if (it->second.second && fpln.IsValid() && !this->outOfVis(fpln)) { - messageHandler->writeMessage("DEBUG", "[" + it->first + "] reconnected.", vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] reconnected.", it->first), vsid::DebugLevel::Fpln); it = this->removeProcessed.erase(it); continue; } @@ -5782,7 +5801,7 @@ void vsid::VSIDPlugin::OnTimer(int Counter) this->removeFromRequests(callsign, icao); - messageHandler->writeMessage("DEBUG", "[" + it->first + "] exceeded disconnection time. Dropping", vsid::MessageHandler::DebugArea::Fpln); + vsid::Logger::log(LogLevel::Debug, std::format("[{}] exceeded disconnection time. Dropping", it->first), vsid::DebugLevel::Fpln); std::erase_if(this->processed, [&](const auto& fpln) { return it->first == fpln.first; }); if (this->savedFplnInfo.contains(it->first)) this->savedFplnInfo.erase(it->first); // #refactor - erase_if @@ -5796,25 +5815,26 @@ void vsid::VSIDPlugin::OnTimer(int Counter) void vsid::VSIDPlugin::deleteScreen(int id) { - messageHandler->writeMessage("DEBUG", "(deleteScreen) size: " + std::to_string(this->radarScreens.size()), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("(deleteScreen) size: {}", this->radarScreens.size()), vsid::DebugLevel::Menu); for (auto [id, screen] : this->radarScreens) { - messageHandler->writeMessage("DEBUG", "(deleteScreen) present id: " + std::to_string(id) + " is valid: " + - ((this->radarScreens.at(id) ? "true" : "false")), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("(deleteScreen) present id [{}] is valid [{}]", id, this->radarScreens.at(id) ? "TRUE" : "FALSE"), + vsid::DebugLevel::Menu); } if (this->radarScreens.contains(id)) { - messageHandler->writeMessage("DEBUG", "(deleteScreen) Removing id: " + std::to_string(id) + " use count: " + - std::to_string(this->radarScreens.at(id).use_count()), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("(deleteScreen) Removing id [{}] use count [{}]", id, this->radarScreens.at(id).use_count()), + vsid::DebugLevel::Menu); + this->radarScreens.erase(id); } else { - messageHandler->writeMessage("DEBUG", "(deleteScreen) id: " + std::to_string(id) + " is unknown.", vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("(deleteScreen) id [{}] is unknown.", id), vsid::DebugLevel::Menu); } - messageHandler->writeMessage("DEBUG", "(deleteScreen) size after deletion: " + std::to_string(this->radarScreens.size()), vsid::MessageHandler::DebugArea::Menu); + vsid::Logger::log(LogLevel::Debug, std::format("(deleteScreen) size after deletion [{}]", this->radarScreens.size()), vsid::DebugLevel::Menu); } void vsid::VSIDPlugin::callExtFunc(const char* sCallsign, const char* sItemPlugInName, int ItemCode, const char* sItemString, const char* sFunctionPlugInName, @@ -5833,8 +5853,8 @@ void vsid::VSIDPlugin::callExtFunc(const char* sCallsign, const char* sItemPlugI } else { - messageHandler->writeMessage("ERROR", "Couldn't call ext func for [" + std::string(sCallsign) + "] as the screen (id: " + - std::to_string(id) + ") couldn't be called. Code: " + ERROR_FPLN_EXTFUNC); + vsid::Logger::log(LogLevel::Error, std::format("Couldn't call ext func for [{}] as the screen (id: {}) couldn't be called. Code: {}", + sCallsign, id, ERROR_FPLN_EXTFUNC), vsid::DebugLevel::Menu); } } } @@ -5850,6 +5870,8 @@ void vsid::VSIDPlugin::exit() this->shared.reset(); if(this->curlInit) curl_global_cleanup(); + + vsid::Logger::shutdown(); } void __declspec (dllexport) EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInstance) diff --git a/vSIDPlugin.h b/vSIDPlugin.h index 5fb1f24..a61f58b 100644 --- a/vSIDPlugin.h +++ b/vSIDPlugin.h @@ -32,6 +32,8 @@ along with this program. If not, see . #include #include +#include + #include // only to call the update check #include "include/es/EuroScopePlugIn.h" @@ -43,6 +45,8 @@ along with this program. If not, see . #include "eseparser.h" #include "versionchecker.h" +#include "logger.h" + namespace vsid { const std::string pluginName = "vSID"; @@ -471,6 +475,10 @@ namespace vsid // if curl init was successfull bool curlInit = false; + // #dev scratchpad storage + std::string lastScratchCS; + std::string lastScratchMsg; + //************************************ // Description: Loads and updates the active airports with available configs // Method: UpdateActiveAirports @@ -505,8 +513,8 @@ namespace vsid //************************************ inline void addSyncQueue(const std::string& callsign, const std::string& newScratch, const std::string& oldScratch) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] adding scratch to queue. New: \"" + - newScratch + "\" | Old: \"" + oldScratch + "\"", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] adding scratch to queue. New [{}] | Old: [{}]", callsign, + newScratch, oldScratch), vsid::DebugLevel::Sync); if (!this->spReleased.contains(callsign)) this->spReleased[callsign] = true; this->syncQueue[callsign].push_back({newScratch, oldScratch}); @@ -523,10 +531,10 @@ namespace vsid //************************************ inline void updateSPSyncRelease(std::string callsign) { - messageHandler->writeMessage("DEBUG", "[" + callsign + "] updating sync release", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] updating sync release", callsign), vsid::DebugLevel::Sync); if(this->spReleased.contains(callsign)) this->spReleased[callsign] = true; - else messageHandler->writeMessage("DEBUG", "[" + callsign + "] failed to update sync release. Not held in release list.", vsid::MessageHandler::DebugArea::Dev); + else vsid::Logger::log(vsid::LogLevel::Debug, std::format("[{}] failed to update sync release. Not held in release list.", callsign), vsid::DebugLevel::Sync); } //************************************ diff --git a/versionchecker.cpp b/versionchecker.cpp index 9229ffd..e0ca7fd 100644 --- a/versionchecker.cpp +++ b/versionchecker.cpp @@ -6,6 +6,7 @@ #include "versionchecker.h" #include "messageHandler.h" +#include "logger.h" #include "include/nlohmann/json.hpp" using json = nlohmann::ordered_json; @@ -90,8 +91,7 @@ std::optional vsid::version::getHttp(bool prerelease) if (res != CURLE_OK || httpCode < 200 || httpCode >= 300) { - messageHandler->writeMessage("ERROR", "Curl error: " + std::string(curl_easy_strerror(res)) + " - Curl Code: " + std::to_string(res) + - " - Http Code: " + std::to_string(httpCode)); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Curl error [{}] - Curl Code [{}] - Http Code [{}]", curl_easy_strerror(res), std::to_string(res), httpCode)); return std::nullopt; } return response; @@ -118,7 +118,7 @@ std::optional vsid::version::getRelease(bool prerelease) } catch (json::parse_error& e) { - messageHandler->writeMessage("ERROR", "Failed to parse github version: " + std::string(e.what())); + vsid::Logger::log(vsid::LogLevel::Error, std::format("Failed to parse github version: {}", e.what())); return std::nullopt; } @@ -131,25 +131,25 @@ void vsid::version::checkForUpdates(int notify, const std::optionalwriteMessage("DEBUG", "Failed to get local version. Value was empty", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, "Failed to get local version. Value was empty", vsid::DebugLevel::Dev); return; } if (!ghv) { - messageHandler->writeMessage("DEBUG", "Failed to get github version. Value was empty", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, "Failed to get github version. Value was empty", vsid::DebugLevel::Dev); return; } else { - messageHandler->writeMessage("DEBUG", "Github version: " + ((ghv.has_value()) ? semverToString(ghv.value()) : " Failed to parse version."), - vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, std::format("Github version [{}]", + (ghv.has_value() ? vsid::version::semverToString(ghv.value()) : " Failed to parse version.")), vsid::DebugLevel::Dev); } int comp = vsid::version::compSemVer(localVersion.value(), ghv.value()); if (comp == 0) { - messageHandler->writeMessage("DEBUG", "No new version found on github", vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, "No new version found on github", vsid::DebugLevel::Dev); return; } @@ -160,26 +160,24 @@ void vsid::version::checkForUpdates(int notify, const std::optionalwriteMessage("DEBUG", "New pre-release version found but notifying only for stable releases.", - vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, "New pre-release version found but notifying only for stable releases.", vsid::DebugLevel::Dev); break; } - messageHandler->writeMessage("INFO", "New Update available. Local version: " + vsid::version::semverToString(localVersion.value()) + - " | Github version: " + vsid::version::semverToString(ghv.value())); + vsid::Logger::log(vsid::LogLevel::Info, std::format("New Update available. Local version [{}] | Github version [{}]", + vsid::version::semverToString(localVersion.value()), vsid::version::semverToString(ghv.value()))); break; case 2: if (comp == 2) { - messageHandler->writeMessage("DEBUG", "New pre-release version found but notifying only for stable releases.", - vsid::MessageHandler::DebugArea::Dev); + vsid::Logger::log(vsid::LogLevel::Debug, "New pre-release version found but notifying only for stable releases.", vsid::DebugLevel::Dev); break; } goto showmsg; case 3: - messageHandler->writeMessage("INFO", "New Update (pre-release) available. Local version: " + vsid::version::semverToString(localVersion.value()) + - " | Github version: " + vsid::version::semverToString(ghv.value())); + vsid::Logger::log(vsid::LogLevel::Info, std::format("New Update (pre-release) available. Local version: {} | Github version: {}", + vsid::version::semverToString(localVersion.value()), vsid::version::semverToString(ghv.value()))); break; case 4: @@ -187,14 +185,13 @@ void vsid::version::checkForUpdates(int notify, const std::optionalwriteMessage("WARNING", "Didn't check for updates. Improper notification value in main config (" + - std::to_string(notify) + "). Should be 0 - 4."); + vsid::Logger::log(vsid::LogLevel::Warning, std::format("Didn't check for updates. Improper notification value in main config ({}). Should be 0 - 4.", notify)); } }