source: opengl-game/logger.cpp@ 9d22ee9

feature/imgui-sdl points-test
Last change on this file since 9d22ee9 was 22b2c37, checked in by Dmitry Portnoy <dmp1488@…>, 7 years ago

Add a simple logger and remove some old, unneeded tutorial files

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