EHS
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 {
19 SUCCESS,
20 ERR,
21 WARN,
22 INFO
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
Definition: Anchor.h:6
void(* LogOutputCb)(const Array< Log > &)
Definition: Log.h:15
unsigned char UInt_8
Definition: Types.h:43
void(* LogRaisedCb)(const Log &)
Definition: Log.h:14
LogType
Definition: Log.h:18