-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.cpp
50 lines (41 loc) · 1.04 KB
/
Log.cpp
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
#include "Log.h"
#include <boost/circular_buffer.hpp>
#include <iostream>
#include <fstream>
using namespace std;
const int LOG_LENGTH = 256;
const std::string LOG_FILE = "log.txt";
Log::Log()
{
m_cbLog.set_capacity(LOG_LENGTH);
m_bStdOut = false;
m_LogFile.open(LOG_FILE, ios_base::trunc);
ios::sync_with_stdio(false);
}
Log::~Log()
{
}
void Log::write(const std::string& s, Log::Message::eLoggingLevel lev)
{
m_cbLog.push_back(Message(s,lev));
if(m_bStdOut)
{
if(lev == Message::LL_WARNING)
cout << "[WARNING] ";
else if(lev == Message::LL_ERROR)
cout << "[ERROR] ";
else if(lev == Message::LL_DEBUG)
cout << "[DEBUG] ";
cout << s << endl;
}
if(m_LogFile.is_open())
{
if(lev == Message::LL_WARNING)
m_LogFile << "[WARNING] ";
else if(lev == Message::LL_ERROR)
m_LogFile << "[ERROR] ";
else if(lev == Message::LL_DEBUG)
m_LogFile << "[DEBUG] ";
m_LogFile << s << endl;
}
}