/
Logger.h
52 lines (41 loc) · 814 Bytes
/
Logger.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
#pragma once
#pragma warning(disable : 4996)
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <chrono>
#include <thread>
#include <time.h>
enum class LogSeverity{
error,
warning,
info,
debug
};
enum class LogOutput{
console,
file,
everywhere
};
class Logger{
public:
// Constructor & Destructor
Logger();
~Logger();
void init(const std::string& filename, const LogOutput output = LogOutput::everywhere);
void open();
void close();
void flush();
void log(const std::string& msg, const LogSeverity severity);
private:
static std::string timestamp();
static std::string threadId();
std::string m_filename;
std::fstream m_file;
LogOutput m_output = LogOutput::everywhere;
bool m_isOpened = false;
};