diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Logging/Log.cpp | 46 | ||||
-rw-r--r-- | src/common/Logging/Log.h | 3 | ||||
-rw-r--r-- | src/common/Logging/LogOperation.cpp | 11 | ||||
-rw-r--r-- | src/common/Logging/LogOperation.h | 11 | ||||
-rw-r--r-- | src/server/game/Handlers/CharacterHandler.cpp | 2 |
5 files changed, 38 insertions, 35 deletions
diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp index dc8f1005d93..99ff568ecd4 100644 --- a/src/common/Logging/Log.cpp +++ b/src/common/Logging/Log.cpp @@ -21,9 +21,9 @@ #include "Config.h" #include "Duration.h" #include "Errors.h" -#include "Logger.h" #include "LogMessage.h" #include "LogOperation.h" +#include "Logger.h" #include "Strand.h" #include "StringConvert.h" #include "Util.h" @@ -223,23 +223,26 @@ void Log::RegisterAppender(uint8 index, AppenderCreatorFn appenderCreateFn) void Log::OutMessageImpl(Logger const* logger, std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const { - write(logger, std::make_unique<LogMessage>(level, filter, Trinity::StringVFormat(messageFormat, messageFormatArgs))); + if (_ioContext) + Trinity::Asio::post(*_strand, LogOperation(logger, new LogMessage(level, filter, Trinity::StringVFormat(messageFormat, messageFormatArgs)))); + else + { + LogMessage msg(level, filter, Trinity::StringVFormat(messageFormat, messageFormatArgs)); + logger->write(&msg); + } } void Log::OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const { - write(GetLoggerByType("commands.gm"), std::make_unique<LogMessage>(LOG_LEVEL_INFO, "commands.gm", Trinity::StringVFormat(messageFormat, messageFormatArgs), Trinity::ToString(account))); -} + Logger const* logger = GetLoggerByType("commands.gm"); -void Log::write(Logger const* logger, std::unique_ptr<LogMessage> msg) const -{ if (_ioContext) + Trinity::Asio::post(*_strand, LogOperation(logger, new LogMessage(LOG_LEVEL_INFO, "commands.gm", Trinity::StringVFormat(messageFormat, messageFormatArgs), Trinity::ToString(account)))); + else { - std::shared_ptr<LogOperation> logOperation = std::make_shared<LogOperation>(logger, std::move(msg)); - Trinity::Asio::post(*_strand, [logOperation]() { logOperation->call(); }); + LogMessage msg(LOG_LEVEL_INFO, "commands.gm", Trinity::StringVFormat(messageFormat, messageFormatArgs), Trinity::ToString(account)); + logger->write(&msg); } - else - logger->write(msg.get()); } Logger const* Log::GetLoggerByType(std::string_view type) const @@ -318,22 +321,23 @@ bool Log::SetLogLevel(std::string const& name, int32 newLeveli, bool isLogger /* return true; } -void Log::OutCharDump(char const* str, uint32 accountId, uint64 guid, char const* name) +void Log::OutCharDump(std::string const& str, uint32 accountId, uint64 guid, std::string const& name) const { - if (!str || !ShouldLog("entities.player.dump", LOG_LEVEL_INFO)) + if (!ShouldLog("entities.player.dump", LOG_LEVEL_INFO)) return; - std::ostringstream ss; - ss << "== START DUMP == (account: " << accountId << " guid: " << guid << " name: " << name - << ")\n" << str << "\n== END DUMP ==\n"; + std::string ss = Trinity::StringFormat("== START DUMP == (account: {} guid: {} name: {})\n{}\n== END DUMP ==\n", accountId, guid, name, str); + std::string param = Trinity::StringFormat("{}_{}", guid, name); - std::unique_ptr<LogMessage> msg(new LogMessage(LOG_LEVEL_INFO, "entities.player.dump", ss.str())); - std::ostringstream param; - param << guid << '_' << name; + Logger const* logger = GetLoggerByType("entities.player.dump"); - msg->param1 = param.str(); - - write(GetLoggerByType("entities.player.dump"), std::move(msg)); + if (_ioContext) + Trinity::Asio::post(*_strand, LogOperation(logger, new LogMessage(LOG_LEVEL_INFO, "entities.player.dump", std::move(ss), std::move(param)))); + else + { + LogMessage msg(LOG_LEVEL_INFO, "entities.player.dump", std::move(ss), std::move(param)); + logger->write(&msg); + } } void Log::SetRealmId(uint32 id) diff --git a/src/common/Logging/Log.h b/src/common/Logging/Log.h index dd6149f42b0..9f9634a40ae 100644 --- a/src/common/Logging/Log.h +++ b/src/common/Logging/Log.h @@ -90,7 +90,7 @@ class TC_COMMON_API Log this->OutCommandImpl(account, fmt, Trinity::MakeFormatArgs(args...)); } - void OutCharDump(char const* str, uint32 account_id, uint64 guid, char const* name); + void OutCharDump(std::string const& str, uint32 account_id, uint64 guid, std::string const& name) const; void SetRealmId(uint32 id); @@ -126,7 +126,6 @@ class TC_COMMON_API Log private: static std::string GetTimestampStr(); - void write(Logger const* logger, std::unique_ptr<LogMessage> msg) const; Logger const* GetLoggerByType(std::string_view type) const; Appender* GetAppenderByName(std::string_view name); diff --git a/src/common/Logging/LogOperation.cpp b/src/common/Logging/LogOperation.cpp index 8370c075ed7..4a1bad6ff41 100644 --- a/src/common/Logging/LogOperation.cpp +++ b/src/common/Logging/LogOperation.cpp @@ -16,19 +16,16 @@ */ #include "LogOperation.h" -#include "Logger.h" #include "LogMessage.h" +#include "Logger.h" -LogOperation::LogOperation(Logger const* _logger, std::unique_ptr<LogMessage>&& _msg) : logger(_logger), msg(std::forward<std::unique_ptr<LogMessage>>(_msg)) +LogOperation::LogOperation(Logger const* _logger, LogMessage* _msg) : logger(_logger), msg(_msg) { } -LogOperation::~LogOperation() -{ -} +LogOperation::~LogOperation() = default; -int LogOperation::call() +void LogOperation::operator()() const { logger->write(msg.get()); - return 0; } diff --git a/src/common/Logging/LogOperation.h b/src/common/Logging/LogOperation.h index 25dc075bd2f..0a642d56e12 100644 --- a/src/common/Logging/LogOperation.h +++ b/src/common/Logging/LogOperation.h @@ -24,14 +24,17 @@ class Logger; struct LogMessage; -class TC_COMMON_API LogOperation +class LogOperation { public: - LogOperation(Logger const* _logger, std::unique_ptr<LogMessage>&& _msg); - + LogOperation(Logger const* _logger, LogMessage* _msg); + LogOperation(LogOperation const&) = delete; + LogOperation(LogOperation&&) noexcept = default; + LogOperation& operator=(LogOperation const&) = delete; + LogOperation& operator=(LogOperation&&) noexcept = default; ~LogOperation(); - int call(); + void operator()() const; protected: Logger const* logger; diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 2c182149d39..e876cada3fd 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -1056,7 +1056,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPackets::Character::CharDelete& c { std::string dump; if (PlayerDumpWriter().GetDump(charDelete.Guid.GetCounter(), dump)) - sLog->OutCharDump(dump.c_str(), accountId, charDelete.Guid.GetCounter(), name.c_str()); + sLog->OutCharDump(dump, accountId, charDelete.Guid.GetCounter(), name); } sCalendarMgr->RemoveAllPlayerEventsAndInvites(charDelete.Guid); |