diff --git a/dAuthServer/AuthServer.cpp b/dAuthServer/AuthServer.cpp index 22f1dfa0..f7ab7bbe 100644 --- a/dAuthServer/AuthServer.cpp +++ b/dAuthServer/AuthServer.cpp @@ -45,6 +45,7 @@ int main(int argc, char** argv) { dConfig config("authconfig.ini"); Game::config = &config; Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); + Game::logger->SetLogDebugStatements(bool(std::stoi(config.GetValue("log_debug_statements")))); //Connect to the MySQL Database std::string mysql_host = config.GetValue("mysql_host"); @@ -152,11 +153,13 @@ int main(int argc, char** argv) { dLogger * SetupLogger() { std::string logPath = "./logs/AuthServer_" + std::to_string(time(nullptr)) + ".log"; bool logToConsole = false; + bool logDebugStatements = false; #ifdef _DEBUG logToConsole = true; + logDebugStatements = true; #endif - return new dLogger(logPath, logToConsole); + return new dLogger(logPath, logToConsole, logDebugStatements); } void HandlePacket(Packet* packet) { diff --git a/dChatServer/ChatServer.cpp b/dChatServer/ChatServer.cpp index be5ec904..57b82721 100644 --- a/dChatServer/ChatServer.cpp +++ b/dChatServer/ChatServer.cpp @@ -48,6 +48,7 @@ int main(int argc, char** argv) { dConfig config("chatconfig.ini"); Game::config = &config; Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); + Game::logger->SetLogDebugStatements(bool(std::stoi(config.GetValue("log_debug_statements")))); //Connect to the MySQL Database std::string mysql_host = config.GetValue("mysql_host"); @@ -156,14 +157,16 @@ int main(int argc, char** argv) { return 0; } -dLogger* SetupLogger() { +dLogger * SetupLogger() { std::string logPath = "./logs/ChatServer_" + std::to_string(time(nullptr)) + ".log"; bool logToConsole = false; + bool logDebugStatements = false; #ifdef _DEBUG logToConsole = true; + logDebugStatements = true; #endif - return new dLogger(logPath, logToConsole); + return new dLogger(logPath, logToConsole, logDebugStatements); } void HandlePacket(Packet* packet) { diff --git a/dCommon/dLogger.cpp b/dCommon/dLogger.cpp index 6ee0e7d2..572fc1e3 100644 --- a/dCommon/dLogger.cpp +++ b/dCommon/dLogger.cpp @@ -1,7 +1,8 @@ #include "dLogger.h" -dLogger::dLogger(const std::string& outpath, bool logToConsole) { +dLogger::dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements) { m_logToConsole = logToConsole; + m_logDebugStatements = logDebugStatements; m_outpath = outpath; #ifdef _WIN32 @@ -24,39 +25,26 @@ dLogger::~dLogger() { #endif } -void dLogger::LogBasic(const std::string & message) { - LogBasic(message.c_str()); -} - -void dLogger::LogBasic(const char * format, ...) { +void dLogger::vLog(const char* format, va_list args) { #ifdef _WIN32 time_t t = time(NULL); struct tm time; localtime_s(&time, &t); - char timeStr[70]; - strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time); - char message[2048]; - va_list args; - va_start(args, format); vsprintf_s(message, format, args); - va_end(args); - if (m_logToConsole) std::cout << "[" << "time machine broke" << "] " << message; - mFile << "[" << "time" << "] " << message; + if (m_logToConsole) std::cout << "[" << timeStr << "] " << message; + mFile << "[" << timeStr << "] " << message; #else time_t t = time(NULL); - struct tm * time = localtime(&t); - char timeStr[70]; - strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time); - + struct tm time; + localtime_s(&time, &t); + char timeStr[70]; + strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time); char message[2048]; - va_list args; - va_start(args, format); vsprintf(message, format, args); - va_end(args); if (m_logToConsole) { fputs("[", stdout); @@ -76,62 +64,42 @@ void dLogger::LogBasic(const char * format, ...) { #endif } -void dLogger::Log(const char * className, const char * format, ...) { -#ifdef _WIN32 - time_t t = time(NULL); - struct tm time; - localtime_s(&time, &t); - - char timeStr[70]; - strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time); - - char message[2048]; +void dLogger::LogBasic(const char * format, ...) { va_list args; va_start(args, format); - vsprintf_s(message, format, args); - + vLog(format, args); va_end(args); +} - if (m_logToConsole) std::cout << "[" << timeStr << "] [" << className << "]: " << message; - mFile << "[" << timeStr << "] [" << className << "]: " << message; -#else - time_t t = time(NULL); - struct tm * time = localtime(&t); - char timeStr[70]; - strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time); - - char message[2048]; - va_list args; - va_start(args, format); - vsprintf(message, format, args); - va_end(args); - - if (m_logToConsole) { - fputs("[", stdout); - fputs(timeStr, stdout); - fputs("] ", stdout); - fputs("[", stdout); - fputs(className, stdout); - fputs("]: ", stdout); - fputs(message, stdout); - } - - if (fp != NULL) { - fputs("[", fp); - fputs(timeStr, fp); - fputs("] ", fp); - fputs("[", fp); - fputs(className, fp); - fputs("]: ", fp); - fputs(message, fp); - } -#endif +void dLogger::LogBasic(const std::string & message) { + LogBasic(message.c_str()); +} + +void dLogger::Log(const char * className, const char * format, ...) { + va_list args; + std::string log = "[" + std::string(className) + "] " + std::string(format); + va_start(args, format); + vLog(log.c_str(), args); + va_end(args); } void dLogger::Log(const std::string & className, const std::string & message) { Log(className.c_str(), message.c_str()); } +void dLogger::LogDebug(const char * className, const char * format, ...) { + if (!m_logDebugStatements) return; + va_list args; + std::string log = "[" + std::string(className) + "] " + std::string(format); + va_start(args, format); + vLog(log.c_str(), args); + va_end(args); +} + +void dLogger::LogDebug(const std::string & className, const std::string & message) { + LogDebug(className.c_str(), message.c_str()); +} + void dLogger::Flush() { #ifdef _WIN32 mFile.flush(); diff --git a/dCommon/dLogger.h b/dCommon/dLogger.h index 622a90d3..7448237e 100644 --- a/dCommon/dLogger.h +++ b/dCommon/dLogger.h @@ -7,21 +7,26 @@ class dLogger { public: - dLogger(const std::string& outpath, bool logToConsole); + dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements); ~dLogger(); void SetLogToConsole(bool logToConsole) { m_logToConsole = logToConsole; } + void SetLogDebugStatements(bool logDebugStatements) { m_logDebugStatements = logDebugStatements; } + void vLog(const char* format, va_list args); void LogBasic(const std::string& message); void LogBasic(const char* format, ...); void Log(const char* className, const char* format, ...); void Log(const std::string& className, const std::string& message); + void LogDebug(const std::string& className, const std::string& message); + void LogDebug(const char* className, const char* format, ...); void Flush(); const bool GetIsLoggingToConsole() const { return m_logToConsole; } private: + bool m_logDebugStatements; bool m_logToConsole; std::string m_outpath; std::ofstream mFile; diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 926168a3..88a95a6d 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -72,6 +72,7 @@ int main(int argc, char** argv) { dConfig config("masterconfig.ini"); Game::config = &config; Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); + Game::logger->SetLogDebugStatements(bool(std::stoi(config.GetValue("log_debug_statements")))); //Connect to CDClient try { @@ -320,11 +321,13 @@ dLogger* SetupLogger() { std::string logPath = "./logs/MasterServer_" + std::to_string(time(nullptr)) + ".log"; bool logToConsole = false; + bool logDebugStatements = false; #ifdef _DEBUG logToConsole = true; + logDebugStatements = true; #endif - return new dLogger(logPath, logToConsole); + return new dLogger(logPath, logToConsole, logDebugStatements); } void HandlePacket(Packet* packet) { diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index cca8a728..1cd1c24f 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -781,11 +781,10 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr script = invalidToReturn; else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua") script = invalidToReturn; - else if (scriptName == "scripts\\ai\\AG\\L_AG_SHIP_SHAKE.lua") - script = invalidToReturn; //Set ship shake to not log it is missing, it is implemented in AgSpaceStuff else if (script == invalidToReturn) { if (scriptName.length() > 0) - Game::logger->Log("CppScripts", "Attempted to load CppScript for '" + scriptName + "', but returned InvalidScript.\n"); + Game::logger->LogDebug("CppScripts", "Attempted to load CppScript for '" + scriptName + "', but returned InvalidScript.\n"); + // information not really needed for sys admins but is for developers script = invalidToReturn; } diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 5d155f29..6c81e93a 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -136,6 +136,7 @@ int main(int argc, char** argv) { dConfig config("worldconfig.ini"); Game::config = &config; Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); + Game::logger->SetLogDebugStatements(bool(std::stoi(config.GetValue("log_debug_statements")))); if (config.GetValue("disable_chat") == "1") chatDisabled = true; // Connect to CDClient @@ -503,11 +504,13 @@ int main(int argc, char** argv) { dLogger * SetupLogger(int zoneID, int instanceID) { std::string logPath = "./logs/WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID) + "_" + std::to_string(time(nullptr)) + ".log"; bool logToConsole = false; + bool logDebugStatements = false; #ifdef _DEBUG logToConsole = true; + logDebugStatements = true; #endif - return new dLogger(logPath, logToConsole); + return new dLogger(logPath, logToConsole, logDebugStatements); } void HandlePacketChat(Packet* packet) { diff --git a/resources/authconfig.ini b/resources/authconfig.ini index fd1fc5c4..40ca146e 100644 --- a/resources/authconfig.ini +++ b/resources/authconfig.ini @@ -19,6 +19,9 @@ max_clients=999 # 0 or 1, should log to console log_to_console=1 +# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation +log_debug_statements=0 + # 0 or 1, should ignore playkeys # If 1 everyone with an account will be able to login, regardless of if they have a key or not dont_use_keys=0 diff --git a/resources/chatconfig.ini b/resources/chatconfig.ini index 28db5988..f30fb8f9 100644 --- a/resources/chatconfig.ini +++ b/resources/chatconfig.ini @@ -19,5 +19,8 @@ max_clients=999 # 0 or 1, should log to console log_to_console=1 +# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation +log_debug_statements=0 + # 0 or 1, should not compile chat hash map to file dont_generate_dcf=0 diff --git a/resources/masterconfig.ini b/resources/masterconfig.ini index 120a3743..cedb7c3a 100644 --- a/resources/masterconfig.ini +++ b/resources/masterconfig.ini @@ -32,5 +32,8 @@ max_clients=999 # 0 or 1, should log to console log_to_console=1 +# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation +log_debug_statements=0 + # 0 or 1, should autostart auth, chat, and char servers prestart_servers=1 diff --git a/resources/worldconfig.ini b/resources/worldconfig.ini index e5932ec7..e30aa865 100644 --- a/resources/worldconfig.ini +++ b/resources/worldconfig.ini @@ -20,6 +20,9 @@ max_clients=999 # 0 or 1, should log to console log_to_console=1 +# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation +log_debug_statements=0 + # 0 or 1, should not compile chat hash map to file dont_generate_dcf=0