TrinityCore
Loading...
Searching...
No Matches
Log Class Reference

#include <Log.h>

Public Member Functions

void Initialize (Trinity::Asio::IoContext *ioContext)
 
void SetSynchronous ()
 
void LoadFromConfig ()
 
void Close ()
 
bool ShouldLog (std::string const &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)
 
template<typename... Args>
void OutCommand (uint32 account, Trinity::FormatString< Args... > fmt, Args &&... args)
 
void OutCharDump (char const *str, uint32 account_id, uint64 guid, char const *name)
 
void SetRealmId (uint32 id)
 
template<class AppenderImpl >
void RegisterAppender ()
 
std::string const & GetLogsDir () const
 
std::string const & GetLogsTimestamp () const
 

Static Public Member Functions

static Log * instance ()
 

Private Types

typedef std::unordered_map< std::string, Logger > LoggerMap
 

Private Member Functions

 Log ()
 
 ~Log ()
 
 Log (Log const &)=delete
 
 Log (Log &&)=delete
 
Log & operator= (Log const &)=delete
 
Log & operator= (Log &&)=delete
 
void write (std::unique_ptr< LogMessage > msg) const
 
Logger const * GetLoggerByType (std::string const &type) const
 
Appender * GetAppenderByName (std::string_view name)
 
uint8 NextAppenderId ()
 
void CreateAppenderFromConfig (std::string const &name)
 
void CreateLoggerFromConfig (std::string const &name)
 
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)
 

Static Private Member Functions

static std::string GetTimestampStr ()
 

Private Attributes

std::unordered_map< uint8, AppenderCreatorFn > appenderFactory
 
std::unordered_map< uint8, std::unique_ptr< Appender > > appenders
 
std::unordered_map< std::string, std::unique_ptr< Logger > > loggers
 
uint8 AppenderId
 
LogLevel lowestLogLevel
 
std::string m_logsDir
 
std::string m_logsTimestamp
 
Trinity::Asio::IoContext * _ioContext
 
Trinity::Asio::Strand * _strand
 

Detailed Description

Definition at line 52 of file Log.h.

Member Typedef Documentation

◆ LoggerMap

typedef std::unordered_map<std::string, Logger> Log::LoggerMap
private

Definition at line 54 of file Log.h.

Constructor & Destructor Documentation

◆ Log() [1/3]

Log::Log ( )
private

Definition at line 33 of file Log.cpp.

References GetTimestampStr(), and m_logsTimestamp.

◆ ~Log()

Log::~Log ( )
private

Definition at line 40 of file Log.cpp.

References _strand, and Close().

◆ Log() [2/3]

Log::Log ( Log const &  )
privatedelete

◆ Log() [3/3]

Log::Log ( Log &&  )
privatedelete

Member Function Documentation

◆ Close()

void Log::Close ( )

Definition at line 331 of file Log.cpp.

References appenders, and loggers.

Referenced by LoadFromConfig(), ReadLoggersFromConfig(), and ~Log().

◆ CreateAppenderFromConfig()

void Log::CreateAppenderFromConfig ( std::string const &  name)
private

◆ CreateLoggerFromConfig()

void Log::CreateLoggerFromConfig ( std::string const &  name)
private

◆ GetAppenderByName()

Appender * Log::GetAppenderByName ( std::string_view  name)
private

Definition at line 51 of file Log.cpp.

References appenders.

Referenced by CreateLoggerFromConfig(), and SetLogLevel().

◆ GetLoggerByType()

Logger const * Log::GetLoggerByType ( std::string const &  type) const
private

Definition at line 240 of file Log.cpp.

References GetLoggerByType(), LOGGER_ROOT, and loggers.

Referenced by GetLoggerByType(), ShouldLog(), and write().

◆ GetLogsDir()

std::string const & Log::GetLogsDir ( ) const
inline

Definition at line 99 of file Log.h.

◆ GetLogsTimestamp()

std::string const & Log::GetLogsTimestamp ( ) const
inline

Definition at line 100 of file Log.h.

◆ GetTimestampStr()

std::string Log::GetTimestampStr ( )
staticprivate

Definition at line 257 of file Log.cpp.

References Trinity::StringFormat().

Referenced by Log().

◆ Initialize()

void Log::Initialize ( Trinity::Asio::IoContext *  ioContext)

Definition at line 361 of file Log.cpp.

References _ioContext, _strand, and LoadFromConfig().

◆ instance()

Log * Log::instance ( )
static

Definition at line 355 of file Log.cpp.

References instance().

Referenced by instance().

◆ LoadFromConfig()

void Log::LoadFromConfig ( )

◆ NextAppenderId()

uint8 Log::NextAppenderId ( )
private

Definition at line 46 of file Log.cpp.

References AppenderId.

Referenced by CreateAppenderFromConfig(), and ReadLoggersFromConfig().

