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-12-14 13:01:42 -06:00
|
|
|
#include <unistd.h>
|
2022-12-19 12:16:51 -06:00
|
|
|
#include <stdio.h>
|
2023-09-25 12:29:04 -05:00
|
|
|
#include "yugine.h"
|
2024-03-14 09:33:15 -05:00
|
|
|
#include "resources.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-04-28 20:55:24 -05:00
|
|
|
#include "script.h"
|
|
|
|
|
2024-03-14 09:33:15 -05:00
|
|
|
char *logstr[] = { "spam", "debug", "info", "warn", "error", "panic"};
|
2023-05-27 10:13:20 -05:00
|
|
|
char *catstr[] = {"engine", "script", "render"};
|
2022-12-14 13:01:42 -06:00
|
|
|
|
2024-03-14 09:33:15 -05:00
|
|
|
static FILE *logout; /* where logs are written to */
|
|
|
|
static FILE *writeout; /* where console is written to */
|
2023-10-26 11:48:02 -05:00
|
|
|
|
2023-09-13 07:31:00 -05:00
|
|
|
void log_init()
|
|
|
|
{
|
2024-03-14 09:33:15 -05:00
|
|
|
#ifndef NDEBUG
|
|
|
|
logout = fopen(".prosperon/log.txt", "w");
|
|
|
|
writeout = fopen(".prosperon/transcript.txt", "w");
|
|
|
|
#endif
|
2023-09-13 07:31:00 -05:00
|
|
|
}
|
2022-12-19 12:16:51 -06:00
|
|
|
|
2024-03-14 09:33:15 -05:00
|
|
|
void log_shutdown()
|
2021-11-30 21:29:18 -06:00
|
|
|
{
|
2024-03-14 09:33:15 -05:00
|
|
|
fclose(logout);
|
|
|
|
fclose(writeout);
|
2023-04-24 17:22:18 -05:00
|
|
|
}
|
2022-12-15 17:30:22 -06:00
|
|
|
|
2024-03-14 09:33:15 -05:00
|
|
|
const char *logfmt = "%s:%d: [%s] %s, %s: ";
|
|
|
|
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
2023-04-24 17:22:18 -05:00
|
|
|
{
|
2023-10-16 09:40:43 -05:00
|
|
|
#ifndef NDEBUG
|
2024-03-14 09:33:15 -05:00
|
|
|
time_t now = time(NULL);
|
|
|
|
struct tm *tinfo = localtime(&now);
|
|
|
|
char timebuf[80];
|
|
|
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tinfo);
|
|
|
|
|
|
|
|
fprintf(logout, logfmt, file, line, timebuf, logstr[priority], catstr[category]);
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, message);
|
|
|
|
vfprintf(logout, message, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(logout, "\n");
|
|
|
|
|
|
|
|
if (priority == LOG_DEBUG) {
|
|
|
|
printf(logfmt, file, line, timebuf, logstr[priority], catstr[category]);
|
|
|
|
va_list args;
|
|
|
|
va_start(args,message);
|
|
|
|
vprintf(message, args);
|
|
|
|
va_end(args);
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
2023-04-24 17:22:18 -05:00
|
|
|
}
|
2023-10-16 09:40:43 -05:00
|
|
|
#endif
|
2023-10-09 18:10:10 -05:00
|
|
|
}
|
2022-12-15 17:30:22 -06:00
|
|
|
|
2024-03-14 09:33:15 -05:00
|
|
|
/* print to stdout and console */
|
|
|
|
void log_print(const char *str)
|
2023-10-09 18:10:10 -05:00
|
|
|
{
|
2023-10-16 09:40:43 -05:00
|
|
|
#ifndef NDEBUG
|
2024-03-14 09:33:15 -05:00
|
|
|
fprintf(writeout, str);
|
2023-10-16 09:40:43 -05:00
|
|
|
#endif
|
2024-03-14 09:33:15 -05:00
|
|
|
printf(str);
|
|
|
|
fflush(stdout);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
2023-09-02 06:53:52 -05:00
|
|
|
|
|
|
|
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {
|
2024-03-14 09:33:15 -05:00
|
|
|
lvl = LOG_PANIC-lvl;
|
|
|
|
mYughLog(LOG_RENDER, lvl, line, file, "tag: %s, id: %d, msg: %s", tag, id, msg);
|
2023-09-02 06:53:52 -05:00
|
|
|
}
|