Merge branch 'azerothcore:master' into Playerbot

This commit is contained in:
ZhengPeiRu21
2022-05-19 12:55:28 -06:00
committed by GitHub
80 changed files with 280 additions and 175 deletions

View File

@@ -194,6 +194,8 @@ void AppenderConsole::_write(LogMessage const* message)
case LOG_LEVEL_FATAL:
index = 0;
break;
case LOG_LEVEL_ERROR:
[[fallthrough]];
default:
index = 1;
break;

View File

@@ -20,9 +20,11 @@
#include "AppenderFile.h"
#include "Config.h"
#include "Errors.h"
#include "IoContext.h"
#include "LogMessage.h"
#include "LogOperation.h"
#include "Logger.h"
#include "Strand.h"
#include "StringConvert.h"
#include "Timer.h"
#include "Tokenize.h"
@@ -38,6 +40,7 @@ Log::Log() : AppenderId(0), highestLogLevel(LOG_LEVEL_FATAL)
Log::~Log()
{
delete _strand;
Close();
}
@@ -240,7 +243,13 @@ void Log::write(std::unique_ptr<LogMessage>&& msg) const
{
Logger const* logger = GetLoggerByType(msg->type);
logger->write(msg.get());
if (_ioContext)
{
std::shared_ptr<LogOperation> logOperation = std::make_shared<LogOperation>(logger, std::move(msg));
Acore::Asio::post(*_ioContext, Acore::Asio::bind_executor(*_strand, [logOperation]() { logOperation->call(); }));
}
else
logger->write(msg.get());
}
Logger const* Log::GetLoggerByType(std::string const& type) const
@@ -356,11 +365,24 @@ Log* Log::instance()
return &instance;
}
void Log::Initialize()
void Log::Initialize(Acore::Asio::IoContext* ioContext)
{
if (ioContext)
{
_ioContext = ioContext;
_strand = new Acore::Asio::Strand(*ioContext);
}
LoadFromConfig();
}
void Log::SetSynchronous()
{
delete _strand;
_strand = nullptr;
_ioContext = nullptr;
}
void Log::LoadFromConfig()
{
Close();

View File

@@ -29,6 +29,12 @@ class Appender;
class Logger;
struct LogMessage;
namespace Acore::Asio
{
class IoContext;
class Strand;
}
#define LOGGER_ROOT "root"
typedef Appender*(*AppenderCreatorFn)(uint8 id, std::string const& name, LogLevel level, AppenderFlags flags, std::vector<std::string_view> const& extraArgs);
@@ -54,7 +60,8 @@ private:
public:
static Log* instance();
void Initialize();
void Initialize(Acore::Asio::IoContext* ioContext);
void SetSynchronous(); // Not threadsafe - should only be called from main() after all threads are joined
void LoadFromConfig();
void Close();
[[nodiscard]] bool ShouldLog(std::string const& type, LogLevel level) const;
@@ -112,6 +119,8 @@ private:
std::string m_logsDir;
std::string m_logsTimestamp;
Acore::Asio::IoContext* _ioContext;
Acore::Asio::Strand* _strand;
// Deprecated debug filter logs
DebugLogFilters _debugLogMask;
};

View File

@@ -23,13 +23,13 @@
// EnumUtils: DESCRIBE THIS
enum LogLevel : uint8
{
LOG_LEVEL_DISABLED,
LOG_LEVEL_FATAL,
LOG_LEVEL_ERROR,
LOG_LEVEL_WARN,
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG,
LOG_LEVEL_TRACE,
LOG_LEVEL_DISABLED = 0,
LOG_LEVEL_FATAL = 1,
LOG_LEVEL_ERROR = 2,
LOG_LEVEL_WARN = 3,
LOG_LEVEL_INFO = 4,
LOG_LEVEL_DEBUG = 5,
LOG_LEVEL_TRACE = 6,
NUM_ENABLED_LOG_LEVELS = LOG_LEVEL_TRACE, // SKIP
LOG_LEVEL_INVALID = 0xFF // SKIP