18#ifndef TRINITYCORE_LOG_H
19#define TRINITYCORE_LOG_H
26#include <unordered_map>
41#define LOGGER_ROOT "root"
45template <
class AppenderImpl>
48 return new AppenderImpl(
id, name, level,
flags, extraArgs);
62 static Log* instance();
65 void SetSynchronous();
66 void LoadFromConfig();
68 bool ShouldLog(std::string_view type,
LogLevel level)
const;
69 bool SetLogLevel(std::string
const& name,
int32 level,
bool isLogger =
true);
71 template<
typename... Args>
77 template<
typename... Args>
86 void OutCharDump(
char const* str,
uint32 account_id,
uint64 guid,
char const* name);
88 void SetRealmId(
uint32 id);
90 template<
class AppenderImpl>
93 RegisterAppender(AppenderImpl::type, &CreateAppender<AppenderImpl>);
96 std::string
const&
GetLogsDir()
const {
return m_logsDir; }
99 void CreateAppenderFromConfigLine(std::string
const& name, std::string
const& options);
100 void CreateLoggerFromConfigLine(std::string
const& name, std::string
const& options);
103 static std::string GetTimestampStr();
104 void write(std::unique_ptr<LogMessage> msg)
const;
106 Logger const* GetLoggerByType(std::string_view type)
const;
107 Appender* GetAppenderByName(std::string_view name);
108 uint8 NextAppenderId();
109 void CreateAppenderFromConfig(std::string
const& name);
110 void CreateLoggerFromConfig(std::string
const& name);
111 void ReadAppendersFromConfig();
112 void ReadLoggersFromConfig();
118 std::unordered_map<uint8, std::unique_ptr<Appender>>
appenders;
119 std::unordered_map<std::string_view, std::unique_ptr<Logger>>
loggers;
130#define sLog Log::instance()
132#ifdef PERFORMANCE_PROFILING
133#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) ((void)0)
134#elif TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
137#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \
139 if (Log* logInstance = sLog; logInstance->ShouldLog(filterType__, level__)) \
140 logInstance->OutMessage(filterType__, level__, __VA_ARGS__); \
143#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \
144 __pragma(warning(push)) \
145 __pragma(warning(disable:4127)) \
147 if (Log* logInstance = sLog; logInstance->ShouldLog(filterType__, level__)) \
148 logInstance->OutMessage(filterType__, level__, __VA_ARGS__); \
150 __pragma(warning(pop))
153#define TC_LOG_TRACE(filterType__, ...) \
154 TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_TRACE, __VA_ARGS__)
156#define TC_LOG_DEBUG(filterType__, ...) \
157 TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_DEBUG, __VA_ARGS__)
159#define TC_LOG_INFO(filterType__, ...) \
160 TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_INFO, __VA_ARGS__)
162#define TC_LOG_WARN(filterType__, ...) \
163 TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_WARN, __VA_ARGS__)
165#define TC_LOG_ERROR(filterType__, ...) \
166 TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_ERROR, __VA_ARGS__)
168#define TC_LOG_FATAL(filterType__, ...) \
169 TC_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_FATAL, __VA_ARGS__)
Appender *(* AppenderCreatorFn)(uint8 id, std::string const &name, LogLevel level, AppenderFlags flags, std::vector< std::string_view > const &extraArgs)
Appender * CreateAppender(uint8 id, std::string const &name, LogLevel level, AppenderFlags flags, std::vector< std::string_view > const &extraArgs)
std::unordered_map< std::string_view, std::unique_ptr< Logger > > loggers
Trinity::Asio::Strand * _strand
std::string const & GetLogsDir() const
void OutCommand(uint32 account, Trinity::FormatString< Args... > fmt, Args &&... args)
std::unordered_map< uint8, std::unique_ptr< Appender > > appenders
std::string m_logsTimestamp
Trinity::Asio::IoContext * _ioContext
Log & operator=(Log const &)=delete
Log & operator=(Log &&)=delete
void OutMessage(std::string_view filter, LogLevel const level, Trinity::FormatString< Args... > fmt, Args &&... args)
std::string const & GetLogsTimestamp() const
std::unordered_map< uint8, AppenderCreatorFn > appenderFactory
fmt::format_args FormatArgs
fmt::format_string< Args... > FormatString
constexpr auto MakeFormatArgs(Args &&... args)
fmt::string_view FormatStringView