diff --git a/client_files/export/main.cpp b/client_files/export/main.cpp index fd8b19026..ff7f1f3dd 100644 --- a/client_files/export/main.cpp +++ b/client_files/export/main.cpp @@ -83,8 +83,9 @@ int main(int argc, char **argv) content_db.SetMysql(database.getMySQL()); } - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->StartFileLogs(); std::string arg_1; diff --git a/client_files/import/main.cpp b/client_files/import/main.cpp index 64b2aee41..2fbdf421a 100644 --- a/client_files/import/main.cpp +++ b/client_files/import/main.cpp @@ -80,8 +80,9 @@ int main(int argc, char **argv) { content_db.SetMysql(database.getMySQL()); } - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->StartFileLogs(); ImportSpells(&content_db); ImportSkillCaps(&content_db); diff --git a/common/database.cpp b/common/database.cpp index 1290d289a..cf9752350 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -2191,95 +2191,6 @@ uint32 Database::GetRaidIDByCharID(uint32 character_id) { return 0; } -/** - * @param log_settings - */ -void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) -{ - std::string query = - "SELECT " - "log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay " - "FROM " - "logsys_categories " - "ORDER BY log_category_id"; - - auto results = QueryDatabase(query); - int log_category_id = 0; - - int *categories_in_database = new int[1000]; - - for (auto row = results.begin(); row != results.end(); ++row) { - log_category_id = atoi(row[0]); - if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) { - continue; - } - - log_settings[log_category_id].log_to_console = static_cast(atoi(row[2])); - log_settings[log_category_id].log_to_file = static_cast(atoi(row[3])); - log_settings[log_category_id].log_to_gmsay = static_cast(atoi(row[4])); - - /** - * Determine if any output method is enabled for the category - * and set it to 1 so it can used to check if category is enabled - */ - const bool log_to_console = log_settings[log_category_id].log_to_console > 0; - const bool log_to_file = log_settings[log_category_id].log_to_file > 0; - const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0; - const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; - - if (is_category_enabled) { - log_settings[log_category_id].is_category_enabled = 1; - } - - /** - * This determines whether or not the process needs to actually file log anything. - * If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open - */ - if (log_settings[log_category_id].log_to_file > 0) { - LogSys.file_logs_enabled = true; - } - - categories_in_database[log_category_id] = 1; - } - - /** - * Auto inject categories that don't exist in the database... - */ - for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { - if (categories_in_database[log_index] != 1) { - - LogInfo( - "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", - Logs::LogCategoryName[log_index] - ); - - auto inject_query = fmt::format( - "INSERT INTO logsys_categories " - "(log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay) " - "VALUES " - "({0}, '{1}', {2}, {3}, {4})", - log_index, - EscapeString(Logs::LogCategoryName[log_index]), - std::to_string(log_settings[log_index].log_to_console), - std::to_string(log_settings[log_index].log_to_file), - std::to_string(log_settings[log_index].log_to_gmsay) - ); - - QueryDatabase(inject_query); - } - } - - delete[] categories_in_database; -} - int Database::CountInvSnapshots() { std::string query = StringFormat("SELECT COUNT(*) FROM (SELECT * FROM `inventory_snapshots` a GROUP BY `charid`, `time_index`) b"); auto results = QueryDatabase(query); diff --git a/common/database.h b/common/database.h index 1b3b736ae..79c52c514 100644 --- a/common/database.h +++ b/common/database.h @@ -78,6 +78,7 @@ class PTimerList; #define SQL(...) #__VA_ARGS__ +class LogSettings; class Database : public DBcore { public: Database(); @@ -268,8 +269,6 @@ public: int CountInvSnapshots(); void ClearInvSnapshots(bool from_now = false); - /* EQEmuLogSys */ - void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings); private: diff --git a/common/eqemu_logsys.cpp b/common/eqemu_logsys.cpp index ad43ee61d..950c17107 100644 --- a/common/eqemu_logsys.cpp +++ b/common/eqemu_logsys.cpp @@ -22,8 +22,8 @@ #include "rulesys.h" #include "platform.h" #include "string_util.h" -#include "database.h" #include "misc.h" +#include "repositories/logsys_categories_repository.h" #include #include @@ -31,6 +31,7 @@ #include #include #include +#include std::ofstream process_log; @@ -96,7 +97,7 @@ EQEmuLogSys::EQEmuLogSys() */ EQEmuLogSys::~EQEmuLogSys() = default; -void EQEmuLogSys::LoadLogSettingsDefaults() +EQEmuLogSys *EQEmuLogSys::LoadLogSettingsDefaults() { /** * Get Executable platform currently running this code (Zone/World/etc) @@ -177,6 +178,8 @@ void EQEmuLogSys::LoadLogSettingsDefaults() else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformHC) { platform_file_name = "hc"; } + + return this; } /** @@ -601,3 +604,76 @@ void EQEmuLogSys::EnableConsoleLogging() log_settings[log_index].is_category_enabled = 1; } } + +EQEmuLogSys *EQEmuLogSys::LoadLogDatabaseSettings() +{ + auto categories = LogsysCategoriesRepository::GetWhere( + *m_database, + "TRUE ORDER BY log_category_id" + ); + + // keep track of categories + std::vector db_categories{}; + db_categories.reserve(categories.size()); + + // loop through database categories + for (auto &c: categories) { + if (c.log_category_id <= Logs::None || c.log_category_id >= Logs::MaxCategoryID) { + continue; + } + + log_settings[c.log_category_id].log_to_console = static_cast(c.log_to_console); + log_settings[c.log_category_id].log_to_file = static_cast(c.log_to_file); + log_settings[c.log_category_id].log_to_gmsay = static_cast(c.log_to_gmsay); + + // Determine if any output method is enabled for the category + // and set it to 1 so it can used to check if category is enabled + const bool log_to_console = log_settings[c.log_category_id].log_to_console > 0; + const bool log_to_file = log_settings[c.log_category_id].log_to_file > 0; + const bool log_to_gmsay = log_settings[c.log_category_id].log_to_gmsay > 0; + const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; + + if (is_category_enabled) { + log_settings[c.log_category_id].is_category_enabled = 1; + } + + // This determines whether or not the process needs to actually file log anything. + // If we go through this whole loop and nothing is set to any debug level, there + // is no point to create a file or keep anything open + if (log_settings[c.log_category_id].log_to_file > 0) { + LogSys.file_logs_enabled = true; + } + + db_categories.emplace_back(c.log_category_id); + } + + // Auto inject categories that don't exist in the database... + for (int i = Logs::AA; i != Logs::MaxCategoryID; i++) { + if (std::find(db_categories.begin(), db_categories.end(), i) == db_categories.end()) { + LogInfo( + "Automatically adding new log category [{0}]", + Logs::LogCategoryName[i] + ); + + auto new_category = LogsysCategoriesRepository::NewEntity(); + new_category.log_category_id = i; + new_category.log_category_description = EscapeString(Logs::LogCategoryName[i]); + new_category.log_to_console = log_settings[i].log_to_console; + new_category.log_to_gmsay = log_settings[i].log_to_gmsay; + new_category.log_to_file = log_settings[i].log_to_file; + + LogsysCategoriesRepository::InsertOne(*m_database, new_category); + } + } + + LogInfo("Loaded [{}] log categories", categories.size()); + + return this; +} + +EQEmuLogSys *EQEmuLogSys::SetDatabase(Database *db) +{ + m_database = db; + + return this; +} diff --git a/common/eqemu_logsys.h b/common/eqemu_logsys.h index 0b33b55a3..4db6cedb2 100644 --- a/common/eqemu_logsys.h +++ b/common/eqemu_logsys.h @@ -23,8 +23,9 @@ #include #include -#include +#include #include +#include #ifdef _WIN32 #ifdef utf16_to_utf8 @@ -37,9 +38,9 @@ namespace Logs { enum DebugLevel { - General = 1, /* 1 - Low-Level general debugging, useful info on single line */ - Moderate, /* 2 - Informational based, used in functions, when particular things load */ - Detail /* 3 - Use this for extreme detail in logging, usually in extreme debugging in the stack or interprocess communication */ + General = 1, // 1 - Low-Level general debugging, useful info on single line + Moderate, // 2 - Informational based, used in functions, when particular things load + Detail // 3 - Use this for extreme detail in logging, usually in extreme debugging in the stack or interprocess communication }; /** @@ -127,7 +128,7 @@ namespace Logs { /** * If you add to this, make sure you update LogCategory */ - static const char* LogCategoryName[LogCategory::MaxCategoryID] = { + static const char *LogCategoryName[LogCategory::MaxCategoryID] = { "", "AA", "AI", @@ -206,6 +207,8 @@ namespace Logs { #include "eqemu_logsys_log_aliases.h" +class Database; + class EQEmuLogSys { public: EQEmuLogSys(); @@ -216,7 +219,8 @@ public: * This should be handled on deconstructor but to be safe we use it anyways. */ void CloseFileLogs(); - void LoadLogSettingsDefaults(); + EQEmuLogSys *LoadLogSettingsDefaults(); + EQEmuLogSys *LoadLogDatabaseSettings(); /** * @param directory_name @@ -246,7 +250,7 @@ public: * Used in file logs to prepend a timestamp entry for logs * @param time_stamp */ - void SetCurrentTimeStamp(char* time_stamp); + void SetCurrentTimeStamp(char *time_stamp); /** * @param log_name @@ -273,101 +277,53 @@ public: /** * Internally used memory reference for all log settings per category * These are loaded via DB and have defaults loaded in LoadLogSettingsDefaults - * Database loaded via Database::LoadLogSettings(log_settings) + * Database loaded via LogSys.SetDatabase(&database)->LoadLogDatabaseSettings(); */ LogSettings log_settings[Logs::LogCategory::MaxCategoryID]{}; bool file_logs_enabled = false; - /** - * Sets Executable platform (Zone/World/UCS) etc. - */ - int log_platform = 0; + int log_platform = 0; + std::string platform_file_name; - /** - * File name used in writing logs - */ - std::string platform_file_name; - /** - * GMSay Client Message colors mapped by category - * - * @param log_category - * @return - */ + // gmsay uint16 GetGMSayColorFromCategory(uint16 log_category); - /** - * @param f - */ - void SetGMSayHandler(std::function f) { on_log_gmsay_hook = f; } + EQEmuLogSys * SetGMSayHandler(std::function f) { + on_log_gmsay_hook = f; + return this; + } - /** - * @param f - */ - void SetConsoleHandler(std::function f) { on_log_console_hook = f; } - - /** - * Silence console logging - */ + // console + void SetConsoleHandler( + std::function f + ) { on_log_console_hook = f; } void SilenceConsoleLogging(); - - /** - * Turn on all console logging - */ void EnableConsoleLogging(); + // database + EQEmuLogSys *SetDatabase(Database *db); + private: - /** - * Callback pointer to zone process for hooking logs to zone using GMSay - */ - std::function on_log_gmsay_hook; - std::function on_log_console_hook; + // reference to database + Database *m_database; + + std::function on_log_gmsay_hook; + std::function on_log_console_hook; - /** - * Formats log messages like '[Category] This is a log message' - */ std::string FormatOutMessageString(uint16 log_category, const std::string &in_message); - - /** - * Linux console color messages mapped by category - * - * @param log_category - * @return - */ std::string GetLinuxConsoleColorFromCategory(uint16 log_category); - - /** - * Windows console color messages mapped by category - */ uint16 GetWindowsConsoleColorFromCategory(uint16 log_category); - /** - * @param debug_level - * @param log_category - * @param message - */ void ProcessConsoleMessage(uint16 debug_level, uint16 log_category, const std::string &message); - - /** - * @param debug_level - * @param log_category - * @param message - */ void ProcessGMSay(uint16 debug_level, uint16 log_category, const std::string &message); - - /** - * @param debug_level - * @param log_category - * @param message - */ void ProcessLogWrite(uint16 debug_level, uint16 log_category, const std::string &message); - - /** - * @param log_category - * @return - */ bool IsRfc5424LogCategory(uint16 log_category); }; diff --git a/common/repositories/base/base_logsys_categories_repository.h b/common/repositories/base/base_logsys_categories_repository.h index 4077e32f7..fd15aec24 100644 --- a/common/repositories/base/base_logsys_categories_repository.h +++ b/common/repositories/base/base_logsys_categories_repository.h @@ -4,7 +4,7 @@ * This repository was automatically generated and is NOT to be modified directly. * Any repository modifications are meant to be made to the repository extending the base. * Any modifications to base repositories are to be made by the generator only - * + * * @generator ./utils/scripts/generators/repository-generator.pl * @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories */ diff --git a/loginserver/database.cpp b/loginserver/database.cpp index 35f49e0eb..8bf481d20 100644 --- a/loginserver/database.cpp +++ b/loginserver/database.cpp @@ -598,95 +598,6 @@ MySQLRequestResult Database::GetLoginserverApiTokens() return QueryDatabase("SELECT token, can_write, can_read FROM login_api_tokens"); } -/** - * @param log_settings - */ -void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) -{ - std::string query = - "SELECT " - "log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay " - "FROM " - "logsys_categories " - "ORDER BY log_category_id"; - - auto results = QueryDatabase(query); - int log_category_id = 0; - - int *categories_in_database = new int[1000]; - - for (auto row = results.begin(); row != results.end(); ++row) { - log_category_id = atoi(row[0]); - if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) { - continue; - } - - log_settings[log_category_id].log_to_console = static_cast(atoi(row[2])); - log_settings[log_category_id].log_to_file = static_cast(atoi(row[3])); - log_settings[log_category_id].log_to_gmsay = static_cast(atoi(row[4])); - - /** - * Determine if any output method is enabled for the category - * and set it to 1 so it can used to check if category is enabled - */ - const bool log_to_console = log_settings[log_category_id].log_to_console > 0; - const bool log_to_file = log_settings[log_category_id].log_to_file > 0; - const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0; - const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; - - if (is_category_enabled) { - log_settings[log_category_id].is_category_enabled = 1; - } - - /** - * This determines whether or not the process needs to actually file log anything. - * If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open - */ - if (log_settings[log_category_id].log_to_file > 0) { - LogSys.file_logs_enabled = true; - } - - categories_in_database[log_category_id] = 1; - } - - /** - * Auto inject categories that don't exist in the database... - */ - for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { - if (categories_in_database[log_index] != 1) { - - LogInfo( - "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", - Logs::LogCategoryName[log_index] - ); - - auto inject_query = fmt::format( - "INSERT INTO logsys_categories " - "(log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay) " - "VALUES " - "({0}, '{1}', {2}, {3}, {4})", - log_index, - EscapeString(Logs::LogCategoryName[log_index]), - std::to_string(log_settings[log_index].log_to_console), - std::to_string(log_settings[log_index].log_to_file), - std::to_string(log_settings[log_index].log_to_gmsay) - ); - - QueryDatabase(inject_query); - } - } - - delete[] categories_in_database; -} - /** * @param account_name * @param account_password @@ -806,4 +717,4 @@ Database::DbLoginServerAccount Database::GetLoginServerAccountByAccountName( } return login_server_account; -} \ No newline at end of file +} diff --git a/loginserver/database.h b/loginserver/database.h index 8ffcb187b..ecb809ee9 100644 --- a/loginserver/database.h +++ b/loginserver/database.h @@ -201,11 +201,6 @@ public: unsigned int &server_admin_id ); - /** - * @param log_settings - */ - void LoadLogSettings(EQEmuLogSys::LogSettings *log_settings); - /** * @param write_mode * @param read_mode diff --git a/loginserver/main.cpp b/loginserver/main.cpp index 9e6006342..d1f001957 100644 --- a/loginserver/main.cpp +++ b/loginserver/main.cpp @@ -165,8 +165,7 @@ int main(int argc, char **argv) LoadDatabaseConnection(); if (argc == 1) { - server.db->LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.LoadLogDatabaseSettings()->StartFileLogs(); } /** diff --git a/queryserv/database.cpp b/queryserv/database.cpp index 20465e6b5..8f2de678d 100644 --- a/queryserv/database.cpp +++ b/queryserv/database.cpp @@ -448,89 +448,3 @@ void Database::GeneralQueryReceive(ServerPacket *pack) safe_delete_array(queryBuffer); } - -void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) -{ - std::string query = - "SELECT " - "log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay " - "FROM " - "logsys_categories " - "ORDER BY log_category_id"; - - auto results = QueryDatabase(query); - int log_category_id = 0; - - int *categories_in_database = new int[1000]; - - for (auto row = results.begin(); row != results.end(); ++row) { - log_category_id = atoi(row[0]); - if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) { - continue; - } - - log_settings[log_category_id].log_to_console = static_cast(atoi(row[2])); - log_settings[log_category_id].log_to_file = static_cast(atoi(row[3])); - log_settings[log_category_id].log_to_gmsay = static_cast(atoi(row[4])); - - /** - * Determine if any output method is enabled for the category - * and set it to 1 so it can used to check if category is enabled - */ - const bool log_to_console = log_settings[log_category_id].log_to_console > 0; - const bool log_to_file = log_settings[log_category_id].log_to_file > 0; - const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0; - const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; - - if (is_category_enabled) { - log_settings[log_category_id].is_category_enabled = 1; - } - - /** - * This determines whether or not the process needs to actually file log anything. - * If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open - */ - if (log_settings[log_category_id].log_to_file > 0) { - LogSys.file_logs_enabled = true; - } - - categories_in_database[log_category_id] = 1; - } - - /** - * Auto inject categories that don't exist in the database... - */ - for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { - if (categories_in_database[log_index] != 1) { - - LogInfo( - "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", - Logs::LogCategoryName[log_index] - ); - - auto inject_query = fmt::format( - "INSERT INTO logsys_categories " - "(log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay) " - "VALUES " - "({0}, '{1}', {2}, {3}, {4})", - log_index, - EscapeString(Logs::LogCategoryName[log_index]), - std::to_string(log_settings[log_index].log_to_console), - std::to_string(log_settings[log_index].log_to_file), - std::to_string(log_settings[log_index].log_to_gmsay) - ); - - QueryDatabase(inject_query); - } - } - - delete[] categories_in_database; -} \ No newline at end of file diff --git a/queryserv/database.h b/queryserv/database.h index 13815c575..9aa6383a3 100644 --- a/queryserv/database.h +++ b/queryserv/database.h @@ -53,8 +53,6 @@ public: void LogMerchantTransaction(QSMerchantLogTransaction_Struct* QS, uint32 Items); void GeneralQueryReceive(ServerPacket *pack); - void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings); - protected: void HandleMysqlError(uint32 errnum); private: diff --git a/queryserv/queryserv.cpp b/queryserv/queryserv.cpp index 67a371a8e..005d54c6a 100644 --- a/queryserv/queryserv.cpp +++ b/queryserv/queryserv.cpp @@ -42,15 +42,15 @@ const queryservconfig *Config; WorldServer *worldserver = 0; EQEmuLogSys LogSys; -void CatchSignal(int sig_num) { - RunLoops = false; +void CatchSignal(int sig_num) { + RunLoops = false; } int main() { RegisterExecutablePlatform(ExePlatformQueryServ); LogSys.LoadLogSettingsDefaults(); - set_exception_handler(); - Timer LFGuildExpireTimer(60000); + set_exception_handler(); + Timer LFGuildExpireTimer(60000); LogInfo("Starting EQEmu QueryServ"); if (!queryservconfig::LoadConfig()) { @@ -58,11 +58,11 @@ int main() { return 1; } - Config = queryservconfig::get(); - WorldShortName = Config->ShortName; + Config = queryservconfig::get(); + WorldShortName = Config->ShortName; LogInfo("Connecting to MySQL"); - + /* MySQL Connection */ if (!database.Connect( Config->QSDatabaseHost.c_str(), @@ -74,9 +74,9 @@ int main() { return 1; } - /* Register Log System and Settings */ - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->StartFileLogs(); if (signal(SIGINT, CatchSignal) == SIG_ERR) { LogInfo("Could not set signal handler"); @@ -89,13 +89,13 @@ int main() { /* Initial Connection to Worldserver */ worldserver = new WorldServer; - worldserver->Connect(); + worldserver->Connect(); /* Load Looking For Guild Manager */ lfguildmanager.LoadDatabase(); - while(RunLoops) { - Timer::SetCurrentTime(); + while(RunLoops) { + Timer::SetCurrentTime(); if(LFGuildExpireTimer.Check()) lfguildmanager.ExpireEntries(); diff --git a/shared_memory/main.cpp b/shared_memory/main.cpp index 7cf54f946..57416aac5 100644 --- a/shared_memory/main.cpp +++ b/shared_memory/main.cpp @@ -120,9 +120,9 @@ int main(int argc, char **argv) content_db.SetMysql(database.getMySQL()); } - /* Register Log System and Settings */ - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->StartFileLogs(); std::string shared_mem_directory = Config->SharedMemDir; if (MakeDirectory(shared_mem_directory)) { diff --git a/ucs/database.cpp b/ucs/database.cpp index 108b17871..d3e01b54d 100644 --- a/ucs/database.cpp +++ b/ucs/database.cpp @@ -673,89 +673,3 @@ void Database::GetFriendsAndIgnore(int charID, std::vector &friends } } - -void Database::LoadLogSettings(EQEmuLogSys::LogSettings *log_settings) -{ - std::string query = - "SELECT " - "log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay " - "FROM " - "logsys_categories " - "ORDER BY log_category_id"; - - auto results = QueryDatabase(query); - int log_category_id = 0; - - int *categories_in_database = new int[1000]; - - for (auto row = results.begin(); row != results.end(); ++row) { - log_category_id = atoi(row[0]); - if (log_category_id <= Logs::None || log_category_id >= Logs::MaxCategoryID) { - continue; - } - - log_settings[log_category_id].log_to_console = static_cast(atoi(row[2])); - log_settings[log_category_id].log_to_file = static_cast(atoi(row[3])); - log_settings[log_category_id].log_to_gmsay = static_cast(atoi(row[4])); - - /** - * Determine if any output method is enabled for the category - * and set it to 1 so it can used to check if category is enabled - */ - const bool log_to_console = log_settings[log_category_id].log_to_console > 0; - const bool log_to_file = log_settings[log_category_id].log_to_file > 0; - const bool log_to_gmsay = log_settings[log_category_id].log_to_gmsay > 0; - const bool is_category_enabled = log_to_console || log_to_file || log_to_gmsay; - - if (is_category_enabled) { - log_settings[log_category_id].is_category_enabled = 1; - } - - /** - * This determines whether or not the process needs to actually file log anything. - * If we go through this whole loop and nothing is set to any debug level, there is no point to create a file or keep anything open - */ - if (log_settings[log_category_id].log_to_file > 0) { - LogSys.file_logs_enabled = true; - } - - categories_in_database[log_category_id] = 1; - } - - /** - * Auto inject categories that don't exist in the database... - */ - for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) { - if (categories_in_database[log_index] != 1) { - - LogInfo( - "New Log Category [{0}] doesn't exist... Automatically adding to [logsys_categories] table...", - Logs::LogCategoryName[log_index] - ); - - auto inject_query = fmt::format( - "INSERT INTO logsys_categories " - "(log_category_id, " - "log_category_description, " - "log_to_console, " - "log_to_file, " - "log_to_gmsay) " - "VALUES " - "({0}, '{1}', {2}, {3}, {4})", - log_index, - EscapeString(Logs::LogCategoryName[log_index]), - std::to_string(log_settings[log_index].log_to_console), - std::to_string(log_settings[log_index].log_to_file), - std::to_string(log_settings[log_index].log_to_gmsay) - ); - - QueryDatabase(inject_query); - } - } - - delete[] categories_in_database; -} diff --git a/ucs/database.h b/ucs/database.h index ade93ef42..fc9b96d19 100644 --- a/ucs/database.h +++ b/ucs/database.h @@ -57,8 +57,7 @@ public: void ExpireMail(); void AddFriendOrIgnore(int CharID, int Type, std::string Name); void RemoveFriendOrIgnore(int CharID, int Type, std::string Name); - void GetFriendsAndIgnore(int CharID, std::vector &Friends, std::vector &Ignorees); - void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings); + void GetFriendsAndIgnore(int CharID, std::vector &Friends, std::vector &Ignorees); protected: diff --git a/ucs/ucs.cpp b/ucs/ucs.cpp index 11f6ed103..5914b4fcc 100644 --- a/ucs/ucs.cpp +++ b/ucs/ucs.cpp @@ -97,9 +97,9 @@ int main() { return 1; } - /* Register Log System and Settings */ - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->StartFileLogs(); char tmp[64]; diff --git a/world/main.cpp b/world/main.cpp index f150db0e4..2aaafca16 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -297,11 +297,9 @@ int main(int argc, char** argv) { guild_mgr.SetDatabase(&database); - /** - * Logging - */ - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->StartFileLogs(); /** * Parse simple CLI passes diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index c350de44d..c53b474af 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -812,7 +812,7 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { } case ServerOP_ReloadLogs: { zoneserver_list.SendPacket(pack); - database.LoadLogSettings(LogSys.log_settings); + LogSys.LoadLogDatabaseSettings(); break; } case ServerOP_ReloadRules: { @@ -1289,11 +1289,11 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { case ServerOP_CZTaskDisablePlayer: case ServerOP_CZTaskDisableGroup: case ServerOP_CZTaskDisableRaid: - case ServerOP_CZTaskDisableGuild: + case ServerOP_CZTaskDisableGuild: case ServerOP_CZTaskEnablePlayer: case ServerOP_CZTaskEnableGroup: case ServerOP_CZTaskEnableRaid: - case ServerOP_CZTaskEnableGuild: + case ServerOP_CZTaskEnableGuild: case ServerOP_CZTaskFailPlayer: case ServerOP_CZTaskFailGroup: case ServerOP_CZTaskFailRaid: diff --git a/zone/main.cpp b/zone/main.cpp index b81a41f5b..a152e9945 100644 --- a/zone/main.cpp +++ b/zone/main.cpp @@ -254,9 +254,10 @@ int main(int argc, char** argv) { } /* Register Log System and Settings */ - LogSys.SetGMSayHandler(&Zone::GMSayHookCallBackProcess); - database.LoadLogSettings(LogSys.log_settings); - LogSys.StartFileLogs(); + LogSys.SetDatabase(&database) + ->LoadLogDatabaseSettings() + ->SetGMSayHandler(&Zone::GMSayHookCallBackProcess) + ->StartFileLogs(); /* Guilds */ guild_mgr.SetDatabase(&database); diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index beef1c8f8..5a5595f6f 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -1833,7 +1833,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) break; } case ServerOP_ReloadLogs: { - database.LoadLogSettings(LogSys.log_settings); + LogSys.LoadLogDatabaseSettings(); break; } case ServerOP_ReloadPerlExportSettings: {