diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp index c5a65dc87..00f8398ee 100644 --- a/src/common/Configuration/Config.cpp +++ b/src/common/Configuration/Config.cpp @@ -6,7 +6,6 @@ #include "Config.h" #include "Errors.h" -#include "Log.h" // Defined here as it must not be exposed to end-users. bool ConfigMgr::GetValueHelper(const char* name, ACE_TString &result) @@ -87,15 +86,6 @@ bool ConfigMgr::LoadData(char const* file) std::string ConfigMgr::GetStringDefault(const char* name, const std::string &def) { ACE_TString val; - - if (GetValueHelper(name, val)) - return val.c_str(); - else - { - sLog->outError("-> Not found option '%s'. The default value is used (%s)", name, def.c_str()); - return def; - } - return GetValueHelper(name, val) ? val.c_str() : def; } @@ -104,10 +94,7 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def) ACE_TString val; if (!GetValueHelper(name, val)) - { - def ? sLog->outError("-> Not found option '%s'. The default value is used (Yes)", name) : sLog->outError(">> Not found option '%s'. The default value is used (No)", name); return def; - } return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" || val == "1"); @@ -116,27 +103,13 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def) int ConfigMgr::GetIntDefault(const char* name, int def) { ACE_TString val; - - if (GetValueHelper(name, val)) - return atoi(val.c_str()); - else - { - sLog->outError("-> Not found option '%s'. The default value is used (%i)", name, def); - return def; - } + return GetValueHelper(name, val) ? atoi(val.c_str()) : def; } float ConfigMgr::GetFloatDefault(const char* name, float def) { ACE_TString val; - - if (GetValueHelper(name, val)) - return (float)atof(val.c_str()); - else - { - sLog->outError("-> Not found option '%s'. The default value is used (%f)", name, def); - return def; - } + return GetValueHelper(name, val) ? (float)atof(val.c_str()) : def; } std::list ConfigMgr::GetKeysByString(std::string const& name) diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp index 2c16a6a47..281628738 100644 --- a/src/common/Logging/Log.cpp +++ b/src/common/Logging/Log.cpp @@ -87,6 +87,12 @@ void Log::SetLogFileLevel(char *Level) void Log::Initialize() { + /// Check whether we'll log GM commands/RA events/character outputs/chat stuffs + m_dbChar = sConfigMgr->GetBoolDefault("LogDB.Char", false); + m_dbRA = sConfigMgr->GetBoolDefault("LogDB.RA", false); + m_dbGM = sConfigMgr->GetBoolDefault("LogDB.GM", false); + m_dbChat = sConfigMgr->GetBoolDefault("LogDB.Chat", false); + /// Realm must be 0 by default SetRealmID(0); @@ -102,6 +108,45 @@ void Log::Initialize() logfile = openLogFile("LogFile", "LogTimestamp", "w"); InitColors(sConfigMgr->GetStringDefault("LogColors", "")); + m_gmlog_per_account = sConfigMgr->GetBoolDefault("GmLogPerAccount", false); + if (!m_gmlog_per_account) + gmLogfile = openLogFile("GMLogFile", "GmLogTimestamp", "a"); + else + { + // GM log settings for per account case + m_gmlog_filename_format = sConfigMgr->GetStringDefault("GMLogFile", ""); + if (!m_gmlog_filename_format.empty()) + { + bool m_gmlog_timestamp = sConfigMgr->GetBoolDefault("GmLogTimestamp", false); + + size_t dot_pos = m_gmlog_filename_format.find_last_of('.'); + if (dot_pos!=m_gmlog_filename_format.npos) + { + if (m_gmlog_timestamp) + m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp); + + m_gmlog_filename_format.insert(dot_pos, "_#%u"); + } + else + { + m_gmlog_filename_format += "_#%u"; + + if (m_gmlog_timestamp) + m_gmlog_filename_format += m_logsTimestamp; + } + + m_gmlog_filename_format = m_logsDir + m_gmlog_filename_format; + } + } + + charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a"); + dberLogfile = openLogFile("DBErrorLogFile", NULL, "a"); + raLogfile = openLogFile("RaLogFile", NULL, "a"); + chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a"); + sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a"); + sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a"); + miscLogFile = fopen((m_logsDir+"Misc.log").c_str(), "a"); + // Main log file settings m_logLevel = sConfigMgr->GetIntDefault("LogLevel", LOGL_NORMAL); m_logFileLevel = sConfigMgr->GetIntDefault("LogFileLevel", LOGL_NORMAL); @@ -109,6 +154,17 @@ void Log::Initialize() m_sqlDriverQueryLogging = sConfigMgr->GetBoolDefault("SQLDriverQueryLogging", false); m_DebugLogMask = DebugLogFilters(sConfigMgr->GetIntDefault("DebugLogMask", LOG_FILTER_NONE)); + + // Char log settings + m_charLog_Dump = sConfigMgr->GetBoolDefault("CharLogDump", false); + m_charLog_Dump_Separate = sConfigMgr->GetBoolDefault("CharLogDump.Separate", false); + if (m_charLog_Dump_Separate) + { + m_dumpsDir = sConfigMgr->GetStringDefault("CharLogDump.SeparateDir", ""); + if (!m_dumpsDir.empty()) + if ((m_dumpsDir.at(m_dumpsDir.length() - 1) != '/') && (m_dumpsDir.at(m_dumpsDir.length() - 1) != '\\')) + m_dumpsDir.push_back('/'); + } } void Log::ReloadConfig() @@ -446,8 +502,6 @@ void Log::outSQLDriver(const char* str, ...) if (!str) return; - sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a"); - va_list ap; va_start(ap, str); vutf8printf(stdout, str, &ap); @@ -513,8 +567,6 @@ void Log::outErrorDb(const char * err, ...) fflush(logfile); } - dberLogfile = openLogFile("DBErrorLogFile", NULL, "a"); - if (dberLogfile) { outTimestamp(dberLogfile); @@ -630,8 +682,6 @@ void Log::outSQLDev(const char* str, ...) printf("\n"); - sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a"); - if (sqlDevLogFile) { va_list ap2; @@ -763,8 +813,6 @@ void Log::outCommand(uint32 account, const char * str, ...) if (!str) return; - m_dbGM = sConfigMgr->GetBoolDefault("LogDB.GM", false); - // TODO: support accountid if (m_enableLogDB && m_dbGM) { @@ -803,37 +851,6 @@ void Log::outCommand(uint32 account, const char * str, ...) } } - m_gmlog_per_account = sConfigMgr->GetBoolDefault("GmLogPerAccount", false); - if (!m_gmlog_per_account) - gmLogfile = openLogFile("GMLogFile", "GmLogTimestamp", "a"); - else - { - // GM log settings for per account case - m_gmlog_filename_format = sConfigMgr->GetStringDefault("GMLogFile", ""); - if (!m_gmlog_filename_format.empty()) - { - bool m_gmlog_timestamp = sConfigMgr->GetBoolDefault("GmLogTimestamp", false); - - size_t dot_pos = m_gmlog_filename_format.find_last_of('.'); - if (dot_pos != m_gmlog_filename_format.npos) - { - if (m_gmlog_timestamp) - m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp); - - m_gmlog_filename_format.insert(dot_pos, "_#%u"); - } - else - { - m_gmlog_filename_format += "_#%u"; - - if (m_gmlog_timestamp) - m_gmlog_filename_format += m_logsTimestamp; - } - - m_gmlog_filename_format = m_logsDir + m_gmlog_filename_format; - } - } - if (m_gmlog_per_account) { if (FILE* per_file = openGmlogPerAccount (account)) @@ -866,8 +883,6 @@ void Log::outChar(const char * str, ...) if (!str) return; - m_dbChar = sConfigMgr->GetBoolDefault("LogDB.Char", false); - if (m_enableLogDB && m_dbChar) { va_list ap2; @@ -878,8 +893,6 @@ void Log::outChar(const char * str, ...) va_end(ap2); } - charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a"); - if (charLogfile) { outTimestamp(charLogfile); @@ -895,10 +908,6 @@ void Log::outChar(const char * str, ...) void Log::outCharDump(const char * str, uint32 account_id, uint32 guid, const char * name) { FILE* file = NULL; - - charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a"); - - m_charLog_Dump_Separate = sConfigMgr->GetBoolDefault("CharLogDump.Separate", false); if (m_charLog_Dump_Separate) { char fileName[29]; // Max length: name(12) + guid(11) + _.log (5) + \0 @@ -909,7 +918,6 @@ void Log::outCharDump(const char * str, uint32 account_id, uint32 guid, const ch } else file = charLogfile; - if (file) { fprintf(file, "== START DUMP == (account: %u guid: %u name: %s )\n%s\n== END DUMP ==\n", @@ -925,8 +933,6 @@ void Log::outChat(const char * str, ...) if (!str) return; - m_dbChat = sConfigMgr->GetBoolDefault("LogDB.Chat", false); - if (m_enableLogDB && m_dbChat) { va_list ap2; @@ -937,8 +943,6 @@ void Log::outChat(const char * str, ...) va_end(ap2); } - chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a"); - if (chatLogfile) { outTimestamp(chatLogfile); @@ -956,8 +960,6 @@ void Log::outRemote(const char * str, ...) if (!str) return; - m_dbRA = sConfigMgr->GetBoolDefault("LogDB.RA", false); - if (m_enableLogDB && m_dbRA) { va_list ap2; @@ -968,8 +970,6 @@ void Log::outRemote(const char * str, ...) va_end(ap2); } - raLogfile = openLogFile("RaLogFile", NULL, "a"); - if (raLogfile) { outTimestamp(raLogfile); @@ -987,8 +987,6 @@ void Log::outMisc(const char * str, ...) if (!str) return; - miscLogFile = fopen((m_logsDir + "Misc.log").c_str(), "a"); - if (m_enableLogDB) { va_list ap2;