feat(Core/Logging): rework logging (#4692)

* feat(Core/Logging): rework logging

* correct level for sql.sql

* del unused config options

* Correct build

* correct after merge

* whitespace

20:29:37 1. 'Player.cpp'. Replace (1)
20:29:37 2. 'ObjectMgr.cpp'. Replace (3)

* 1

* correct logging

* correct affter merge

* 1

* 2

* LOG_LEVEL_WARN

* #include "AppenderDB.h"

* 3

* 4

* 5

* 1. 'WorldSocket.cpp'. Replace (1)

* 6

* 1
This commit is contained in:
Kargatum
2021-04-17 16:20:07 +07:00
committed by GitHub
parent b2861be1cd
commit 4af4cbd3d9
246 changed files with 7413 additions and 6807 deletions

View File

@@ -13,6 +13,7 @@
*/
#include "Common.h"
#include "AppenderDB.h"
#include "DatabaseEnv.h"
#include "Config.h"
#include "Log.h"
@@ -47,7 +48,7 @@ bool stopEvent = false; // Setting it to tru
/// Print out the usage string for this program on the console.
void usage(const char* prog)
{
sLog->outString("Usage: \n %s [<options>]\n"
LOG_INFO("server.authserver", "Usage: \n %s [<options>]\n"
" -c config_file use config_file as configuration file\n\r",
prog);
}
@@ -80,27 +81,29 @@ extern int main(int argc, char** argv)
if (!sConfigMgr->LoadAppConfigs())
return 1;
sLog->outString("%s (authserver)", GitRevision::GetFullVersion());
sLog->outString("<Ctrl-C> to stop.\n");
// Init logging
sLog->RegisterAppender<AppenderDB>();
sLog->Initialize();
sLog->outString(" █████╗ ███████╗███████╗██████╗ ██████╗ ████████╗██╗ ██╗");
sLog->outString(" ██╔══██╗╚══███╔╝██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝██║ ██║");
sLog->outString(" ███████║ ███╔╝ █████╗ ██████╔╝██║ ██║ ██║ ███████║");
sLog->outString(" ██╔══██║ ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ ██ ██╔══██");
sLog->outString(" ██║ ██║███████╗███████╗██║ ██║╚██████╔╝ ██║ ██║ ██║");
sLog->outString(" ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝");
sLog->outString(" ██████╗ ██████╗ ██████╗ ███████");
sLog->outString(" ██╔════╝██╔═══██╗██╔══██╗██╔═══╝");
sLog->outString(" ██║ ██║ ██║██████╔╝█████╗");
sLog->outString(" ██║ ██║ ████╔══██╗██╔══╝");
sLog->outString(" ██████╗██████╔╝██║ ██║███████╗");
sLog->outString(" ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝\n");
sLog->outString(" AzerothCore 3.3.5a - www.azerothcore.org\n");
sLog->outString("Using configuration file %s.", configFile.c_str());
sLog->outDetail("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
LOG_INFO("server.authserver", "%s (authserver)", GitRevision::GetFullVersion());
LOG_INFO("server.authserver", "<Ctrl-C> to stop.");
LOG_INFO("server.authserver", " ");
LOG_INFO("server.authserver", " █████╗ ███████╗███████╗██████ ██████╗ ████████╗██╗ ██");
LOG_INFO("server.authserver", " ██╔══██╗╚══███╔╝██╔════╝██╔══████╔═══██╗╚══██╔══╝██║ ██║");
LOG_INFO("server.authserver", " ███████║ ███╔╝ █████╗ ██████╔╝██║ ██║ ██║ ███████║");
LOG_INFO("server.authserver", " ██╔══██║ ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ ██║ ██╔══██");
LOG_INFO("server.authserver", " ██║ ██║███████╗███████╗██║ ██║╚██████╔╝ ██║ ██║ ██║");
LOG_INFO("server.authserver", " ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝");
LOG_INFO("server.authserver", " ██████╗ ██████╗ ██████╗ ███████╗");
LOG_INFO("server.authserver", " ██╔════╝██╔═══██╗██╔══████╔═══");
LOG_INFO("server.authserver", " ██║ ██║ ██║██████╔╝█████╗");
LOG_INFO("server.authserver", " ██║ ██║ ██║██╔══██╗██╔══╝");
LOG_INFO("server.authserver", " ╚██████╗╚██████╔╝██║ ██║███████╗");
LOG_INFO("server.authserver", " ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝\n");
LOG_INFO("server.authserver", " AzerothCore 3.3.5a - www.azerothcore.org");
LOG_INFO("server.authserver", " ");
LOG_INFO("server.authserver", "Using configuration file %s.", configFile.c_str());
LOG_INFO("server.authserver", "%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
@@ -108,17 +111,17 @@ extern int main(int argc, char** argv)
ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true);
#endif
sLog->outBasic("Max allowed open files is %d", ACE::max_handles());
LOG_INFO("server.authserver", "Max allowed open files is %d", ACE::max_handles());
// authserver PID file creation
std::string pidFile = sConfigMgr->GetOption<std::string>("PidFile", "");
if (!pidFile.empty())
{
if (uint32 pid = CreatePIDFile(pidFile))
sLog->outError("Daemon PID: %u\n", pid); // outError for red color in console
LOG_INFO("server.authserver", "Daemon PID: %u\n", pid); // outError for red color in console
else
{
sLog->outError("Cannot create PID file %s (possible error: permission)\n", pidFile.c_str());
LOG_ERROR("server.authserver", "Cannot create PID file %s (possible error: permission)\n", pidFile.c_str());
return 1;
}
}
@@ -127,15 +130,11 @@ extern int main(int argc, char** argv)
if (!StartDB())
return 1;
// Initialize the log database
sLog->SetLogDB(false);
sLog->SetRealmID(0); // ensure we've set realm to 0 (authserver realmid)
// Get the list of realms for the server
sRealmList->Initialize(sConfigMgr->GetOption<int32>("RealmsStateUpdateDelay", 20));
if (sRealmList->size() == 0)
{
sLog->outError("No valid realms specified.");
LOG_ERROR("server.authserver", "No valid realms specified.");
return 1;
}
@@ -145,7 +144,7 @@ extern int main(int argc, char** argv)
int32 rmport = sConfigMgr->GetOption<int32>("RealmServerPort", 3724);
if (rmport < 0 || rmport > 0xFFFF)
{
sLog->outError("The specified RealmServerPort (%d) is out of the allowed range (1-65535)", rmport);
LOG_ERROR("server.authserver", "The specified RealmServerPort (%d) is out of the allowed range (1-65535)", rmport);
return 1;
}
@@ -155,11 +154,11 @@ extern int main(int argc, char** argv)
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
sLog->outError("Auth server can not bind to %s:%d (possible error: port already in use)", bind_ip.c_str(), rmport);
LOG_ERROR("server.authserver", "Auth server can not bind to %s:%d (possible error: port already in use)", bind_ip.c_str(), rmport);
return 1;
}
sLog->outString("Authserver listening to %s:%d", bind_ip.c_str(), rmport);
LOG_INFO("server.authserver", "Authserver listening to %s:%d", bind_ip.c_str(), rmport);
// Initialize the signal handlers
acore::SignalHandler signalHandler;
@@ -192,20 +191,20 @@ extern int main(int argc, char** argv)
ULONG_PTR currentAffinity = affinity & appAff;
if (!currentAffinity)
sLog->outError("server.authserver", "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff);
LOG_ERROR("server.authserver", "server.authserver", "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff);
else if (SetProcessAffinityMask(hProcess, currentAffinity))
sLog->outString("server.authserver", "Using processors (bitmask, hex): %x", currentAffinity);
LOG_INFO("server.authserver", "server.authserver", "Using processors (bitmask, hex): %x", currentAffinity);
else
sLog->outError("server.authserver", "Can't set used processors (hex): %x", currentAffinity);
LOG_ERROR("server.authserver", "server.authserver", "Can't set used processors (hex): %x", currentAffinity);
}
}
if (highPriority)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
sLog->outString("server.authserver", "authserver process priority class set to HIGH");
LOG_INFO("server.authserver", "server.authserver", "authserver process priority class set to HIGH");
else
sLog->outError("server.authserver", "Can't set authserver process priority class.");
LOG_ERROR("server.authserver", "server.authserver", "Can't set authserver process priority class.");
}
#else // Linux
@@ -220,21 +219,21 @@ extern int main(int argc, char** argv)
CPU_SET(i, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
sLog->outError("Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
LOG_ERROR("server.authserver", "Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
else
{
CPU_ZERO(&mask);
sched_getaffinity(0, sizeof(mask), &mask);
sLog->outString("Using processors (bitmask, hex): %lx", *(__cpu_mask*)(&mask));
LOG_INFO("server.authserver", "Using processors (bitmask, hex): %lx", *(__cpu_mask*)(&mask));
}
}
if (highPriority)
{
if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
sLog->outError("Can't set authserver process priority class, error: %s", strerror(errno));
LOG_ERROR("server.authserver", "Can't set authserver process priority class, error: %s", strerror(errno));
else
sLog->outString("authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0));
LOG_INFO("server.authserver", "authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0));
}
#endif
@@ -244,13 +243,6 @@ extern int main(int argc, char** argv)
uint32 numLoops = (sConfigMgr->GetOption<int32>("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// possibly enable db logging; avoid massive startup spam by doing it here.
if (sConfigMgr->GetOption<bool>("EnableLogDB", false))
{
sLog->outString("Enabling database logging...");
sLog->SetLogDB(true);
}
// Wait for termination signal
while (!stopEvent)
{
@@ -263,7 +255,7 @@ extern int main(int argc, char** argv)
if ((++loopCounter) == numLoops)
{
loopCounter = 0;
sLog->outDetail("Ping MySQL to keep connection alive");
LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
LoginDatabase.KeepAlive();
}
}
@@ -271,7 +263,7 @@ extern int main(int argc, char** argv)
// Close the Database Pool and library
StopDB();
sLog->outString("Halting process...");
LOG_INFO("server.authserver", "Halting process...");
return 0;
}
@@ -290,7 +282,8 @@ bool StartDB()
if (!loader.Load())
return false;
sLog->outString("Started auth database connection pool.");
LOG_INFO("server.authserver", "Started auth database connection pool.");
sLog->SetRealmId(0); // Enables DB appenders when realm is set.
return true;
}