From 108d3110b64fd921e868820c6ebb52c44f1b90ed Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sat, 10 Jan 2015 23:26:10 -0600 Subject: [PATCH] RULE_BOOL(Logging, EnableConsoleLogging, true) /* Turns on or off ALL logging to console */ RULE_BOOL(Logging, EnableFileLogging, true) /* Turns on or off ALL forms of file logging */ --- common/eqemu_logsys.cpp | 60 ++++++++++++++++++++++++++++++++++------- common/eqemu_logsys.h | 6 +++-- common/ruletypes.h | 5 ++++ 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/common/eqemu_logsys.cpp b/common/eqemu_logsys.cpp index fd380e1e2..eab7ee2d9 100644 --- a/common/eqemu_logsys.cpp +++ b/common/eqemu_logsys.cpp @@ -25,7 +25,7 @@ #include #include #include - +#include std::ofstream process_log; @@ -35,6 +35,8 @@ std::ofstream process_log; #include #include #include +#else +#include #endif namespace Console { @@ -65,7 +67,18 @@ static const char* TypeNames[EQEmuLogSys::MaxLogID] = { "Debug", "Quest", "Command", - "Crash" + "Crash", + "Save", + "UCS", + "Query Server", + "Socket Server", + "Spawns", + "AI", + "Pathing", + "Quests", + "Spells", + "Zone", + }; static Console::Color LogColors[EQEmuLogSys::MaxLogID] = { Console::Color::Yellow, // "Status", @@ -86,7 +99,7 @@ EQEmuLogSys::~EQEmuLogSys(){ void EQEmuLogSys::StartZoneLogs(const std::string log_name) { - _mkdir("logs/zone"); + EQEmuLogSys::MakeDirectory("logs/zone"); std::cout << "Starting Zone Logs..." << std::endl; process_log.open(StringFormat("logs/zone/%s.txt", log_name.c_str()), std::ios_base::app | std::ios_base::out); } @@ -115,6 +128,22 @@ void EQEmuLogSys::LogDebug(DebugLevel debug_level, std::string message, ...) EQEmuLogSys::Log(EQEmuLogSys::LogType::Debug, output_message); } +void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp){ + time_t raw_time; + struct tm * time_info; + time(&raw_time); + time_info = localtime(&raw_time); + strftime(time_stamp, 80, "[%d-%m-%Y :: %H:%M:%S]", time_info); +} + +void EQEmuLogSys::MakeDirectory(std::string directory_name){ +#ifdef _WINDOWS + _mkdir(directory_name.c_str()); +#else + mkdir(directory_name.c_str()); +#endif +} + void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...) { if (log_type > EQEmuLogSys::MaxLogID){ @@ -122,20 +151,25 @@ void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...) } if (!RuleB(Logging, LogFileCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; } + if (!RuleB(Logging, EnableFileLogging)){ + 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, output_message); + char time_stamp[80]; + EQEmuLogSys::SetCurrentTimeStamp(time_stamp); + if (process_log){ - process_log << std::put_time(&tm, "[%d-%m-%Y :: %H:%M:%S] ") << StringFormat("[%s] ", TypeNames[log_type]).c_str() << output_message << std::endl; + process_log << time_stamp << " " << 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 " << "\n"; } } @@ -144,6 +178,9 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message) if (log_type > EQEmuLogSys::MaxLogID){ return; } + if (!RuleB(Logging, EnableConsoleLogging)){ + return; + } if (!RuleB(Logging, ConsoleLogCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; } #ifdef _WINDOWS @@ -155,10 +192,15 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message) info.FontWeight = FW_NORMAL; wcscpy(info.FaceName, L"Lucida Console"); SetCurrentConsoleFontEx(console_handle, NULL, &info); - SetConsoleTextAttribute(console_handle, LogColors[log_type]); + if (LogColors[log_type]){ + SetConsoleTextAttribute(console_handle, LogColors[log_type]); + } + else{ + SetConsoleTextAttribute(console_handle, Console::Color::White); + } #endif - std::cout << "[N::" << TypeNames[log_type] << "] " << message << std::endl; + std::cout << "[N::" << TypeNames[log_type] << "] " << message << "\n"; #ifdef _WINDOWS /* Always set back to white*/ diff --git a/common/eqemu_logsys.h b/common/eqemu_logsys.h index f91a2338b..88fd1362f 100644 --- a/common/eqemu_logsys.h +++ b/common/eqemu_logsys.h @@ -45,12 +45,14 @@ public: 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 Log(uint16 log_type, const std::string message, ...); void LogDebug(DebugLevel debug_level, std::string message, ...); void LogDebugType(DebugLevel debug_level, uint16 log_type, std::string message, ...); - void Log(uint16 log_type, const std::string message, ...); + void MakeDirectory(std::string directory_name); + void SetCurrentTimeStamp(char* time_stamp); void StartZoneLogs(const std::string log_name); diff --git a/common/ruletypes.h b/common/ruletypes.h index 1d9286a69..c16590783 100644 --- a/common/ruletypes.h +++ b/common/ruletypes.h @@ -599,7 +599,12 @@ RULE_CATEGORY_END() RULE_CATEGORY(Logging) RULE_BOOL(Logging, ConsoleLogCommands, false) /* Turns on or off console logs */ RULE_BOOL(Logging, LogFileCommands, false) + RULE_INT(Logging, DebugLogLevel, 0) /* Sets Debug Level, -1 = OFF, 0 = Low Level, 1 = Info, 2 = Extreme */ + +RULE_BOOL(Logging, EnableConsoleLogging, true) /* Turns on or off ALL logging to console */ +RULE_BOOL(Logging, EnableFileLogging, true) /* Turns on or off ALL forms of file logging */ + RULE_CATEGORY_END()