-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.cpp
45 lines (35 loc) · 823 Bytes
/
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
#include "prelude.h"
#include <cstdlib>
using std::atexit;
#include <ctime>
#include <fstream>
using std::ofstream;
using std::endl;
namespace {
ofstream error_log_stream;
void on_exit()
{
error_log_stream << "Ending error logging at " << endl;
std::time_t time_var = std::time(NULL);
error_log_stream << std::ctime(&time_var) << endl;
error_log_stream.close();
}
}
void logInit()
{
error_log_stream.open("error_log.txt", std::ios_base::app | std::ios_base::out);
error_log_stream << "Begining error logging at " << endl;
std::time_t time_var = std::time(NULL);
error_log_stream << std::ctime(&time_var);// << endl;
atexit(on_exit);
}
// exposes the error log for writing
std::ostream& err()
{
static bool first = true;
if (first) {
logInit();
first = false;
}
return error_log_stream;
}