1.1.26+ FS24 adjustments
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#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\\toLog.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);
|
||||
}
|
||||
Reference in New Issue
Block a user