Improve logging output

This commit is contained in:
Piotr Krygier committed 2023-09-26 14:15:21 +02:00
1 parent 7ca73f3c60
commit 3a58bd8756
3 files changed
+6 -5

No files matched your search

+3 -2
View File
@@ -17,9 +17,10 @@
#endif
#include <stdio.h>
#include <string.h>
#define LOGGER(log_level, ...) _log_log(log_level, __FILE__, __LINE__, __VA_ARGS__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define LOGGER(log_level, ...) _log_log(log_level, __FILENAME__, __LINE__, __VA_ARGS__)
// #define LOGGER(log_level, ...) printf("[##log_level] %s:%d", __FILE__, __LINE__); printf(__VA_ARGS__)
#define LOGT(...) LOGGER(LOGLEVEL_TRACE, __VA_ARGS__)
+2 -2
View File
@@ -2,7 +2,7 @@
#include "stdarg.h"
const char* log_levels[] = {
"LOGLEVEL_TRACE", "LOGLEVEL_DEBUG", "LOGLEVEL_INFO", "LOGLEVEL_WARNING", "LOGLEVEL_ERROR", "LOGLEVEL_FATAL"
"[TRACE]", "[DEBUG]", "[INFO]", "WARNING", "[ERROR]", "[FATAL]"
};
void _log_log(unsigned int level, const char* file, int line, const char* fmt, ...)
@@ -11,7 +11,7 @@ void _log_log(unsigned int level, const char* file, int line, const char* fmt, .
va_list list;
va_start(list, fmt);
fprintf(stdout, "%s %s:%d ", log_levels[level], file, line);
fprintf(stdout, "%s %s:%d: ", log_levels[level], file, line);
vfprintf(stdout, fmt, list);
fprintf(stdout, "\n");
fflush(stdout);