File tree Expand file tree Collapse file tree 1 file changed +29
-19
lines changed Expand file tree Collapse file tree 1 file changed +29
-19
lines changed Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
3
- #define LOG (x ) std::cout << x << std::endl
4
-
5
- class Player
3
+ class Log
6
4
{
7
5
public:
8
- int x, y;
9
- int speed;
6
+ const int LogLevelError = 0 ;
7
+ const int LogLevelWarning = 1 ;
8
+ const int LogLevelInfo = 2 ;
9
+
10
+ private:
11
+ int m_LogLevel = LogLevelInfo;
10
12
11
- void Move (int xa, int ya)
13
+ public:
14
+ void SetLevel (int level)
12
15
{
13
- x += xa * speed;
14
- y += ya * speed;
16
+ m_LogLevel = level;
15
17
}
16
- };
17
18
18
- struct Vec2
19
- {
20
- float x, y;
19
+ void Error (const char * message)
20
+ {
21
+ if (m_LogLevel >= LogLevelError)
22
+ std::cout << " [ERROR]:" << message << std::endl;
23
+ }
21
24
22
- void Add (const Vec2& other )
25
+ void Warn (const char * message )
23
26
{
24
- x += other.x ;
25
- y += other.y ;
27
+ if (m_LogLevel >= LogLevelWarning)
28
+ std::cout << " [WARNING]:" << message << std::endl;
29
+ }
30
+
31
+ void Info (const char * message)
32
+ {
33
+ if (m_LogLevel >= LogLevelInfo)
34
+ std::cout << " [INFO]:" << message << std::endl;
26
35
}
27
36
};
28
37
29
38
int main ()
30
39
{
31
- Player player;
32
- player.x = 5 ;
33
- player.Move (1 , -1 );
34
-
40
+ Log log;
41
+ log.SetLevel (log.LogLevelError );
42
+ log.Warn (" Hello!" );
43
+ log.Error (" Hello!" );
44
+ log.Info (" Hello!" );
35
45
std::cin.get ();
36
46
}
You can’t perform that action at this time.
0 commit comments