2021-11-30 21:29:18 -06:00
|
|
|
#include "log.h"
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#include "render.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-07-02 03:40:50 -05:00
|
|
|
#define logLevel 0
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-11-17 16:48:20 -06:00
|
|
|
//char *logstr[] = { "INFO", "WARN", "\x1b[1;31mERROR\x1b[0m", "CRITICAL" };
|
|
|
|
char *logstr[] = { "INFO", "WARN", "ERROR", "CRITICAL" };
|
|
|
|
char *catstr[] = {"ENGINE"};
|
|
|
|
|
2022-11-24 01:54:17 -06:00
|
|
|
FILE *fout = NULL;
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
2021-11-30 21:29:18 -06:00
|
|
|
{
|
|
|
|
if (priority >= logLevel) {
|
|
|
|
time_t now = time(0);
|
|
|
|
char *dt = ctime(&now);
|
|
|
|
dt[strlen(dt) - 1] = '\0'; // The above time conversion adds a \n; this removes it
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, message);
|
|
|
|
char msgbuffer[ERROR_BUFFER] = { '\0' };
|
|
|
|
vsnprintf(msgbuffer, ERROR_BUFFER, message, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
char buffer[ERROR_BUFFER] = { '\0' };
|
2022-11-17 16:48:20 -06:00
|
|
|
snprintf(buffer, ERROR_BUFFER, "%s | %s | %s [ %s:%d ] %s\n", logstr[priority], catstr[0], dt, file, line, msgbuffer);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
printf("%s", buffer);
|
2022-11-24 01:54:17 -06:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
if (fout) {
|
|
|
|
fprintf(fout, "%s", buffer);
|
|
|
|
fflush(fout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_setfile(char *file) {
|
|
|
|
YughInfo("Opening output log %s.", file);
|
|
|
|
fout = fopen(file, "w");
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_cat(FILE *f) {
|
|
|
|
char out[1024];
|
|
|
|
|
|
|
|
while (fgets(out, sizeof(out), f)) {
|
|
|
|
out[strcspn(out, "\n")] = '\0';
|
|
|
|
YughInfo(out);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlushGLErrors()
|
|
|
|
{
|
|
|
|
GLenum glErr = GL_NO_ERROR;
|
|
|
|
glErr = glGetError();
|
|
|
|
while (glErr != GL_NO_ERROR) {
|
2022-02-06 10:14:57 -06:00
|
|
|
YughLog(0, 3,
|
2021-11-30 21:29:18 -06:00
|
|
|
"GL Error: %d", glErr);
|
|
|
|
glErr = glGetError();
|
|
|
|
}
|
|
|
|
}
|