diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp index 00f8398ee..c5a65dc87 100644 --- a/src/common/Configuration/Config.cpp +++ b/src/common/Configuration/Config.cpp @@ -6,6 +6,7 @@ #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) @@ -86,6 +87,15 @@ 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; } @@ -94,7 +104,10 @@ 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"); @@ -103,13 +116,27 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def) int ConfigMgr::GetIntDefault(const char* name, int def) { ACE_TString val; - return GetValueHelper(name, val) ? atoi(val.c_str()) : def; + + 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; + } } float ConfigMgr::GetFloatDefault(const char* name, float def) { ACE_TString val; - return GetValueHelper(name, val) ? (float)atof(val.c_str()) : def; + + 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; + } } std::list ConfigMgr::GetKeysByString(std::string const& name) diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp index 281628738..2c16a6a47 100644 --- a/src/common/Logging/Log.cpp +++ b/src/common/Logging/Log.cpp @@ -87,12 +87,6 @@ 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); @@ -108,45 +102,6 @@ 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); @@ -154,17 +109,6 @@ 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() @@ -502,6 +446,8 @@ 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); @@ -567,6 +513,8 @@ void Log::outErrorDb(const char * err, ...) fflush(logfile); } + dberLogfile = openLogFile("DBErrorLogFile", NULL, "a"); + if (dberLogfile) { outTimestamp(dberLogfile); @@ -682,6 +630,8 @@ void Log::outSQLDev(const char* str, ...) printf("\n"); + sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a"); + if (sqlDevLogFile) { va_list ap2; @@ -813,6 +763,8 @@ 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) { @@ -851,6 +803,37 @@ 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)) @@ -883,6 +866,8 @@ void Log::outChar(const char * str, ...) if (!str) return; + m_dbChar = sConfigMgr->GetBoolDefault("LogDB.Char", false); + if (m_enableLogDB && m_dbChar) { va_list ap2; @@ -893,6 +878,8 @@ void Log::outChar(const char * str, ...) va_end(ap2); } + charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a"); + if (charLogfile) { outTimestamp(charLogfile); @@ -908,6 +895,10 @@ 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 @@ -918,6 +909,7 @@ 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", @@ -933,6 +925,8 @@ void Log::outChat(const char * str, ...) if (!str) return; + m_dbChat = sConfigMgr->GetBoolDefault("LogDB.Chat", false); + if (m_enableLogDB && m_dbChat) { va_list ap2; @@ -943,6 +937,8 @@ void Log::outChat(const char * str, ...) va_end(ap2); } + chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a"); + if (chatLogfile) { outTimestamp(chatLogfile); @@ -960,6 +956,8 @@ void Log::outRemote(const char * str, ...) if (!str) return; + m_dbRA = sConfigMgr->GetBoolDefault("LogDB.RA", false); + if (m_enableLogDB && m_dbRA) { va_list ap2; @@ -970,6 +968,8 @@ void Log::outRemote(const char * str, ...) va_end(ap2); } + raLogfile = openLogFile("RaLogFile", NULL, "a"); + if (raLogfile) { outTimestamp(raLogfile); @@ -987,6 +987,8 @@ void Log::outMisc(const char * str, ...) if (!str) return; + miscLogFile = fopen((m_logsDir + "Misc.log").c_str(), "a"); + if (m_enableLogDB) { va_list ap2;