-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cpp
41 lines (37 loc) · 970 Bytes
/
Logger.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
#include "Logger.h"
#include <ctime>
void Logger::log(unsigned char where, const std::string &msg) const
{
if (where & LOG_FILE)
{
fwrite(msg.c_str(), msg.size(), 1, file);
fflush(file);
}
if (where & LOG_USER) //TODO: implement pop-up box or similar for log() 7
{
std::cerr << msg;
}
}
Logger::Logger()
{
file = file_open(LOG_FILE_NAME, "a+");
log(LOG_FILE, "Beginning program...\nStart time: ");
std::time_t now = std::time(0);
char str[60];
std::time_t time;
std::time(&time);
std::strftime(str, 60, "%H:%M:%S on %m/%d/%Y", std::localtime(&time));
logln(LOG_FILE, str);
}
Logger::~Logger()
{
log(LOG_FILE, "End time: ");
std::time_t now = std::time(0);
char str[60];
std::time_t time;
std::time(&time);
std::strftime(str, 60, "%H:%M:%S on %m/%d/%Y", std::localtime(&time));
logln(LOG_FILE, str);
logln(LOG_FILE, "Program quit\n");
fclose(file);
}