-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogger.cpp
More file actions
61 lines (53 loc) · 1.1 KB
/
Logger.cpp
File metadata and controls
61 lines (53 loc) · 1.1 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "PJLib.h"
namespace PJLib
{
/* Singleton Implementation */
Logger* Logger::_instance = 0;
Logger* Logger::Instance()
{
if (_instance == 0)
{
_instance = new Logger();
}
return _instance;
}
Logger::Logger()
{
}
void Logger::SetFilePath(string filePath)
{
this->filePath = filePath;
this->logFileStream.open(filePath + "\\log.txt");
/* Open filestream */
if(logFileStream.is_open())
{
this->logFileStream << "<pre>//------------------------- Log -------------------------//" << endl;
}
else
{
try
{
boost::filesystem::create_directory(filePath);
}
catch(...)
{
throw exception("Could not create directory for the log file!");
}
}
}
void Logger::Append(string logMessage)
{
if(this->filePath.empty())
{
cout << logMessage << endl;
}
else
{
time(&this->rawTime);
string timeString = ctime(&this->rawTime);
this->logFileStream << timeString.substr(0,timeString.length()-1) << " - " << logMessage << endl;
/* Emit a signal so that observers know an entry has been added to the log */
this->entryAddedSignal();
}
}
}