source: opengl-game/logger.cpp@ 7c929fc

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

Rename logger.h to logger.hpp

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include "logger.hpp"
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);
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);
44 vfprintf(file, message.c_str(), argptr);
45 va_end(argptr);
46 fprintf(file, "\n");
47 va_start(argptr, message);
48 vfprintf(stderr, message.c_str(), argptr);
49 va_end(argptr);
50 fprintf(stderr, "\n");
51 fclose(file);
52 return true;
53}
54
55ofstream ofs;
56
57void 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
65ofstream& get_log() {
66 return ofs;
67}
68
69void close_log() {
70 ofs.close();
71}
Note: See TracBrowser for help on using the repository browser.