source: opengl-game/logger.cpp@ bae0911

feature/imgui-sdl points-test
Last change on this file since bae0911 was bae0911, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Update logging code to send all errors to the log file as well as the console

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include "logger.h"
2
3#include <cstdio>
4#include <ctime>
5#include <cstdarg>
6#include <iostream>
7
8bool restart_gl_log() {
9 FILE* file = fopen(GL_LOG_FILE, "w");
10 if (!file) {
11 cerr << "ERROR: could not open GL_LOG_FILE log file " << GL_LOG_FILE << " for writing" << endl;
12 return false;
13 }
14 time_t now = time(NULL);
15 string date(ctime(&now));
16 fprintf(file, "GL_LOG_FILE log. local time %s\n", date.c_str());
17 fclose(file);
18 return true;
19}
20
21bool gl_log(const string message, ...) {
22 va_list argptr;
23 FILE* file = fopen(GL_LOG_FILE, "a");
24 if (!file) {
25 cerr << "ERROR: could not open GL_LOG_FILE log file " << GL_LOG_FILE << " for appending" << endl;
26 return false;
27 }
28 va_start(argptr, message.c_str());
29 vfprintf(file, message.c_str(), argptr);
30 va_end(argptr);
31 fprintf(file, "\n");
32 fclose(file);
33 return true;
34}
35
36bool gl_log_err(const string message, ...) {
37 va_list argptr;
38 FILE* file = fopen(GL_LOG_FILE, "a");
39 if (!file) {
40 cerr << "ERROR: could not open GL_LOG_FILE log file " << GL_LOG_FILE << " for appending" << endl;
41 return false;
42 }
43 va_start(argptr, message.c_str());
44 vfprintf(file, message.c_str(), argptr);
45 va_end(argptr);
46 fprintf(file, "\n");
47 va_start(argptr, message.c_str());
48 vfprintf(stderr, message.c_str(), argptr);
49 va_end(argptr);
50 fprintf(stderr, "\n");
51 fclose(file);
52 return true;
53}
Note: See TracBrowser for help on using the repository browser.