-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNMF_Logging.h
98 lines (81 loc) · 2.57 KB
/
NMF_Logging.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#ifndef NMF_VERSION
#include "NMF.h"
#endif
#ifdef NMF_USE_LOGGING
#include <iostream>
#include <stdint.h>
#include <vector>
namespace NMF
{
enum class LogDestination : uint8_t
{
None = 0,
File = 1,
Console = 2,
GUIConsole = 4
};
enum class LogSeverity : uint32_t
{
Info,
Warning,
Debug,
VerboseDebug,
Error
};
enum class LogFilter : uint32_t
{
None = 0,
Info = (1 << static_cast<int>(LogSeverity::Info)),
Warning = (1 << static_cast<int>(LogSeverity::Warning)),
Debug = (1 << static_cast<int>(LogSeverity::Debug)),
VerboseDebug = (1 << static_cast<int>(LogSeverity::VerboseDebug)),
Error = (1 << static_cast<int>(LogSeverity::Error)),
All = Info | Warning | Debug | Error,
AllVerbose = All | VerboseDebug
};
constexpr LogDestination operator|(LogDestination lhs, LogDestination rhs)
{
return static_cast<LogDestination>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
}
constexpr LogDestination operator&(LogDestination lhs, LogDestination rhs)
{
return static_cast<LogDestination>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
}
constexpr LogFilter operator<<(int lhs, LogSeverity rhs)
{
return static_cast<LogFilter>(lhs << static_cast<int>(rhs));
}
constexpr LogFilter operator|(LogFilter lhs, LogFilter rhs)
{
return static_cast<LogFilter>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
}
constexpr LogFilter operator&(LogFilter lhs, LogFilter rhs)
{
return static_cast<LogFilter>(static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs));
}
class NMF_EXTENDED_EXPORT Logger final
{
public:
Logger(std::initializer_list<const char*> l);
void AddScope(const char* scope);
void RemoveLastScope();
void Log(LogSeverity severity, const char* fmt, ...) const;
private:
#pragma warning(disable: 4251)
std::vector<const char*> Scopes;
#pragma warning(default: 4251)
};
class NMF_EXPORT LogManager final
{
static LogDestination Destination;
static LogFilter SeverityFilter;
static std::ofstream* OutFileStream;
static Logger LogManagerLogger;
public:
static void Setup(LogDestination destination, LogFilter filter);
static void Teardown();
static void Log(LogSeverity severity, const char* fmt, ...);
};
}
#endif