[1fcca9e] | 1 | #include "logger.hpp"
|
---|
[22b2c37] | 2 |
|
---|
| 3 | #include <cstdio>
|
---|
| 4 | #include <ctime>
|
---|
| 5 | #include <cstdarg>
|
---|
[155a7cf] | 6 | #include <iostream>
|
---|
| 7 |
|
---|
[22b2c37] | 8 | bool restart_gl_log() {
|
---|
| 9 | FILE* file = fopen(GL_LOG_FILE, "w");
|
---|
| 10 | if (!file) {
|
---|
[155a7cf] | 11 | cerr << "ERROR: could not open GL_LOG_FILE log file " << GL_LOG_FILE << " for writing" << endl;
|
---|
[22b2c37] | 12 | return false;
|
---|
| 13 | }
|
---|
| 14 | time_t now = time(NULL);
|
---|
[bae0911] | 15 | string date(ctime(&now));
|
---|
| 16 | fprintf(file, "GL_LOG_FILE log. local time %s\n", date.c_str());
|
---|
[22b2c37] | 17 | fclose(file);
|
---|
| 18 | return true;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[bae0911] | 21 | bool gl_log(const string message, ...) {
|
---|
[22b2c37] | 22 | va_list argptr;
|
---|
| 23 | FILE* file = fopen(GL_LOG_FILE, "a");
|
---|
| 24 | if (!file) {
|
---|
[155a7cf] | 25 | cerr << "ERROR: could not open GL_LOG_FILE log file " << GL_LOG_FILE << " for appending" << endl;
|
---|
[22b2c37] | 26 | return false;
|
---|
| 27 | }
|
---|
[caa2359] | 28 | va_start(argptr, message);
|
---|
[bae0911] | 29 | vfprintf(file, message.c_str(), argptr);
|
---|
[22b2c37] | 30 | va_end(argptr);
|
---|
| 31 | fprintf(file, "\n");
|
---|
| 32 | fclose(file);
|
---|
| 33 | return true;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[bae0911] | 36 | bool gl_log_err(const string message, ...) {
|
---|
[22b2c37] | 37 | va_list argptr;
|
---|
| 38 | FILE* file = fopen(GL_LOG_FILE, "a");
|
---|
| 39 | if (!file) {
|
---|
[155a7cf] | 40 | cerr << "ERROR: could not open GL_LOG_FILE log file " << GL_LOG_FILE << " for appending" << endl;
|
---|
[22b2c37] | 41 | return false;
|
---|
| 42 | }
|
---|
[caa2359] | 43 | va_start(argptr, message);
|
---|
[bae0911] | 44 | vfprintf(file, message.c_str(), argptr);
|
---|
[22b2c37] | 45 | va_end(argptr);
|
---|
| 46 | fprintf(file, "\n");
|
---|
[caa2359] | 47 | va_start(argptr, message);
|
---|
[bae0911] | 48 | vfprintf(stderr, message.c_str(), argptr);
|
---|
[22b2c37] | 49 | va_end(argptr);
|
---|
| 50 | fprintf(stderr, "\n");
|
---|
| 51 | fclose(file);
|
---|
| 52 | return true;
|
---|
| 53 | }
|
---|
[98f06d9] | 54 |
|
---|
| 55 | ofstream ofs;
|
---|
| 56 |
|
---|
| 57 | void open_log() {
|
---|
| 58 | ofs.open(LOG_FILE, ios::out);
|
---|
| 59 |
|
---|
| 60 | time_t now = time(NULL);
|
---|
| 61 | string date(ctime(&now));
|
---|
| 62 | ofs << "LOG_FILE log. local time " << date << endl;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | ofstream& get_log() {
|
---|
| 66 | return ofs;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | void close_log() {
|
---|
| 70 | ofs.close();
|
---|
| 71 | }
|
---|