2014-08-10 19:44:49 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
class cLogger
|
2014-08-10 19:44:49 +01:00
|
|
|
{
|
2014-08-12 16:05:04 +01:00
|
|
|
public:
|
2014-08-10 19:44:49 +01:00
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
class cListener
|
2014-08-10 19:44:49 +01:00
|
|
|
{
|
|
|
|
public:
|
2020-05-15 03:35:43 +01:00
|
|
|
virtual void Log(std::string_view a_Message, eLogLevel a_LogLevel) = 0;
|
2014-08-12 16:05:04 +01:00
|
|
|
|
|
|
|
virtual ~cListener(){}
|
2014-08-10 19:44:49 +01:00
|
|
|
};
|
|
|
|
|
2015-08-30 22:57:43 +01:00
|
|
|
class cAttachment
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-04-01 16:28:42 +01:00
|
|
|
cAttachment() : m_listener(nullptr) {}
|
2015-08-30 22:57:43 +01:00
|
|
|
cAttachment(cAttachment && a_other)
|
|
|
|
: m_listener(a_other.m_listener)
|
|
|
|
{
|
2017-04-01 16:28:42 +01:00
|
|
|
a_other.m_listener = nullptr;
|
2015-08-30 22:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~cAttachment()
|
|
|
|
{
|
2017-04-01 16:28:42 +01:00
|
|
|
if (m_listener != nullptr)
|
|
|
|
{
|
|
|
|
cLogger::GetInstance().DetachListener(m_listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cAttachment & operator=(cAttachment && a_other)
|
|
|
|
{
|
|
|
|
m_listener = a_other.m_listener;
|
|
|
|
a_other.m_listener = nullptr;
|
|
|
|
return *this;
|
2015-08-30 22:57:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
cListener * m_listener;
|
|
|
|
|
|
|
|
friend class cLogger;
|
|
|
|
|
|
|
|
cAttachment(cListener * a_listener) : m_listener(a_listener) {}
|
|
|
|
};
|
|
|
|
|
2018-01-03 17:41:16 +00:00
|
|
|
/** Log a message formatted with a printf style formatting string. */
|
2020-05-04 19:21:48 +01:00
|
|
|
void LogPrintf(std::string_view a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList);
|
2018-01-03 17:41:16 +00:00
|
|
|
|
|
|
|
/** Log a message formatted with a python style formatting string. */
|
2020-05-04 19:21:48 +01:00
|
|
|
void LogFormat(std::string_view a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList);
|
2014-08-10 19:44:49 +01:00
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
/** Logs the simple text message at the specified log level. */
|
2020-05-15 03:35:43 +01:00
|
|
|
void LogSimple(std::string_view a_Message, eLogLevel a_LogLevel = eLogLevel::Regular);
|
2014-08-10 19:44:49 +01:00
|
|
|
|
2015-08-30 22:57:43 +01:00
|
|
|
cAttachment AttachListener(std::unique_ptr<cListener> a_Listener);
|
2016-02-05 23:45:45 +02:00
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
static cLogger & GetInstance(void);
|
2020-05-04 19:21:48 +01:00
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
// Must be called before calling GetInstance in a multithreaded context
|
|
|
|
static void InitiateMultithreading();
|
2020-05-04 19:21:48 +01:00
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
private:
|
2014-08-10 19:44:49 +01:00
|
|
|
|
2014-08-12 16:05:04 +01:00
|
|
|
cCriticalSection m_CriticalSection;
|
2015-08-30 22:57:43 +01:00
|
|
|
std::vector<std::unique_ptr<cListener>> m_LogListeners;
|
2014-08-10 19:44:49 +01:00
|
|
|
|
2015-08-30 22:57:43 +01:00
|
|
|
void DetachListener(cListener * a_Listener);
|
2020-05-15 03:35:43 +01:00
|
|
|
void LogLine(std::string_view a_Line, eLogLevel a_LogLevel);
|
2015-08-30 22:57:43 +01:00
|
|
|
};
|