Files
xkhofmann-tfdidesign-md11-l…/PackageSources/wasm-module/src/log.cpp
T
Kilian f0efa84610 Fix log
Defuling enabled
2026-08-27 22:00:44 +02:00

49 lines
1.3 KiB
C++

#include "log.h"
void toLog(FILE *file, const char *format, double *optional) {
static FILE *logFile;
static bool logFileFailed = false;
if (logFile == NULL) {
logFile = fopen("\\work\\log.txt", "w");
if (logFile == NULL) {
logFileFailed = true;
toLog(stderr, "Error creating logfile.\n");
} else {
toLog(stdout, "Logfile created.\n");
}
}
if (!logFileFailed) {
time_t rawtime;
time(&rawtime);
char *_new = (char *)calloc(strlen(format) + 24 + 1, sizeof(char));
if (_new == NULL) {
fprintf(stderr, MODULE_NAME "Failed to allocate string for toLog.\n");
return;
}
strftime(_new, 24, "%FT%TZ | ", gmtime(&rawtime));
strncat(_new, format, strlen(format));
if (optional != nullptr) fprintf(logFile, _new, *optional);
else
fprintf(logFile, _new);
fflush(logFile);
free(_new);
}
char *_new = (char *)calloc(strlen(format) + strlen(MODULE_NAME) + 1, sizeof(char));
if (_new == NULL) {
fprintf(stderr, MODULE_NAME "Failed to allocate string for internal console.\n");
return;
}
strncpy(_new, MODULE_NAME, strlen(MODULE_NAME));
strncat(_new, format, strlen(format));
if (optional != nullptr) fprintf(file, _new, *optional);
else
fprintf(file, _new);
free(_new);
}