diff --git a/src/gui.c b/src/gui.c index 687eae4..9b9188f 100644 --- a/src/gui.c +++ b/src/gui.c @@ -190,20 +190,25 @@ gui_render_panel(Gui *gui, unsigned int width, unsigned int height, Camera *cam) void gui_log(const char *fmt, ...) { + char buffer[log_data.strlen]; char *new_message; unsigned int i; - - new_message = ec_malloc(log_data.strlen * sizeof(char)); + char tstamp[10]; va_list args; va_start(args, fmt); #ifndef _MSC_VER - vsprintf(new_message, fmt, args); + vsprintf(buffer, fmt, args); #else // _MSC_VER - vsprintf_s(new_message, log_data.strlen, fmt, args); + vsprintf_s(buffer, log_data.strlen, fmt, args); #endif // _MSC_VER va_end(args); + new_message = ec_malloc(log_data.strlen * sizeof(char)); + + timestamp(tstamp, 10); + m_sprintf(new_message, log_data.strlen, "%s > %s", tstamp, buffer); + log_data.count++; if (log_data.count > log_data.len) { log_data.count = log_data.len; diff --git a/src/util.c b/src/util.c index 8e8f7f0..32953ca 100644 --- a/src/util.c +++ b/src/util.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "defines.h" @@ -56,7 +57,10 @@ void debug(const char *fmt, ...) { va_list args; - printf("[--] "); + char tstamp[10]; + + timestamp(tstamp, 10); + printf("[%s][--] ", tstamp); va_start(args, fmt); vprintf(fmt, args); va_end(args); @@ -67,7 +71,10 @@ void info(const char * fmt, ...) { va_list args; - printf("[**] "); + char tstamp[10]; + + timestamp(tstamp, 10); + printf("[%s][**] ", tstamp); va_start(args, fmt); vprintf(fmt, args); va_end(args); @@ -78,7 +85,10 @@ void error(const char *fmt, ...) { va_list args; - fprintf(stderr, "[!*] Error "); + char tstamp[10]; + + timestamp(tstamp, 10); + fprintf(stderr, "[%s][!*] ", tstamp); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); @@ -89,7 +99,10 @@ void fatal(const char *fmt, ...) { va_list args; - fprintf(stderr, "[!!] Fatal Error "); + char tstamp[10]; + + timestamp(tstamp, 10); + fprintf(stderr, "[%s][!!] ", tstamp); va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); @@ -106,3 +119,15 @@ void fatal("in ec_malloc() on memory allocation"); return ptr; } + +void +timestamp(char *tstamp, size_t sz) +{ + time_t cTime; + struct tm *tm_info; + + time(&cTime); + tm_info = localtime(&cTime); + + strftime(tstamp, sz, "%H:%M:%S", tm_info); +} diff --git a/src/util.h b/src/util.h index 8f3147c..6d03a74 100644 --- a/src/util.h +++ b/src/util.h @@ -25,4 +25,7 @@ m_strncat(char *dest, size_t destsz, char *src, size_t srcsz); void m_sprintf(char *dest, size_t destsz, const char *format, ...); +void +timestamp(char *tstamp, size_t sz); + #endif // UTIL_H_