refactor(Core/Logging): switch to fmt style for LOG_ (#10366)

* feat(Core/Common): add support fmt style for ASSERT and ABORT

* correct CheckCompactArrayMaskOverflow

* 1

* Update src/server/game/Spells/Spell.cpp

* rework logging

* add fmt replace logs

* logging

* FMT_LOG_

* settings

* fix startup

* 1

* 2

* 3

* 4

* 5

* fmt::print

* to fmt
This commit is contained in:
Kargatum
2022-01-27 22:44:41 +07:00
committed by GitHub
parent 5228d29379
commit 5969df4e30
211 changed files with 3689 additions and 3842 deletions

View File

@@ -35,18 +35,18 @@ void ACSoapThread(const std::string& host, uint16 port)
if (!soap_valid_socket(soap_bind(&soap, host.c_str(), port, 100)))
{
LOG_ERROR("network.soap", "ACSoap: couldn't bind to %s:%d", host.c_str(), port);
LOG_ERROR("network.soap", "ACSoap: couldn't bind to {}:{}", host, port);
exit(-1);
}
LOG_INFO("network.soap", "ACSoap: bound to http://%s:%d", host.c_str(), port);
LOG_INFO("network.soap", "ACSoap: bound to http://{}:{}", host, port);
while (!World::IsStopped())
{
if (!soap_valid_socket(soap_accept(&soap)))
continue; // ran into an accept timeout
LOG_DEBUG("network.soap", "ACSoap: accepted connection from IP=%d.%d.%d.%d", (int)(soap.ip >> 24) & 0xFF, (int)(soap.ip >> 16) & 0xFF, (int)(soap.ip >> 8) & 0xFF, (int)soap.ip & 0xFF);
LOG_DEBUG("network.soap", "ACSoap: accepted connection from IP={}.{}.{}.{}", (int)(soap.ip >> 24) & 0xFF, (int)(soap.ip >> 16) & 0xFF, (int)(soap.ip >> 8) & 0xFF, (int)soap.ip & 0xFF);
struct soap* thread_soap = soap_copy(&soap);// make a safe copy
process_message(thread_soap);
@@ -83,26 +83,26 @@ int ns1__executeCommand(soap* soap, char* command, char** result)
uint32 accountId = AccountMgr::GetId(soap->userid);
if (!accountId)
{
LOG_DEBUG("network", "ACSoap: Client used invalid username '%s'", soap->userid);
LOG_DEBUG("network", "ACSoap: Client used invalid username '{}'", soap->userid);
return 401;
}
if (!AccountMgr::CheckPassword(accountId, soap->passwd))
{
LOG_DEBUG("network.soap", "ACSoap: invalid password for account '%s'", soap->userid);
LOG_DEBUG("network.soap", "ACSoap: invalid password for account '{}'", soap->userid);
return 401;
}
if (AccountMgr::GetSecurity(accountId) < SEC_ADMINISTRATOR)
{
LOG_DEBUG("network.soap", "ACSoap: %s's gmlevel is too low", soap->userid);
LOG_DEBUG("network.soap", "ACSoap: {}'s gmlevel is too low", soap->userid);
return 403;
}
if (!command || !*command)
return soap_sender_fault(soap, "Command can not be empty", "The supplied command was an empty string");
LOG_DEBUG("network.soap", "ACSoap: got command '%s'", command);
LOG_DEBUG("network.soap", "ACSoap: got command '{}'", command);
SOAPCommand connection;
// commands are executed in the world thread. We have to wait for them to be completed

View File

@@ -24,6 +24,7 @@
#include "Errors.h"
#include "ObjectMgr.h"
#include "World.h"
#include <fmt/core.h>
#if AC_PLATFORM != AC_PLATFORM_WINDOWS
#include "Chat.h"
@@ -37,7 +38,7 @@ static constexpr char CLI_PREFIX[] = "AC> ";
static inline void PrintCliPrefix()
{
printf("%s", CLI_PREFIX);
fmt::print(CLI_PREFIX);
}
#if AC_PLATFORM != AC_PLATFORM_WINDOWS
@@ -74,14 +75,10 @@ namespace Acore::Impl::Readline
void utf8print(void* /*arg*/, std::string_view str)
{
#if AC_PLATFORM == AC_PLATFORM_WINDOWS
std::wstring wbuf;
if (!Utf8toWStr(str, wbuf))
return;
wprintf(L"%s", wbuf.c_str());
fmt::print(str);
#else
{
printf(STRING_VIEW_FMT, STRING_VIEW_FMT_ARG(str));
fmt::print(str);
fflush(stdout);
}
#endif

View File

@@ -204,13 +204,13 @@ int main(int argc, char** argv)
Acore::Banner::Show("worldserver-daemon",
[](std::string_view text)
{
FMT_LOG_INFO("server.worldserver", text);
LOG_INFO("server.worldserver", text);
},
[]()
{
FMT_LOG_INFO("server.worldserver", "> Using configuration file {}", sConfigMgr->GetFilename());
FMT_LOG_INFO("server.worldserver", "> Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
FMT_LOG_INFO("server.worldserver", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
LOG_INFO("server.worldserver", "> Using configuration file {}", sConfigMgr->GetFilename());
LOG_INFO("server.worldserver", "> Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
LOG_INFO("server.worldserver", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
});
OpenSSLCrypto::threadsSetup();
@@ -227,10 +227,10 @@ int main(int argc, char** argv)
if (!pidFile.empty())
{
if (uint32 pid = CreatePIDFile(pidFile))
LOG_ERROR("server", "Daemon PID: %u\n", pid); // outError for red color in console
LOG_ERROR("server", "Daemon PID: {}\n", pid); // outError for red color in console
else
{
LOG_ERROR("server", "Cannot create PID file %s (possible error: permission)\n", pidFile.c_str());
LOG_ERROR("server", "Cannot create PID file {} (possible error: permission)\n", pidFile);
return 1;
}
}
@@ -389,10 +389,10 @@ int main(int argc, char** argv)
{
freezeDetector = std::make_shared<FreezeDetector>(*ioContext, coreStuckTime * 1000);
FreezeDetector::Start(freezeDetector);
LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", coreStuckTime);
LOG_INFO("server.worldserver", "Starting up anti-freeze thread ({} seconds max stuck time)...", coreStuckTime);
}
LOG_INFO("server.worldserver", "%s (worldserver-daemon) ready...", GitRevision::GetFullVersion());
LOG_INFO("server.worldserver", "{} (worldserver-daemon) ready...", GitRevision::GetFullVersion());
sScriptMgr->OnStartup();
@@ -469,7 +469,7 @@ bool StartDB()
}
LOG_INFO("server.loading", "Loading world information...");
LOG_INFO("server.loading", "> RealmID: %u", realm.Id.Realm);
LOG_INFO("server.loading", "> RealmID: {}", realm.Id.Realm);
///- Clean the database before starting
ClearOnlineAccounts();
@@ -480,7 +480,7 @@ bool StartDB()
sWorld->LoadDBVersion();
sWorld->LoadDBRevision();
LOG_INFO("server.loading", "> Version DB world: %s", sWorld->GetDBVersion());
LOG_INFO("server.loading", "> Version DB world: {}", sWorld->GetDBVersion());
sScriptMgr->OnAfterDatabasesLoaded(loader.GetUpdateFlags());
@@ -524,7 +524,7 @@ void ShutdownCLIThread(std::thread* cliThread)
if (!formatReturnCode)
errorBuffer = "Unknown error";
LOG_DEBUG("server.worldserver", "Error cancelling I/O of CliThread, error code %u, detail: %s", uint32(errorCode), errorBuffer);
LOG_DEBUG("server.worldserver", "Error cancelling I/O of CliThread, error code {}, detail: {}", uint32(errorCode), errorBuffer);
if (!formatReturnCode)
LocalFree((LPSTR)errorBuffer);
@@ -674,7 +674,7 @@ bool LoadRealmInfo(Acore::Asio::IoContext& ioContext)
Optional<boost::asio::ip::tcp::endpoint> externalAddress = resolver.Resolve(boost::asio::ip::tcp::v4(), fields[2].GetString(), "");
if (!externalAddress)
{
LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[2].GetString().c_str());
LOG_ERROR("server.worldserver", "Could not resolve address {}", fields[2].GetString());
return false;
}
@@ -683,7 +683,7 @@ bool LoadRealmInfo(Acore::Asio::IoContext& ioContext)
Optional<boost::asio::ip::tcp::endpoint> localAddress = resolver.Resolve(boost::asio::ip::tcp::v4(), fields[3].GetString(), "");
if (!localAddress)
{
LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[3].GetString().c_str());
LOG_ERROR("server.worldserver", "Could not resolve address {}", fields[3].GetString());
return false;
}
@@ -692,7 +692,7 @@ bool LoadRealmInfo(Acore::Asio::IoContext& ioContext)
Optional<boost::asio::ip::tcp::endpoint> localSubmask = resolver.Resolve(boost::asio::ip::tcp::v4(), fields[4].GetString(), "");
if (!localSubmask)
{
LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[4].GetString().c_str());
LOG_ERROR("server.worldserver", "Could not resolve address {}", fields[4].GetString());
return false;
}

View File

@@ -57,7 +57,7 @@ void RASession::Start()
if (username.empty())
return;
LOG_INFO("commands.ra", "Accepting RA connection from user %s (IP: %s)", username.c_str(), GetRemoteIpAddress().c_str());
LOG_INFO("commands.ra", "Accepting RA connection from user {} (IP: {})", username, GetRemoteIpAddress());
Send("Password: ");
@@ -72,7 +72,7 @@ void RASession::Start()
return;
}
LOG_INFO("commands.ra", "User %s (IP: %s) authenticated correctly to RA", username.c_str(), GetRemoteIpAddress().c_str());
LOG_INFO("commands.ra", "User {} (IP: {}) authenticated correctly to RA", username, GetRemoteIpAddress());
// Authentication successful, send the motd
Send(std::string(std::string(Motd::GetMotd()) + "\r\n").c_str());
@@ -131,7 +131,7 @@ bool RASession::CheckAccessLevel(const std::string& user)
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
LOG_INFO("commands.ra", "User %s does not exist in database", user.c_str());
LOG_INFO("commands.ra", "User {} does not exist in database", user);
return false;
}
@@ -139,12 +139,12 @@ bool RASession::CheckAccessLevel(const std::string& user)
if (fields[1].GetUInt8() < sConfigMgr->GetOption<int32>("Ra.MinLevel", 3))
{
LOG_INFO("commands.ra", "User %s has no privilege to login", user.c_str());
LOG_INFO("commands.ra", "User {} has no privilege to login", user);
return false;
}
else if (fields[2].GetInt32() != -1)
{
LOG_INFO("commands.ra", "User %s has to be assigned on all realms (with RealmID = '-1')", user.c_str());
LOG_INFO("commands.ra", "User {} has to be assigned on all realms (with RealmID = '-1')", user);
return false;
}
@@ -174,7 +174,7 @@ bool RASession::CheckPassword(const std::string& user, const std::string& pass)
return true;
}
LOG_INFO("commands.ra", "Wrong password for user: %s", user.c_str());
LOG_INFO("commands.ra", "Wrong password for user: {}", user);
return false;
}
@@ -183,7 +183,7 @@ bool RASession::ProcessCommand(std::string& command)
if (command.length() == 0)
return true;
LOG_INFO("commands.ra", "Received command: %s", command.c_str());
LOG_INFO("commands.ra", "Received command: {}", command);
// handle quit, exit and logout commands to terminate connection
if (command == "quit" || command == "exit" || command == "logout")