-
-
Notifications
You must be signed in to change notification settings - Fork 454
Expand file tree
/
Copy pathLogging.cpp
More file actions
77 lines (58 loc) · 1.61 KB
/
Logging.cpp
File metadata and controls
77 lines (58 loc) · 1.61 KB
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
#include "Logging.hpp"
#include <string>
namespace libprojectM {
Logging::UserCallback Logging::m_globalCallback = {};
thread_local Logging::UserCallback Logging::m_threadCallback = {};
Logging::LogLevel Logging::m_globalLogLevel = LogLevel::NotSet;
thread_local Logging::LogLevel Logging::m_threadLogLevel = LogLevel::NotSet;
const Logging::LogLevel Logging::m_defaultLogLevel = LogLevel::Information;
void Logging::SetGlobalCallback(const UserCallback callback)
{
m_globalCallback = callback;
}
void Logging::SetThreadCallback(const UserCallback callback)
{
m_threadCallback = callback;
}
void Logging::SetGlobalLogLevel(const LogLevel logLevel)
{
m_globalLogLevel = logLevel;
}
void Logging::SetThreadLogLevel(const LogLevel logLevel)
{
m_threadLogLevel = logLevel;
}
auto Logging::GetLogLevel() -> LogLevel
{
if (m_threadLogLevel != LogLevel::NotSet)
{
return m_threadLogLevel;
}
if (m_globalLogLevel != LogLevel::NotSet)
{
return m_globalLogLevel;
}
return m_defaultLogLevel;
}
auto Logging::HasCallback() -> bool
{
return GetLoggingCallback().callbackFunction != nullptr;
}
void Logging::Log(const std::string& message, LogLevel severity)
{
auto callback = GetLoggingCallback();
if (callback.callbackFunction == nullptr)
{
return;
}
callback.callbackFunction(message.c_str(), static_cast<int>(severity), callback.userData);
}
auto Logging::GetLoggingCallback() -> UserCallback
{
if (m_threadCallback.callbackFunction != nullptr)
{
return m_threadCallback;
}
return m_globalCallback;
}
} // namespace libprojectM