From 5266d7b25cf463f889d92a3d070c93976e820a1d Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sun, 25 Jan 2015 04:24:05 -0600 Subject: [PATCH] Add extra checking at the root of Log.Out to check if the category is subscribed to any of the output methods before trying to parse message strings and then pass them to the sub output functions and THEN perform log_setting checks and debug_level checks. I performed a unit test of 1,000,000 log writes, there is hardly any difference. #::: Before Checks [01-25-2015 :: 03:15:35] [999999] Test #2... Took 17.940001 seconds #::: With Checks [01-25-2015 :: 04:10:55] [999999] Test #2... Took 18.018000 seconds --- common/eqemu_logsys.cpp | 13 ++++++++++--- zone/command.cpp | 11 +---------- zone/net.cpp | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/common/eqemu_logsys.cpp b/common/eqemu_logsys.cpp index 647628296..13302fbd2 100644 --- a/common/eqemu_logsys.cpp +++ b/common/eqemu_logsys.cpp @@ -269,6 +269,13 @@ void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::string message, ...) { + const bool log_to_console = log_settings[log_category].log_to_console > 0; + const bool log_to_file = log_settings[log_category].log_to_file > 0; + const bool log_to_gmsay = log_settings[log_category].log_to_gmsay > 0; + const bool nothing_to_log = !log_to_console && !log_to_file && !log_to_gmsay; + + if (nothing_to_log) return; + va_list args; va_start(args, message); std::string output_message = vStringFormat(message.c_str(), args); @@ -276,9 +283,9 @@ void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::st std::string output_debug_message = EQEmuLogSys::FormatOutMessageString(log_category, output_message); - EQEmuLogSys::ProcessConsoleMessage(debug_level, log_category, output_debug_message); - EQEmuLogSys::ProcessGMSay(debug_level, log_category, output_debug_message); - EQEmuLogSys::ProcessLogWrite(debug_level, log_category, output_message); + if (log_to_console) EQEmuLogSys::ProcessConsoleMessage(debug_level, log_category, output_debug_message); + if (log_to_gmsay) EQEmuLogSys::ProcessGMSay(debug_level, log_category, output_debug_message); + if (log_to_file) EQEmuLogSys::ProcessLogWrite(debug_level, log_category, output_message); } void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp) diff --git a/zone/command.cpp b/zone/command.cpp index 52389c342..ce6825a2e 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -10472,19 +10472,10 @@ void command_logtest(Client *c, const Seperator *sep){ clock_t t = std::clock(); /* Function timer start */ if (sep->IsNumber(1)){ uint32 i = 0; - std::ofstream log_test; - for (i = 0; i < atoi(sep->arg[1]); i++){ - log_test.open("logs/log_test.txt", std::ios_base::app | std::ios_base::out); - log_test << "this is a test\n"; - log_test.close(); - } - Log.Out(Logs::General, Logs::Zone_Server, "[%u] Test #1... Took %f seconds", i, ((float)(std::clock() - t)) / CLOCKS_PER_SEC); t = std::clock(); - log_test.open("logs/log_test.txt", std::ios_base::app | std::ios_base::out); for (i = 0; i < atoi(sep->arg[1]); i++){ - Log.Out(Logs::General, Logs::Zone_Server, "[%u] Test #2... Took %f seconds", i, ((float)(std::clock() - t)) / CLOCKS_PER_SEC); + Log.Out(Logs::General, Logs::Debug, "[%u] Test #2... Took %f seconds", i, ((float)(std::clock() - t)) / CLOCKS_PER_SEC); } - log_test.close(); } } diff --git a/zone/net.cpp b/zone/net.cpp index dd96f0e17..c35add8c3 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -151,7 +151,7 @@ int main(int argc, char** argv) { Log.Out(Logs::General, Logs::Error, "Loading server configuration failed."); return 1; } - const ZoneConfig *Config=ZoneConfig::get(); + const ZoneConfig *Config = ZoneConfig::get(); worldserver.SetPassword(Config->SharedKey.c_str());