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

@@ -53,7 +53,7 @@ struct ServerPktHeader
uint8 headerIndex = 0;
if (isLargePacket())
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "initializing large server to client packet. Size: %u, cmd: %u", size, cmd);
LOG_DEBUG("network", "initializing large server to client packet. Size: %u, cmd: %u", size, cmd);
header[headerIndex++] = 0x80 | (0xFF & (size >> 16));
}
header[headerIndex++] = 0xFF & (size >> 8);
@@ -123,7 +123,7 @@ bool WorldSocket::IsClosed(void) const
void WorldSocket::CloseSocket(std::string const& reason)
{
if (!reason.empty())
sLog->outDebug(LOG_FILTER_CLOSE_SOCKET, "Socket closed because of: %s", reason.c_str());
LOG_DEBUG("network", "Socket closed because of: %s", reason.c_str());
{
std::lock_guard<std::mutex> guard(m_OutBufferLock);
@@ -187,7 +187,7 @@ int WorldSocket::SendPacket(WorldPacket const& pct)
if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
{
sLog->outError("WorldSocket::SendPacket enqueue_tail failed");
LOG_ERROR("server", "WorldSocket::SendPacket enqueue_tail failed");
mb->release();
return -1;
}
@@ -230,7 +230,7 @@ int WorldSocket::open(void* a)
if (peer().get_remote_addr(remote_addr) == -1)
{
sLog->outError("WorldSocket::open: peer().get_remote_addr errno = %s", ACE_OS::strerror (errno));
LOG_ERROR("server", "WorldSocket::open: peer().get_remote_addr errno = %s", ACE_OS::strerror (errno));
return -1;
}
@@ -248,7 +248,7 @@ int WorldSocket::open(void* a)
// Register with ACE Reactor
if (reactor()->register_handler(this, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK) == -1)
{
sLog->outError("WorldSocket::open: unable to register client handler errno = %s", ACE_OS::strerror (errno));
LOG_ERROR("server", "WorldSocket::open: unable to register client handler errno = %s", ACE_OS::strerror (errno));
return -1;
}
@@ -285,7 +285,7 @@ int WorldSocket::handle_input(ACE_HANDLE)
}
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
LOG_DEBUG("server", "WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
#endif
errno = ECONNRESET;
@@ -294,7 +294,7 @@ int WorldSocket::handle_input(ACE_HANDLE)
case 0:
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::handle_input: Peer has closed connection");
LOG_DEBUG("server", "WorldSocket::handle_input: Peer has closed connection");
#endif
errno = ECONNRESET;
@@ -364,7 +364,7 @@ int WorldSocket::handle_output_queue()
if (msg_queue()->dequeue_head(mblk, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
{
sLog->outError("WorldSocket::handle_output_queue dequeue_head");
LOG_ERROR("server", "WorldSocket::handle_output_queue dequeue_head");
return -1;
}
@@ -399,7 +399,7 @@ int WorldSocket::handle_output_queue()
if (msg_queue()->enqueue_head(mblk, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
sLog->outError("WorldSocket::handle_output_queue enqueue_head");
LOG_ERROR("server", "WorldSocket::handle_output_queue enqueue_head");
mblk->release();
return -1;
}
@@ -478,7 +478,7 @@ int WorldSocket::handle_input_header(void)
if ((header.size < 4) || (header.size > 10240) || (header.cmd > 10240))
{
Player* _player = m_Session ? m_Session->GetPlayer() : nullptr;
sLog->outError("WorldSocket::handle_input_header(): client (account: %u, char [GUID: %u, name: %s]) sent malformed packet (size: %d, cmd: %d)", m_Session ? m_Session->GetAccountId() : 0, _player ? _player->GetGUIDLow() : 0, _player ? _player->GetName().c_str() : "<none>", header.size, header.cmd);
LOG_ERROR("server", "WorldSocket::handle_input_header(): client (account: %u, char [GUID: %u, name: %s]) sent malformed packet (size: %d, cmd: %d)", m_Session ? m_Session->GetAccountId() : 0, _player ? _player->GetGUIDLow() : 0, _player ? _player->GetName().c_str() : "<none>", header.size, header.cmd);
errno = EINVAL;
return -1;
@@ -580,7 +580,7 @@ int WorldSocket::handle_input_missing_data(void)
// hope this is not hack, as proper m_RecvWPct is asserted around
if (!m_RecvWPct)
{
sLog->outError("Forcing close on input m_RecvWPct = nullptr");
LOG_ERROR("server", "Forcing close on input m_RecvWPct = nullptr");
errno = EINVAL;
return -1;
}
@@ -624,7 +624,7 @@ int WorldSocket::cancel_wakeup_output()
(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
// would be good to store errno from reactor with errno guard
sLog->outError("WorldSocket::cancel_wakeup_output");
LOG_ERROR("server", "WorldSocket::cancel_wakeup_output");
return -1;
}
@@ -641,7 +641,7 @@ int WorldSocket::schedule_wakeup_output()
if (reactor()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
sLog->outError("WorldSocket::schedule_wakeup_output");
LOG_ERROR("server", "WorldSocket::schedule_wakeup_output");
return -1;
}
@@ -675,13 +675,13 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
return HandlePing(*new_pct);
}
catch (ByteBufferPositionException const&) {}
sLog->outError("WorldSocket::ReadDataHandler(): client sent malformed CMSG_PING");
LOG_ERROR("server", "WorldSocket::ReadDataHandler(): client sent malformed CMSG_PING");
return -1;
}
case CMSG_AUTH_SESSION:
if (m_Session)
{
sLog->outError("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
LOG_ERROR("server", "WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
return -1;
}
return HandleAuthSession (*new_pct);
@@ -706,7 +706,7 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
}
else
{
sLog->outError("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
LOG_ERROR("server", "WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
return -1;
}
}
@@ -714,10 +714,10 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
}
catch (ByteBufferException const&)
{
sLog->outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.", opcode, GetRemoteAddress().c_str(), m_Session ? m_Session->GetAccountId() : -1);
if (sLog->IsOutDebug())
LOG_ERROR("server", "WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.", opcode, GetRemoteAddress().c_str(), m_Session ? m_Session->GetAccountId() : -1);
if (sLog->ShouldLog("network", LogLevel::LOG_LEVEL_DEBUG))
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "Dumping error causing packet:");
LOG_DEBUG("network", "Dumping error causing packet:");
new_pct->hexlike();
}
@@ -751,7 +751,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
packet << uint8(AUTH_REJECT);
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: World closed, denying client (%s).", GetRemoteAddress().c_str());
LOG_ERROR("server", "WorldSocket::HandleAuthSession: World closed, denying client (%s).", GetRemoteAddress().c_str());
return -1;
}
@@ -768,7 +768,8 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
recvPacket.read(digest);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug ("WorldSocket::HandleAuthSession: client %u, loginServerID %u, account %s, loginServerType %u, clientseed %u", BuiltNumberClient, loginServerID, account.c_str(), loginServerType, clientSeed);
LOG_DEBUG("server", "WorldSocket::HandleAuthSession: client %u, loginServerID %u, account %s, loginServerType %u",
BuiltNumberClient, loginServerID, account.c_str(), loginServerType);
#endif
// Get the account information from the realmd database
// 0 1 2 3 4 5 6 7 8 9 10
@@ -788,7 +789,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
LOG_ERROR("server", "WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
return -1;
}
@@ -823,7 +824,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
packet << uint8 (AUTH_FAILED);
SendPacket(packet);
sLog->outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs. Original IP: %s, new IP: %s).", fields[2].GetCString(), address.c_str());
LOG_INFO("server", "WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs. Original IP: %s, new IP: %s).", fields[2].GetCString(), address.c_str());
// We could log on hook only instead of an additional db log, however action logger is config based. Better keep DB logging as well
sScriptMgr->OnFailedAccountLogin(id);
return -1;
@@ -866,7 +867,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
packet << uint8(AUTH_REJECT);
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Client %s attempted to log in using invalid client OS (%s).", address.c_str(), os.c_str());
LOG_ERROR("server", "WorldSocket::HandleAuthSession: Client %s attempted to log in using invalid client OS (%s).", address.c_str(), os.c_str());
return -1;
}
@@ -901,7 +902,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
packet << uint8 (AUTH_BANNED);
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
LOG_ERROR("server", "WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -909,7 +910,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
// Check locked state for server
AccountTypes allowedAccountType = sWorld->GetPlayerSecurityLimit();
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "Allowed Level: %u Player Level %u", allowedAccountType, AccountTypes(security));
LOG_DEBUG("network", "Allowed Level: %u Player Level %u", allowedAccountType, AccountTypes(security));
#endif
if (AccountTypes(security) < allowedAccountType)
{
@@ -919,7 +920,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendPacket(packet);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDetail("WorldSocket::HandleAuthSession: User tries to login but his security level is not enough");
LOG_DEBUG("server", "WorldSocket::HandleAuthSession: User tries to login but his security level is not enough");
#endif
sScriptMgr->OnFailedAccountLogin(id);
return -1;
@@ -943,12 +944,12 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Authentication failed for account: %u ('%s') address: %s", id, account.c_str(), address.c_str());
LOG_ERROR("server", "WorldSocket::HandleAuthSession: Authentication failed for account: %u ('%s') address: %s", id, account.c_str(), address.c_str());
return -1;
}
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outStaticDebug("WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
LOG_DEBUG("server", "WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
account.c_str(),
address.c_str());
#endif
@@ -985,7 +986,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
packet << uint8 (AUTH_REJECT);
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: World closed, denying client (%s).", address.c_str());
LOG_ERROR("server", "WorldSocket::HandleAuthSession: World closed, denying client (%s).", address.c_str());
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -996,7 +997,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
packet << uint8 (REALM_LIST_REALM_NOT_FOUND);
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Client %s requested connecting with realm id %u but this realm has id %u set in config.",
LOG_ERROR("server", "WorldSocket::HandleAuthSession: Client %s requested connecting with realm id %u but this realm has id %u set in config.",
address.c_str(), realm, realmID);
sScriptMgr->OnFailedAccountLogin(id);
return -1;
@@ -1052,7 +1053,7 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
if (m_Session && AccountMgr::IsPlayerAccount(m_Session->GetSecurity()))
{
Player* _player = m_Session->GetPlayer();
sLog->outError("WorldSocket::HandlePing: Player (account: %u, GUID: %u, name: %s) kicked for over-speed pings (address: %s)",
LOG_ERROR("server", "WorldSocket::HandlePing: Player (account: %u, GUID: %u, name: %s) kicked for over-speed pings (address: %s)",
m_Session->GetAccountId(),
_player ? _player->GetGUIDLow() : 0,
_player ? _player->GetName().c_str() : "<none>",
@@ -1077,7 +1078,7 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
}
else
{
sLog->outError("WorldSocket::HandlePing: peer sent CMSG_PING, "
LOG_ERROR("server", "WorldSocket::HandlePing: peer sent CMSG_PING, "
"but is not authenticated or got recently kicked, "
" address = %s",
GetRemoteAddress().c_str());