From bc88a30c0c532312290eff6fc7772228d1f45270 Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Sat, 14 Dec 2024 10:10:03 -0600 Subject: [PATCH] change logger format to include date/time --- src/logger.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/logger.h b/src/logger.h index b43a06e..dc8bb45 100644 --- a/src/logger.h +++ b/src/logger.h @@ -1,5 +1,8 @@ #ifndef LOGGER_H #define LOGGER_H +#include +#include +#include #include #include #include @@ -29,7 +32,7 @@ public: void print(int level, const char* message, Args... args) { std::lock_guard lock(log_mutex); char* prepared; - asprintf(&prepared, "[%c] %s\n", logTypeChar(level), message); + asprintf(&prepared, "[%s] (%c) %s\n", getTime(), logTypeChar(level), message); char* formatted; asprintf(&formatted, prepared, args...); fprintf(stdout, formatted); @@ -48,6 +51,18 @@ public: private: std::map logfiles; + static const char* getTime() { + time_t rawtime; + struct tm* timeinfo; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + static char buffer[20]; + strftime(buffer, 20, "%y/%m/%d %H:%M:%S", timeinfo); + return buffer; + } + static const char logTypeChar(int level) { switch(level) { default: return ' ';