refactoring the log-writing to its own method
@@ -7,24 +7,12 @@ getColorComponents(uint32_t color, uint8_t *r, uint8_t *g, uint8_t *b) {
internal void
ENGINE_openLogFile(ENGINE* engine) {
- // DOME-2020-02-02-090000.log
char* filename = "DOME-out.log";
engine->debug.logFile = fopen(filename, "w+");
}
internal void
-ENGINE_printLogVariadic(ENGINE* engine, const char* line, va_list argList) {
- va_list args;
- va_copy(args, argList);
- size_t bufSize = vsnprintf(NULL, 0, line, args) + 1;
- va_end(args);
-
- char buffer[bufSize];
- buffer[0] = '\0';
- va_copy(args, argList);
- vsnprintf(buffer, bufSize, line, args);
- va_end(args);
-
+ENGINE_writeToLog(ENGINE* engine, const char* buffer) {
// Output to console
printf("%s", buffer);
@@ -38,6 +26,22 @@ ENGINE_printLogVariadic(ENGINE* engine, const char* line, va_list argList) {
}
}
+internal void
+ENGINE_printLogVariadic(ENGINE* engine, const char* line, va_list argList) {
+ va_list args;
+ va_copy(args, argList);
+ size_t bufSize = vsnprintf(NULL, 0, line, args) + 1;
+ va_end(args);
+
+ char buffer[bufSize];
+ buffer[0] = '\0';
+ va_copy(args, argList);
+ vsnprintf(buffer, bufSize, line, args);
+ va_end(args);
+ ENGINE_writeToLog(engine, buffer);
+}
+
+
internal void
ENGINE_printLog(ENGINE* engine, char* line, ...) {
// Args is mutated by each vsnprintf call,
@@ -1180,7 +1184,7 @@ ENGINE_reportErrorVariadic(ENGINE* engine, const char* line, va_list argList) {
vsnprintf(buffer, bufSize, line, args);
va_end(args);
- ENGINE_printLog(engine, buffer);
+ ENGINE_writeToLog(engine, buffer);
if (engine->debug.errorDialog) {
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"DOME - Error",
