Cuberite
A lightweight, fast and extensible game server for Minecraft
Logger.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 
5 class cLogger
6 {
7 public:
8 
9  class cListener
10  {
11  public:
12  virtual void Log(std::string_view a_Message, eLogLevel a_LogLevel) = 0;
13 
14  virtual ~cListener(){}
15  };
16 
18  {
19  public:
20 
21  cAttachment() : m_listener(nullptr) {}
23  : m_listener(a_other.m_listener)
24  {
25  a_other.m_listener = nullptr;
26  }
27 
29  {
30  if (m_listener != nullptr)
31  {
33  }
34  }
35 
37  {
38  m_listener = a_other.m_listener;
39  a_other.m_listener = nullptr;
40  return *this;
41  }
42 
43  private:
44 
46 
47  friend class cLogger;
48 
49  cAttachment(cListener * a_listener) : m_listener(a_listener) {}
50  };
51 
53  void LogPrintf(std::string_view a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList);
54 
56  void LogFormat(std::string_view a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList);
57 
59  void LogSimple(std::string_view a_Message, eLogLevel a_LogLevel = eLogLevel::Regular);
60 
61  cAttachment AttachListener(std::unique_ptr<cListener> a_Listener);
62 
63  static cLogger & GetInstance(void);
64 
65  // Must be called before calling GetInstance in a multithreaded context
66  static void InitiateMultithreading();
67 
68 private:
69 
71  std::vector<std::unique_ptr<cListener>> m_LogListeners;
72 
73  void DetachListener(cListener * a_Listener);
74  void LogLine(std::string_view a_Line, eLogLevel a_LogLevel);
75 };
eLogLevel
Definition: LoggerSimple.h:6
Definition: Logger.h:6
void LogPrintf(std::string_view a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList)
Log a message formatted with a printf style formatting string.
Definition: Logger.cpp:87
void LogLine(std::string_view a_Line, eLogLevel a_LogLevel)
Definition: Logger.cpp:74
static cLogger & GetInstance(void)
Definition: Logger.cpp:43
void LogFormat(std::string_view a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList)
Log a message formatted with a python style formatting string.
Definition: Logger.cpp:101
void DetachListener(cListener *a_Listener)
Definition: Logger.cpp:129
static void InitiateMultithreading()
Definition: Logger.cpp:53
std::vector< std::unique_ptr< cListener > > m_LogListeners
Definition: Logger.h:71
void LogSimple(std::string_view a_Message, eLogLevel a_LogLevel=eLogLevel::Regular)
Logs the simple text message at the specified log level.
Definition: Logger.cpp:62
cCriticalSection m_CriticalSection
Definition: Logger.h:70
cAttachment AttachListener(std::unique_ptr< cListener > a_Listener)
Definition: Logger.cpp:115
virtual ~cListener()
Definition: Logger.h:14
virtual void Log(std::string_view a_Message, eLogLevel a_LogLevel)=0
cAttachment(cListener *a_listener)
Definition: Logger.h:49
cListener * m_listener
Definition: Logger.h:45
cAttachment & operator=(cAttachment &&a_other)
Definition: Logger.h:36
cAttachment(cAttachment &&a_other)
Definition: Logger.h:22