mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-19 06:25:45 +01:00
We were statically creating a new string per log message, so re-using the same message would cause duplicate byte sizes. Now, all prefixes / suffixes are only defined once, the file name is defined once per file, the line number should be defined once per unique line. This just saves some memory in the final binary, allowing things to be optimised a little better.
52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#include "error.h"
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
|
|
#include "util/intdef.h"
|
|
|
|
static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap) {
|
|
fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx);
|
|
|
|
vfprintf(stream, fmt, ap);
|
|
|
|
fprintf(stream, "'\n");
|
|
}
|
|
|
|
void error_dbg(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
error_log(stdout, "\033[95mDBG\033[0m", ln, file, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
void error_inf(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
error_log(stdout, "\033[93mINF\033[0m", ln, file, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
void error_war(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
error_log(stdout, "\033[91mWAR\033[0m", ln, file, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
void error_err(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
error_log(stdout, "\033[mFAT\033[0m", ln, file, fmt, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
void error_fat(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
error_log(stdout, "\033[mFAT\033[0m", ln, file, fmt, ap);
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
}
|