Show default options, missing in config files (#908)

This commit is contained in:
Kargatum
2018-06-05 18:14:57 +07:00
committed by José González
parent e222cbbc0a
commit f122ed57bf
2 changed files with 87 additions and 58 deletions

View File

@@ -6,6 +6,7 @@
#include "Config.h" #include "Config.h"
#include "Errors.h" #include "Errors.h"
#include "Log.h"
// Defined here as it must not be exposed to end-users. // Defined here as it must not be exposed to end-users.
bool ConfigMgr::GetValueHelper(const char* name, ACE_TString &result) 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) std::string ConfigMgr::GetStringDefault(const char* name, const std::string &def)
{ {
ACE_TString val; 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; return GetValueHelper(name, val) ? val.c_str() : def;
} }
@@ -94,7 +104,10 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def)
ACE_TString val; ACE_TString val;
if (!GetValueHelper(name, 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 def;
}
return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" || return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" ||
val == "1"); val == "1");
@@ -103,13 +116,27 @@ bool ConfigMgr::GetBoolDefault(const char* name, bool def)
int ConfigMgr::GetIntDefault(const char* name, int def) int ConfigMgr::GetIntDefault(const char* name, int def)
{ {
ACE_TString val; 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) float ConfigMgr::GetFloatDefault(const char* name, float def)
{ {
ACE_TString val; 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<std::string> ConfigMgr::GetKeysByString(std::string const& name) std::list<std::string> ConfigMgr::GetKeysByString(std::string const& name)

View File

@@ -87,12 +87,6 @@ void Log::SetLogFileLevel(char *Level)
void Log::Initialize() 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 /// Realm must be 0 by default
SetRealmID(0); SetRealmID(0);
@@ -108,45 +102,6 @@ void Log::Initialize()
logfile = openLogFile("LogFile", "LogTimestamp", "w"); logfile = openLogFile("LogFile", "LogTimestamp", "w");
InitColors(sConfigMgr->GetStringDefault("LogColors", "")); 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 // Main log file settings
m_logLevel = sConfigMgr->GetIntDefault("LogLevel", LOGL_NORMAL); m_logLevel = sConfigMgr->GetIntDefault("LogLevel", LOGL_NORMAL);
m_logFileLevel = sConfigMgr->GetIntDefault("LogFileLevel", LOGL_NORMAL); m_logFileLevel = sConfigMgr->GetIntDefault("LogFileLevel", LOGL_NORMAL);
@@ -154,17 +109,6 @@ void Log::Initialize()
m_sqlDriverQueryLogging = sConfigMgr->GetBoolDefault("SQLDriverQueryLogging", false); m_sqlDriverQueryLogging = sConfigMgr->GetBoolDefault("SQLDriverQueryLogging", false);
m_DebugLogMask = DebugLogFilters(sConfigMgr->GetIntDefault("DebugLogMask", LOG_FILTER_NONE)); 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() void Log::ReloadConfig()
@@ -502,6 +446,8 @@ void Log::outSQLDriver(const char* str, ...)
if (!str) if (!str)
return; return;
sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a");
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
vutf8printf(stdout, str, &ap); vutf8printf(stdout, str, &ap);
@@ -567,6 +513,8 @@ void Log::outErrorDb(const char * err, ...)
fflush(logfile); fflush(logfile);
} }
dberLogfile = openLogFile("DBErrorLogFile", NULL, "a");
if (dberLogfile) if (dberLogfile)
{ {
outTimestamp(dberLogfile); outTimestamp(dberLogfile);
@@ -682,6 +630,8 @@ void Log::outSQLDev(const char* str, ...)
printf("\n"); printf("\n");
sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a");
if (sqlDevLogFile) if (sqlDevLogFile)
{ {
va_list ap2; va_list ap2;
@@ -813,6 +763,8 @@ void Log::outCommand(uint32 account, const char * str, ...)
if (!str) if (!str)
return; return;
m_dbGM = sConfigMgr->GetBoolDefault("LogDB.GM", false);
// TODO: support accountid // TODO: support accountid
if (m_enableLogDB && m_dbGM) 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 (m_gmlog_per_account)
{ {
if (FILE* per_file = openGmlogPerAccount (account)) if (FILE* per_file = openGmlogPerAccount (account))
@@ -883,6 +866,8 @@ void Log::outChar(const char * str, ...)
if (!str) if (!str)
return; return;
m_dbChar = sConfigMgr->GetBoolDefault("LogDB.Char", false);
if (m_enableLogDB && m_dbChar) if (m_enableLogDB && m_dbChar)
{ {
va_list ap2; va_list ap2;
@@ -893,6 +878,8 @@ void Log::outChar(const char * str, ...)
va_end(ap2); va_end(ap2);
} }
charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a");
if (charLogfile) if (charLogfile)
{ {
outTimestamp(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) void Log::outCharDump(const char * str, uint32 account_id, uint32 guid, const char * name)
{ {
FILE* file = NULL; FILE* file = NULL;
charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a");
m_charLog_Dump_Separate = sConfigMgr->GetBoolDefault("CharLogDump.Separate", false);
if (m_charLog_Dump_Separate) if (m_charLog_Dump_Separate)
{ {
char fileName[29]; // Max length: name(12) + guid(11) + _.log (5) + \0 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 else
file = charLogfile; file = charLogfile;
if (file) if (file)
{ {
fprintf(file, "== START DUMP == (account: %u guid: %u name: %s )\n%s\n== END DUMP ==\n", 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) if (!str)
return; return;
m_dbChat = sConfigMgr->GetBoolDefault("LogDB.Chat", false);
if (m_enableLogDB && m_dbChat) if (m_enableLogDB && m_dbChat)
{ {
va_list ap2; va_list ap2;
@@ -943,6 +937,8 @@ void Log::outChat(const char * str, ...)
va_end(ap2); va_end(ap2);
} }
chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a");
if (chatLogfile) if (chatLogfile)
{ {
outTimestamp(chatLogfile); outTimestamp(chatLogfile);
@@ -960,6 +956,8 @@ void Log::outRemote(const char * str, ...)
if (!str) if (!str)
return; return;
m_dbRA = sConfigMgr->GetBoolDefault("LogDB.RA", false);
if (m_enableLogDB && m_dbRA) if (m_enableLogDB && m_dbRA)
{ {
va_list ap2; va_list ap2;
@@ -970,6 +968,8 @@ void Log::outRemote(const char * str, ...)
va_end(ap2); va_end(ap2);
} }
raLogfile = openLogFile("RaLogFile", NULL, "a");
if (raLogfile) if (raLogfile)
{ {
outTimestamp(raLogfile); outTimestamp(raLogfile);
@@ -987,6 +987,8 @@ void Log::outMisc(const char * str, ...)
if (!str) if (!str)
return; return;
miscLogFile = fopen((m_logsDir + "Misc.log").c_str(), "a");
if (m_enableLogDB) if (m_enableLogDB)
{ {
va_list ap2; va_list ap2;