Skip to content

Commit 8ab7f9e

Browse files
committed
Log Class in cpp in Cherno's lesson
1 parent 00ab314 commit 8ab7f9e

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎cpp/Log/Log.hpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
class Log
3+
{
4+
public:
5+
enum Level
6+
{
7+
LevelERROR = 0,
8+
LevelWARNING,
9+
LevelINFO
10+
};
11+
12+
public:
13+
Level m_LogLevel = LevelINFO;
14+
15+
public:
16+
void SetLevel(Level level)
17+
{
18+
m_LogLevel = level;
19+
};
20+
void Error(const char *message)
21+
{
22+
if (m_LogLevel >= LevelERROR)
23+
std::cout << "[ERROR]: " << message << std::endl;
24+
};
25+
void Warn(const char *message)
26+
{
27+
if (m_LogLevel >= LevelWARNING)
28+
std::cout << "[WARNING]: " << message << std::endl;
29+
};
30+
void Info(const char *message)
31+
{
32+
if (m_LogLevel >= LevelINFO)
33+
std::cout << "[INFO]: " << message << std::endl;
34+
};
35+
};

‎cpp/Log/test.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "Log.hpp"
2+
3+
int main()
4+
{
5+
Log log;
6+
log.SetLevel(Log::LevelERROR);
7+
log.Error("ERROR");
8+
log.Warn("WARNING");
9+
log.Info("INFO");
10+
log.SetLevel(Log::LevelWARNING);
11+
log.Error("ERROR");
12+
log.Warn("WARNING");
13+
log.Info("INFO");
14+
log.SetLevel(Log::LevelINFO);
15+
log.Error("ERROR");
16+
log.Warn("WARNING");
17+
log.Info("INFO");
18+
}

0 commit comments

Comments
 (0)