-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
43 lines (33 loc) · 1.01 KB
/
log.cpp
File metadata and controls
43 lines (33 loc) · 1.01 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
#include <iostream>
class Log
{
public: // fields/variables
enum Level {
LevelError = 0, LevelWarning, LevelInfo // 'LevelError' and not just 'Error' because their is also a function in this namespace with the name 'Error'
};
private:
Level m_LogLevel = LevelInfo; // m stands for class private members
public: // methods
void SetLevel(Level level)
{
m_LogLevel = level;
}
// Level = Error --> shows only error
// Level = Warning --> shows errors and warnings
// Level = Info --> shows errors, warnings, and info
void Error(const char* message)
{
if (m_LogLevel >= LevelError)
std::cout << "[ERROR]: " << message << std::endl;
}
void Warn(const char* message)
{
if (m_LogLevel >= LevelWarning)
std::cout << "[WARNING]: " << message << std::endl;
}
void Info(const char* message)
{
if (m_LogLevel >= LevelInfo)
std::cout << "[INFO]: " << message << std::endl;
}
};