From 1a54147c6996ac580bbac79a8b5399b99ff34372 Mon Sep 17 00:00:00 2001 From: Marvin Blum <6115423+Kugelschieber@users.noreply.github.com> Date: Wed, 9 Jun 2021 14:31:49 +0200 Subject: [PATCH] Fixed log levels and time string function. --- src/log.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/log.c b/src/log.c index 217f0d0..ee3e68e 100644 --- a/src/log.c +++ b/src/log.c @@ -5,33 +5,27 @@ int logLevel = 0; -// TODO -/*const char* timeStr() { +char* timeNow() { time_t now = time(NULL); struct tm * p = localtime(&now); - char buffer[25]; - strftime(buffer, 25, "%Y-%m-%d %H:%M:%S", p); - //buffer[24] = '\0'; - const char* str = buffer; - return str; -}*/ + static char buffer[21]; + strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", p); + buffer[20] = '\0'; + return buffer; +} void vkeSetLogLevel(int level) { logLevel = level; } void vkeLogDebug(const char* message) { - if(logLevel == 0) { - time_t now; - time(&now); - printf("%s [DEBUG] %s\n", ctime(&now), message); + if(logLevel < VKE_LOG_ERROR) { + printf("%s [DEBUG] %s\n", timeNow(), message); } } void vkeLogError(const char* message) { - if(logLevel > 0) { - time_t now; - time(&now); - printf("%s [ERROR] %s\n", ctime(&now), message); + if(logLevel < VKE_LOG_ERROR+1) { + printf("%s [ERROR] %s\n", timeNow(), message); } }