DDraceNetwork Docs
logger.h
Go to the documentation of this file.
1#ifndef BASE_LOGGER_H
2#define BASE_LOGGER_H
3
4#include "lock.h"
5#include "log.h"
6
7#include <atomic>
8#include <memory>
9#include <vector>
10
11typedef void *IOHANDLE;
12
19{
20public:
31 char m_aTimestamp[80];
32 char m_aSystem[32];
36 char m_aLine[4096];
44
48 const char *Message() const
49 {
51 }
52};
53
55{
56public:
61 std::atomic_int m_MaxLevel{LEVEL_INFO};
62
63 bool Filters(const CLogMessage *pMessage);
64};
65
67{
68protected:
70
71public:
72 virtual ~ILogger() {}
73
78 void SetFilter(const CLogFilter &Filter)
79 {
80 m_Filter.m_MaxLevel.store(Filter.m_MaxLevel.load(std::memory_order_relaxed), std::memory_order_relaxed);
82 }
83
89 virtual void Log(const CLogMessage *pMessage) = 0;
105 virtual void GlobalFinish() {}
109 virtual void OnFilterChange() {}
110};
111
124void log_set_global_logger(ILogger *logger);
125
138
151
159
170void log_set_scope_logger(ILogger *logger);
171
179std::unique_ptr<ILogger> log_logger_android();
180
186std::unique_ptr<ILogger> log_logger_collection(std::vector<std::shared_ptr<ILogger>> &&vpLoggers);
187
195std::unique_ptr<ILogger> log_logger_file(IOHANDLE file);
196
202std::unique_ptr<ILogger> log_logger_stdout();
203
211std::unique_ptr<ILogger> log_logger_windows_debugger();
212
218std::unique_ptr<ILogger> log_logger_noop();
219
232class CFutureLogger : public ILogger
233{
234private:
235 std::shared_ptr<ILogger> m_pLogger;
236 std::vector<CLogMessage> m_vPending;
238
239public:
244 void Set(std::shared_ptr<ILogger> pLogger) REQUIRES(!m_PendingLock);
245 void Log(const CLogMessage *pMessage) override REQUIRES(!m_PendingLock);
246 void GlobalFinish() override;
247 void OnFilterChange() override;
248};
249
258{
261
262public:
265 new_scope_logger(logger)
266 {
268 }
270 {
271 //dbg_assert(log_get_scope_logger() == new_scope_logger, "loggers weren't properly scoped");
273 }
274};
275#endif // BASE_LOGGER_H
Definition: logger.h:233
void Log(const CLogMessage *pMessage) override
Definition: log.cpp:517
void OnFilterChange() override
Definition: log.cpp:544
void Set(std::shared_ptr< ILogger > pLogger)
Definition: log.cpp:499
std::shared_ptr< ILogger > m_pLogger
Definition: logger.h:235
std::vector< CLogMessage > m_vPending
Definition: logger.h:236
CLock m_PendingLock
Definition: logger.h:237
void GlobalFinish() override
Definition: log.cpp:535
Definition: lock.h:88
Definition: logger.h:55
std::atomic_int m_MaxLevel
Definition: logger.h:61
bool Filters(const CLogMessage *pMessage)
Definition: log.cpp:144
Definition: logger.h:19
int m_LineMessageOffset
Definition: logger.h:43
char m_aSystem[32]
Definition: logger.h:32
char m_aLine[4096]
Definition: logger.h:36
char m_aTimestamp[80]
Definition: logger.h:31
int m_TimestampLength
Definition: logger.h:37
bool m_HaveColor
Definition: logger.h:25
LOG_COLOR m_Color
Definition: logger.h:30
const char * Message() const
Definition: logger.h:48
int m_LineLength
Definition: logger.h:42
int m_SystemLength
Definition: logger.h:38
LEVEL m_Level
Definition: logger.h:24
Definition: logger.h:258
~CLogScope()
Definition: logger.h:269
ILogger * old_scope_logger
Definition: logger.h:259
ILogger * new_scope_logger
Definition: logger.h:260
CLogScope(ILogger *logger)
Definition: logger.h:263
Definition: logger.h:67
virtual void Log(const CLogMessage *pMessage)=0
virtual ~ILogger()
Definition: logger.h:72
CLogFilter m_Filter
Definition: logger.h:69
virtual void GlobalFinish()
Definition: logger.h:105
void SetFilter(const CLogFilter &Filter)
Definition: logger.h:78
virtual void OnFilterChange()
Definition: logger.h:109
std::unique_ptr< ILogger > log_logger_noop()
Definition: log.cpp:494
ILogger * log_get_scope_logger()
Definition: log.cpp:57
void log_set_global_logger(ILogger *logger)
Definition: log.cpp:26
std::unique_ptr< ILogger > log_logger_windows_debugger()
Definition: log.cpp:479
std::unique_ptr< ILogger > log_logger_android()
Definition: log.cpp:176
std::unique_ptr< ILogger > log_logger_file(IOHANDLE file)
Definition: log.cpp:277
void log_set_global_logger_default()
Definition: log.cpp:43
std::unique_ptr< ILogger > log_logger_stdout()
Definition: log.cpp:386
void log_set_scope_logger(ILogger *logger)
Definition: log.cpp:66
std::unique_ptr< ILogger > log_logger_collection(std::vector< std::shared_ptr< ILogger > > &&vpLoggers)
Definition: log.cpp:213
void log_global_logger_finish()
Definition: log.cpp:36
#define REQUIRES(...)
Definition: lock.h:32
LEVEL
Definition: log.h:14
@ LEVEL_INFO
Definition: log.h:17
void * IOHANDLE
Definition: logger.h:11
Definition: log.h:23