mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-02-05 08:28:57 +01:00
Core/Logging: Fix intellisense errors - people don't like it when code glows red without a reason
This commit is contained in:
@@ -221,20 +221,18 @@ void Log::RegisterAppender(uint8 index, AppenderCreatorFn appenderCreateFn)
|
||||
appenderFactory[index] = appenderCreateFn;
|
||||
}
|
||||
|
||||
void Log::OutMessageImpl(std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs)
|
||||
void Log::OutMessageImpl(Logger const* logger, std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const
|
||||
{
|
||||
write(std::make_unique<LogMessage>(level, filter, Trinity::StringVFormat(messageFormat, messageFormatArgs)));
|
||||
write(logger, std::make_unique<LogMessage>(level, filter, Trinity::StringVFormat(messageFormat, messageFormatArgs)));
|
||||
}
|
||||
|
||||
void Log::OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs)
|
||||
void Log::OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const
|
||||
{
|
||||
write(std::make_unique<LogMessage>(LOG_LEVEL_INFO, "commands.gm", Trinity::StringVFormat(messageFormat, messageFormatArgs), Trinity::ToString(account)));
|
||||
write(GetLoggerByType("commands.gm"), std::make_unique<LogMessage>(LOG_LEVEL_INFO, "commands.gm", Trinity::StringVFormat(messageFormat, messageFormatArgs), Trinity::ToString(account)));
|
||||
}
|
||||
|
||||
void Log::write(std::unique_ptr<LogMessage> msg) const
|
||||
void Log::write(Logger const* logger, std::unique_ptr<LogMessage> msg) const
|
||||
{
|
||||
Logger const* logger = GetLoggerByType(msg->type);
|
||||
|
||||
if (_ioContext)
|
||||
{
|
||||
std::shared_ptr<LogOperation> logOperation = std::make_shared<LogOperation>(logger, std::move(msg));
|
||||
@@ -335,7 +333,7 @@ void Log::OutCharDump(char const* str, uint32 accountId, uint64 guid, char const
|
||||
|
||||
msg->param1 = param.str();
|
||||
|
||||
write(std::move(msg));
|
||||
write(GetLoggerByType("entities.player.dump"), std::move(msg));
|
||||
}
|
||||
|
||||
void Log::SetRealmId(uint32 id)
|
||||
@@ -368,6 +366,20 @@ bool Log::ShouldLog(std::string_view type, LogLevel level) const
|
||||
return logLevel != LOG_LEVEL_DISABLED && logLevel <= level;
|
||||
}
|
||||
|
||||
Logger const* Log::GetEnabledLogger(std::string_view type, LogLevel level) const
|
||||
{
|
||||
// Don't even look for a logger if the LogLevel is lower than lowest log levels across all loggers
|
||||
if (level < lowestLogLevel)
|
||||
return nullptr;
|
||||
|
||||
Logger const* logger = GetLoggerByType(type);
|
||||
if (!logger)
|
||||
return nullptr;
|
||||
|
||||
LogLevel logLevel = logger->getLogLevel();
|
||||
return logLevel != LOG_LEVEL_DISABLED && logLevel <= level ? logger : nullptr;
|
||||
}
|
||||
|
||||
Log* Log::instance()
|
||||
{
|
||||
static Log instance;
|
||||
|
||||
@@ -66,12 +66,19 @@ class TC_COMMON_API Log
|
||||
void LoadFromConfig();
|
||||
void Close();
|
||||
bool ShouldLog(std::string_view type, LogLevel level) const;
|
||||
Logger const* GetEnabledLogger(std::string_view type, LogLevel level) const;
|
||||
bool SetLogLevel(std::string const& name, int32 level, bool isLogger = true);
|
||||
|
||||
template<typename... Args>
|
||||
void OutMessage(std::string_view filter, LogLevel const level, Trinity::FormatString<Args...> fmt, Args&&... args)
|
||||
void OutMessage(std::string_view filter, LogLevel level, Trinity::FormatString<Args...> fmt, Args&&... args)
|
||||
{
|
||||
OutMessageImpl(filter, level, fmt, Trinity::MakeFormatArgs(args...));
|
||||
this->OutMessageImpl(GetLoggerByType(filter), filter, level, fmt, Trinity::MakeFormatArgs(args...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void OutMessageTo(Logger const* logger, std::string_view filter, LogLevel level, Trinity::FormatString<Args...> fmt, Args&&... args)
|
||||
{
|
||||
this->OutMessageImpl(logger, filter, level, fmt, Trinity::MakeFormatArgs(args...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
@@ -80,7 +87,7 @@ class TC_COMMON_API Log
|
||||
if (!ShouldLog("commands.gm", LOG_LEVEL_INFO))
|
||||
return;
|
||||
|
||||
OutCommandImpl(account, fmt, Trinity::MakeFormatArgs(args...));
|
||||
this->OutCommandImpl(account, fmt, Trinity::MakeFormatArgs(args...));
|
||||
}
|
||||
|
||||
void OutCharDump(char const* str, uint32 account_id, uint64 guid, char const* name);
|
||||
@@ -90,7 +97,7 @@ class TC_COMMON_API Log
|
||||
template<class AppenderImpl>
|
||||
void RegisterAppender()
|
||||
{
|
||||
RegisterAppender(AppenderImpl::type, &CreateAppender<AppenderImpl>);
|
||||
this->RegisterAppender(AppenderImpl::type, &CreateAppender<AppenderImpl>);
|
||||
}
|
||||
|
||||
std::string const& GetLogsDir() const { return m_logsDir; }
|
||||
@@ -111,9 +118,15 @@ class TC_COMMON_API Log
|
||||
return { std::begin(chars), (chars[CharArraySize - 1] == '\0' ? CharArraySize - 1 : CharArraySize) };
|
||||
}
|
||||
|
||||
template <size_t CharArraySize>
|
||||
static consteval Trinity::FormatStringView make_format_string_view(char const(&chars)[CharArraySize])
|
||||
{
|
||||
return { std::begin(chars), (chars[CharArraySize - 1] == '\0' ? CharArraySize - 1 : CharArraySize) };
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string GetTimestampStr();
|
||||
void write(std::unique_ptr<LogMessage> msg) const;
|
||||
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);
|
||||
@@ -123,8 +136,8 @@ class TC_COMMON_API Log
|
||||
void ReadAppendersFromConfig();
|
||||
void ReadLoggersFromConfig();
|
||||
void RegisterAppender(uint8 index, AppenderCreatorFn appenderCreateFn);
|
||||
void OutMessageImpl(std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs);
|
||||
void OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs);
|
||||
void OutMessageImpl(Logger const* logger, std::string_view filter, LogLevel level, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const;
|
||||
void OutCommandImpl(uint32 account, Trinity::FormatStringView messageFormat, Trinity::FormatArgs messageFormatArgs) const;
|
||||
|
||||
std::unordered_map<uint8, AppenderCreatorFn> appenderFactory;
|
||||
std::unordered_map<uint8, std::unique_ptr<Appender>> appenders;
|
||||
@@ -141,10 +154,12 @@ class TC_COMMON_API Log
|
||||
|
||||
#define sLog Log::instance()
|
||||
|
||||
#define TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ...) \
|
||||
do { \
|
||||
if (Log* logInstance = sLog; logInstance->ShouldLog(Log::make_string_view(filterType__), level__)) \
|
||||
logInstance->OutMessage(Log::make_string_view(filterType__), level__, Log::make_string_view(message__), ## __VA_ARGS__); \
|
||||
#define TC_LOG_MESSAGE_BODY_CORE(filterType__, level__, message__, ...) \
|
||||
do { \
|
||||
Log* logInstance = sLog; \
|
||||
if (Logger const* loggerInstance = logInstance->GetEnabledLogger(Log::make_string_view((filterType__)), (level__))) \
|
||||
logInstance->OutMessageTo(loggerInstance, Log::make_string_view((filterType__)), (level__), \
|
||||
Log::make_format_string_view((message__)), ## __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#ifdef PERFORMANCE_PROFILING
|
||||
|
||||
@@ -357,10 +357,10 @@ bool AuctionBotSeller::Initialize()
|
||||
{
|
||||
sLog->OutMessage("ahbot", LOG_LEVEL_DEBUG, "Items loaded \tGray\tWhite\tGreen\tBlue\tPurple\tOrange\tYellow");
|
||||
for (uint32 i = 0; i < MAX_ITEM_CLASS; ++i)
|
||||
sLog->OutMessage("ahbot", LOG_LEVEL_DEBUG, "\t\t%u\t%u\t%u\t%u\t%u\t%u\t%u",
|
||||
(uint32)_itemPool[0][i].size(), (uint32)_itemPool[1][i].size(), (uint32)_itemPool[2][i].size(),
|
||||
(uint32)_itemPool[3][i].size(), (uint32)_itemPool[4][i].size(), (uint32)_itemPool[5][i].size(),
|
||||
(uint32)_itemPool[6][i].size());
|
||||
sLog->OutMessage("ahbot", LOG_LEVEL_DEBUG, "\t\t{}\t{}\t{}\t{}\t{}\t{}\t{}",
|
||||
_itemPool[0][i].size(), _itemPool[1][i].size(), _itemPool[2][i].size(),
|
||||
_itemPool[3][i].size(), _itemPool[4][i].size(), _itemPool[5][i].size(),
|
||||
_itemPool[6][i].size());
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("ahbot", "AHBot seller configuration data loaded and initialized");
|
||||
|
||||
Reference in New Issue
Block a user