From 84741e4cb1edf42478ccd4357c1d14804032c2b9 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 10 Jan 2015 14:40:47 -0600 Subject: [PATCH] log_sys to logger enum DebugLevel { General = 0, /* 0 - Low-Level general debugging, useful info on single line */ Moderate, /* 1 - Informational based, used in functions, when particular things load */ Detail, /* 2 - Use this for extreme detail in logging, usually in extreme debugging in the stack or interprocess communication */ }; void EQEmuLogSys::LogDebug(DebugLevel debug_level, std::string message, ...) --- common/eqemu_logsys.cpp | 32 ++++++++++++++++++++++---------- common/eqemu_logsys.h | 14 +++++++++++--- zone/net.cpp | 6 +++++- zone/zone.cpp | 4 ++-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/common/eqemu_logsys.cpp b/common/eqemu_logsys.cpp index 081182386..498526d3b 100644 --- a/common/eqemu_logsys.cpp +++ b/common/eqemu_logsys.cpp @@ -90,21 +90,35 @@ void EQEmuLogSys::StartZoneLogs(const std::string log_name) process_log.open(StringFormat("logs/zone/%s.txt", log_name.c_str()), std::ios_base::app | std::ios_base::out); } -void EQEmuLogSys::Log(uint16 log_type, const std::string message) +void EQEmuLogSys::LogDebug(DebugLevel debug_level, std::string message, ...){ + va_list args; + va_start(args, message); + std::string output_message = vStringFormat(message.c_str(), args); + va_end(args); + EQEmuLogSys::Log(EQEmuLogSys::LogType::Debug, output_message); +} + +void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...) { if (log_type > EQEmuLogSys::MaxLogID){ return; } + if (!RuleB(Logging, LogFileCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; } + + va_list args; + va_start(args, message); + std::string output_message = vStringFormat(message.c_str(), args); + va_end(args); auto t = std::time(nullptr); auto tm = *std::localtime(&t); EQEmuLogSys::ConsoleMessage(log_type, message); if (process_log){ - process_log << std::put_time(&tm, "[%d-%m-%Y :: %H:%M:%S] ") << StringFormat("[%s] ", TypeNames[log_type]).c_str() << message << std::endl; + process_log << std::put_time(&tm, "[%d-%m-%Y :: %H:%M:%S] ") << StringFormat("[%s] ", TypeNames[log_type]).c_str() << output_message << std::endl; } else{ - std::cout << "[DEBUG] " << " :: There currently is no log file open for this process " << std::endl; + std::cout << "[DEBUG] " << ":: There currently is no log file open for this process " << std::endl; } } @@ -113,23 +127,21 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message) if (log_type > EQEmuLogSys::MaxLogID){ return; } + if (!RuleB(Logging, ConsoleLogCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; } #ifdef _WINDOWS HANDLE console_handle; - console_handle = GetStdHandle(STD_OUTPUT_HANDLE); - + console_handle = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_FONT_INFOEX info = { 0 }; info.cbSize = sizeof(info); info.dwFontSize.Y = 12; // leave X as zero info.FontWeight = FW_NORMAL; wcscpy(info.FaceName, L"Lucida Console"); - SetCurrentConsoleFontEx(console_handle, NULL, &info); - - SetConsoleTextAttribute(console_handle, LogColors[log_type]); - + SetCurrentConsoleFontEx(console_handle, NULL, &info); + SetConsoleTextAttribute(console_handle, LogColors[log_type]); #endif - std::cout << "[(N)" << TypeNames[log_type] << "] " << message << std::endl; + std::cout << "[N::" << TypeNames[log_type] << "] " << message << std::endl; #ifdef _WINDOWS /* Always set back to white*/ diff --git a/common/eqemu_logsys.h b/common/eqemu_logsys.h index d2a6c4622..cfeea78ce 100644 --- a/common/eqemu_logsys.h +++ b/common/eqemu_logsys.h @@ -40,17 +40,25 @@ public: MaxLogID /* Max, used in functions to get the max log ID */ }; - void StartZoneLogs(const std::string log_name); - void Log(uint16 log_type, const std::string message); + enum DebugLevel { + General = 0, /* 0 - Low-Level general debugging, useful info on single line */ + Moderate, /* 1 - Informational based, used in functions, when particular things load */ + Detail, /* 2 - Use this for extreme detail in logging, usually in extreme debugging in the stack or interprocess communication */ + }; + void CloseZoneLogs(); void ConsoleMessage(uint16 log_type, const std::string message); + void LogDebug(DebugLevel debug_level, std::string message, ...); + void Log(uint16 log_type, const std::string message, ...); + void StartZoneLogs(const std::string log_name); + private: bool zone_general_init = false; }; -extern EQEmuLogSys log_sys; +extern EQEmuLogSys logger; diff --git a/zone/net.cpp b/zone/net.cpp index b728de18f..cfd00628a 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -103,7 +103,7 @@ TitleManager title_manager; QueryServ *QServ = 0; TaskManager *taskmanager = 0; QuestParserCollection *parse = 0; -EQEmuLogSys log_sys; +EQEmuLogSys logger; const SPDat_Spell_Struct* spells; void LoadSpells(EQEmu::MemoryMappedFile **mmf); @@ -146,6 +146,8 @@ int main(int argc, char** argv) { worldserver.SetLauncherName("NONE"); } + + _log(ZONE__INIT, "Loading server configuration.."); if (!ZoneConfig::LoadConfig()) { _log(ZONE__INIT_ERR, "Loading server configuration failed."); @@ -174,6 +176,8 @@ int main(int argc, char** argv) { GuildBanks = nullptr; + logger.LogDebug(EQEmuLogSys::DebugLevel::General, "This is a crazy test message, database is %s and username is %s", Config->DatabaseDB.c_str(), Config->DatabaseUsername.c_str()); + #ifdef _EQDEBUG _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif diff --git a/zone/zone.cpp b/zone/zone.cpp index 63b673cd1..b56509ee8 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -152,7 +152,7 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) { /* Set Logging */ - log_sys.StartZoneLogs(StringFormat("%s_ver-%u_instid-%u_port-%u", zone->GetShortName(), zone->GetInstanceVersion(), zone->GetInstanceID(), ZoneConfig::get()->ZonePort)); + logger.StartZoneLogs(StringFormat("%s_ver-%u_instid-%u_port-%u", zone->GetShortName(), zone->GetInstanceVersion(), zone->GetInstanceID(), ZoneConfig::get()->ZonePort)); return true; } @@ -720,7 +720,7 @@ void Zone::Shutdown(bool quite) parse->ReloadQuests(true); UpdateWindowTitle(); - log_sys.CloseZoneLogs(); + logger.CloseZoneLogs(); } void Zone::LoadZoneDoors(const char* zone, int16 version)