Repository navigation
Expand file tree
/
Copy pathRecoLogMgr.cpp
More file actions
86 lines (75 loc) · 1.94 KB
/
Copy pathRecoLogMgr.cpp
File metadata and controls
86 lines (75 loc) · 1.94 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//LogWriter.cpp : Creates a LogWriter object that prints to a log file
//Code by Brennan McTernan
//4/23/14
#include "RecoLogMgr.h"
#include <time.h>
#include <iostream>
#include <sstream> // for ostringstream
using namespace std;
CRecoLogMgr* CRecoLogMgr::_pInstance = NULL;
CRecoLogMgr* CRecoLogMgr::Instance()
{
if(!_pInstance)
{
_pInstance = new CRecoLogMgr;
}
return _pInstance;
}
bool CRecoLogMgr::Init(string strBasePath, string strLogName)
{
//Constructor - Initializes LogWriter
//Input - a string containing the filepath
//Output - none
//set filepath to be fileLoc
ostringstream ostrFilePath;
time_t now = time(NULL);
//commented to make a final log
//ostrFilePath << strBasePath << "\\" << LOGFOLDERNAME << "\\" << strLogName << "_" << now << ".txt";
ostrFilePath << strBasePath << "\\" << LOGFOLDERNAME << "\\" << strLogName <<".txt";
try
{
_logFile.open(ostrFilePath.str(), fstream::out | fstream::app);
}
catch ( const exception & ex )
{
std::cerr << "Could not open file - reason is "
<< ex.what();
return false;
}
return true;
}
CRecoLogMgr::~CRecoLogMgr()
{
//Destructor - closes the current log file
//Input: none
//Output: none
if(_logFile.is_open())
{
_logFile.close();
}
//Close log file
}
void CRecoLogMgr::WriteLog(string sizeString)
{
//WriteLog - Writes a line of text to the log.txt file containing: current timestamp followed by a string
//Input: sizeString - a string containing text
//Output: none
std::string outString = TimeStamp();
outString += " " + sizeString;
_logFile << outString << endl;
_logFile.flush();
}
std::string CRecoLogMgr::TimeStamp()
{
//TimeStamp - returns a current localized timestamp string
//Input: none
//Output: String containing the current localized time
struct tm now;
time_t time;
_time64(&time);
char out[100];
localtime_s(&now,&time);
asctime_s(out,100,&now);
out[strnlen_s(out,100)-1] = '\0'; //Trim off newline
return string(out);
}