Changeset bae0911 in opengl-game for logger.cpp


Ignore:
Timestamp:
May 10, 2019, 9:09:49 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
caa2359
Parents:
155a7cf
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • logger.cpp

    r155a7cf rbae0911  
    55#include <cstdarg>
    66#include <iostream>
    7 
    8 using namespace std;
    97
    108bool restart_gl_log() {
     
    1513   }
    1614   time_t now = time(NULL);
    17    char* date = ctime(&now);
    18    fprintf(file, "GL_LOG_FILE log. local time %s\n", date);
     15   string date(ctime(&now));
     16   fprintf(file, "GL_LOG_FILE log. local time %s\n", date.c_str());
    1917   fclose(file);
    2018   return true;
    2119}
    2220
    23 bool gl_log(const char* message, ...) {
     21bool gl_log(const string message, ...) {
    2422   va_list argptr;
    2523   FILE* file = fopen(GL_LOG_FILE, "a");
     
    2826      return false;
    2927   }
    30    va_start(argptr, message);
    31    vfprintf(file, message, argptr);
     28   va_start(argptr, message.c_str());
     29   vfprintf(file, message.c_str(), argptr);
    3230   va_end(argptr);
    3331   fprintf(file, "\n");
     
    3634}
    3735
    38 bool gl_log_err(const char* message, ...) {
     36bool gl_log_err(const string message, ...) {
    3937   va_list argptr;
    4038   FILE* file = fopen(GL_LOG_FILE, "a");
     
    4341      return false;
    4442   }
    45    va_start(argptr, message);
    46    vfprintf(file, message, argptr);
     43   va_start(argptr, message.c_str());
     44   vfprintf(file, message.c_str(), argptr);
    4745   va_end(argptr);
    4846   fprintf(file, "\n");
    49    va_start(argptr, message);
    50    vfprintf(stderr, message, argptr);
     47   va_start(argptr, message.c_str());
     48   vfprintf(stderr, message.c_str(), argptr);
    5149   va_end(argptr);
    5250   fprintf(stderr, "\n");
Note: See TracChangeset for help on using the changeset viewer.