◆ operator=() [1/2]

Log & Log::operator= ( Log &&  )
privatedelete

◆ operator=() [2/2]

Log & Log::operator= ( Log const &  )
privatedelete

◆ OutCharDump()

void Log::OutCharDump ( char const *  str,
uint32  account_id,
uint64  guid,
char const *  name 
)

Definition at line 307 of file Log.cpp.

References LOG_LEVEL_INFO, ShouldLog(), and write().

◆ OutCommand()

template<typename... Args>
void Log::OutCommand ( uint32  account,
Trinity::FormatString< Args... >  fmt,
Args &&...  args 
)
inline

Definition at line 81 of file Log.h.

References LOG_LEVEL_INFO, and Trinity::MakeFormatArgs().

◆ OutCommandImpl()

void Log::OutCommandImpl ( uint32  account,
Trinity::FormatStringView  messageFormat,
Trinity::FormatArgs  messageFormatArgs 
)
private

Definition at line 222 of file Log.cpp.

References LOG_LEVEL_INFO, Trinity::StringVFormat(), Trinity::ToString(), and write().

◆ OutMessage()

template<typename... Args>
void Log::OutMessage ( std::string_view  filter,
LogLevel const  level,
Trinity::FormatString< Args... >  fmt,
Args &&...  args 
)
inline

Definition at line 75 of file Log.h.

References Trinity::MakeFormatArgs().

◆ OutMessageImpl()

void Log::OutMessageImpl ( std::string_view  filter,
LogLevel  level,
Trinity::FormatStringView  messageFormat,
Trinity::FormatArgs  messageFormatArgs 
)
private

Definition at line 217 of file Log.cpp.

References Trinity::StringVFormat(), and write().

◆ ReadAppendersFromConfig()

void Log::ReadAppendersFromConfig ( )
private

Definition at line 176 of file Log.cpp.

References CreateAppenderFromConfig(), and sConfigMgr.

Referenced by LoadFromConfig().

◆ ReadLoggersFromConfig()

◆ RegisterAppender() [1/2]

template<class AppenderImpl >
void Log::RegisterAppender ( )
inline

Definition at line 94 of file Log.h.

◆ RegisterAppender() [2/2]

void Log::RegisterAppender ( uint8  index,
AppenderCreatorFn  appenderCreateFn 
)
private

Definition at line 210 of file Log.cpp.

References appenderFactory, and ASSERT.

◆ SetLogLevel()

bool Log::SetLogLevel ( std::string const &  name,
int32  level,
bool  isLogger = true 
)

◆ SetRealmId()

void Log::SetRealmId ( uint32  id)

Definition at line 325 of file Log.cpp.

References appenders.

◆ SetSynchronous()

void Log::SetSynchronous ( )

Definition at line 372 of file Log.cpp.

References _ioContext, and _strand.

◆ ShouldLog()

bool Log::ShouldLog ( std::string const &  type,
LogLevel  level 
) const

Definition at line 337 of file Log.cpp.

References GetLoggerByType(), Logger::getLogLevel(), LOG_LEVEL_DISABLED, and lowestLogLevel.

Referenced by OutCharDump().

◆ write()

void Log::write ( std::unique_ptr< LogMessage >  msg) const
private

Member Data Documentation

◆ _ioContext

Trinity::Asio::IoContext* Log::_ioContext
private

Definition at line 126 of file Log.h.

Referenced by Initialize(), SetSynchronous(), and write().

◆ _strand

Trinity::Asio::Strand* Log::_strand
private

Definition at line 127 of file Log.h.

Referenced by Initialize(), SetSynchronous(), write(), and ~Log().

◆ appenderFactory

std::unordered_map<uint8, AppenderCreatorFn> Log::appenderFactory
private

Definition at line 117 of file Log.h.

Referenced by CreateAppenderFromConfig(), and RegisterAppender().

◆ AppenderId

uint8 Log::AppenderId
private

Definition at line 120 of file Log.h.

Referenced by LoadFromConfig(), and NextAppenderId().

◆ appenders

std::unordered_map<uint8, std::unique_ptr<Appender> > Log::appenders
private

◆ loggers

std::unordered_map<std::string, std::unique_ptr<Logger> > Log::loggers
private

◆ lowestLogLevel

LogLevel Log::lowestLogLevel
private

Definition at line 121 of file Log.h.

Referenced by CreateLoggerFromConfig(), LoadFromConfig(), SetLogLevel(), and ShouldLog().

◆ m_logsDir

std::string Log::m_logsDir
private

Definition at line 123 of file Log.h.

Referenced by LoadFromConfig().

◆ m_logsTimestamp

std::string Log::m_logsTimestamp
private

Definition at line 124 of file Log.h.

Referenced by Log().


The documentation for this class was generated from the following files: