EHS
Loading...
Searching...
No Matches
Log.h
Go to the documentation of this file.
1#pragma once
2
3#include <initializer_list>
4
5#include "Types.h"
6#include "Array.h"
7#include "UTF.h"
8#include "Str.h"
9
10namespace ehs
11{
12 class Log;
13
14 typedef void (*LogRaisedCb)(const Log &);
15 typedef void (*LogOutputCb)(const Array<Log> &);
16
17 enum class LogType : UInt_8
18 {
23 };
24
28 class EHS_LIB_IO Log
29 {
30 private:
31 static void DefaultRaisedCb(const Log &log);
32
33 static void DefaultOutputCb(const Array<Log> &logs);
34
35 static LogRaisedCb raisedCb;
36 static LogOutputCb outputCb;
37 static Array<Log> logs;
38 static Log lastLog;
39 static bool immediate;
40 LogType type;
41 Array<Str_8> tags;
42 UInt_64 code;
43 Str_8 msg;
44
45 public:
46 static void SetRaisedCallback(LogRaisedCb newCb);
47
48 static void SetOutputCallback(LogOutputCb newCb);
49
50 static void OnExit();
51
52 static void Raise(Log log);
53
55 static Log GetLastLog();
56
57 static void EnableImmediateMode(bool enable);
58
60 Log();
61
66 Log(LogType type, const std::initializer_list<Str_8> &tags, UInt_64 code, Str_8 msg);
67
72 Log(LogType type, Array<Str_8> tags, UInt_64 code, Str_8 msg);
73
74 Log(Log &&log) noexcept;
75
78 Log(const Log &log);
79
80 Log &operator=(Log &&log) noexcept;
81
85 Log &operator=(const Log &log);
86
87 /*
91 bool operator==(const Log log);
92
96 bool operator!=(const Log log);
97 */
98
99 LogType GetType() const;
100
104 bool HasTags(const std::initializer_list<Str_8> &tags) const;
105
109 bool HasTags(const Array<Str_8> &tags) const;
110
114 bool HasTag(const Str_8 &tag) const;
115
118 const Array<Str_8> &GetTags() const;
119
120 UInt_64 GetCode() const;
121
124 Str_8 GetMsg() const;
125
126 Str_8 ToStr() const;
127
131 bool IsValid() const;
132 };
133}
134
135#ifndef EHS_LOG_INT
136 #ifdef EHS_DEBUG
137 #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg))
138 #else
139 #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg))
140 #endif
141#endif
142
143#ifndef EHS_LOG
144 #ifdef EHS_DEBUG
145 #define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg))
146 #else
147 #define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg))
148 #endif
149#endif
150
151#ifndef EHS_LOG_SUCCESS
152#define EHS_LOG_SUCCESS() ehs::Log::Raise({})
153#endif
Definition Array.h:16
Definition Log.h:29
UInt_64 GetCode() const
Definition Log.cpp:192
Log & operator=(Log &&log) noexcept
Definition Log.cpp:103
Str_8 GetMsg() const
Definition Log.cpp:197
static void EnableImmediateMode(bool enable)
Definition Log.cpp:68
Str_8 ToStr() const
Definition Log.cpp:202
Log()
Default members initialization.
Definition Log.cpp:73
bool HasTags(const std::initializer_list< Str_8 > &tags) const
Definition Log.cpp:149
static void SetOutputCallback(LogOutputCb newCb)
Definition Log.cpp:33
bool IsValid() const
Definition Log.cpp:244
LogType GetType() const
Definition Log.cpp:144
static void OnExit()
Definition Log.cpp:38
static void Raise(Log log)
Definition Log.cpp:49
static Log GetLastLog()
Retrieves the last log raised.
Definition Log.cpp:61
const Array< Str_8 > & GetTags() const
Definition Log.cpp:187
bool HasTag(const Str_8 &tag) const
Definition Log.cpp:178
static void SetRaisedCallback(LogRaisedCb newCb)
Definition Log.cpp:28
Definition Anchor.h:6
void(* LogOutputCb)(const Array< Log > &)
Definition Log.h:15
unsigned char UInt_8
Definition Types.h:43
Str< Char_8, UInt_64 > Str_8
Definition Str.h:1953
void(* LogRaisedCb)(const Log &)
Definition Log.h:14
LogType
Definition Log.h:18
@ WARN
Definition Log.h:21
@ INFO
Definition Log.h:22
@ ERR
Definition Log.h:20
@ SUCCESS
Definition Log.h:19