mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
[Logging] Simplify Log Settings Initialization (#1394)
* Simplify logging loading * Fix log injections and reduce verbosity
This commit is contained in:
parent
0e4361955d
commit
bcb0e43d13
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<uint8>(atoi(row[2]));
|
||||
log_settings[log_category_id].log_to_file = static_cast<uint8>(atoi(row[3]));
|
||||
log_settings[log_category_id].log_to_gmsay = static_cast<uint8>(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);
|
||||
|
||||
@ -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:
|
||||
|
||||
|
||||
@ -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 <iostream>
|
||||
#include <fstream>
|
||||
@ -31,6 +31,7 @@
|
||||
#include <iomanip>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <algorithm>
|
||||
|
||||
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<int> 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<uint8>(c.log_to_console);
|
||||
log_settings[c.log_category_id].log_to_file = static_cast<uint8>(c.log_to_file);
|
||||
log_settings[c.log_category_id].log_to_gmsay = static_cast<uint8>(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;
|
||||
}
|
||||
|
||||
@ -23,8 +23,9 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
#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<void(uint16 log_type, const std::string&)> f) { on_log_gmsay_hook = f; }
|
||||
EQEmuLogSys * SetGMSayHandler(std::function<void(uint16 log_type, const std::string &)> f) {
|
||||
on_log_gmsay_hook = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param f
|
||||
*/
|
||||
void SetConsoleHandler(std::function<void(uint16 debug_level, uint16 log_type, const std::string&)> f) { on_log_console_hook = f; }
|
||||
|
||||
/**
|
||||
* Silence console logging
|
||||
*/
|
||||
// console
|
||||
void SetConsoleHandler(
|
||||
std::function<void(
|
||||
uint16 debug_level,
|
||||
uint16 log_type,
|
||||
const std::string &
|
||||
)> 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<void(uint16 log_category, const std::string&)> on_log_gmsay_hook;
|
||||
std::function<void(uint16 debug_level, uint16 log_category, const std::string&)> on_log_console_hook;
|
||||
// reference to database
|
||||
Database *m_database;
|
||||
|
||||
std::function<void(uint16 log_category, const std::string &)> on_log_gmsay_hook;
|
||||
std::function<void(uint16 debug_level, uint16 log_category, const std::string &)> 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);
|
||||
};
|
||||
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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<uint8>(atoi(row[2]));
|
||||
log_settings[log_category_id].log_to_file = static_cast<uint8>(atoi(row[3]));
|
||||
log_settings[log_category_id].log_to_gmsay = static_cast<uint8>(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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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<uint8>(atoi(row[2]));
|
||||
log_settings[log_category_id].log_to_file = static_cast<uint8>(atoi(row[3]));
|
||||
log_settings[log_category_id].log_to_gmsay = static_cast<uint8>(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;
|
||||
}
|
||||
@ -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:
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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)) {
|
||||
|
||||
@ -673,89 +673,3 @@ void Database::GetFriendsAndIgnore(int charID, std::vector<std::string> &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<uint8>(atoi(row[2]));
|
||||
log_settings[log_category_id].log_to_file = static_cast<uint8>(atoi(row[3]));
|
||||
log_settings[log_category_id].log_to_gmsay = static_cast<uint8>(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;
|
||||
}
|
||||
|
||||
@ -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<std::string> &Friends, std::vector<std::string> &Ignorees);
|
||||
void LoadLogSettings(EQEmuLogSys::LogSettings* log_settings);
|
||||
void GetFriendsAndIgnore(int CharID, std::vector<std::string> &Friends, std::vector<std::string> &Ignorees);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@ -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];
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user