diff options
author | tanyaionova <isaqtm@gmail.com> | 2019-11-21 10:41:19 +0300 |
---|---|---|
committer | tanyaionova <isaqtm@gmail.com> | 2019-11-21 10:41:19 +0300 |
commit | 71c5a9445dc709eab44bd94818db2809de31c9b5 (patch) | |
tree | 0b08d13bad1a7e90ab639ac92862f25f2addbb4b /log.c | |
parent | ac7fd63348553c2a0ad1b776c7039b1a8b60dbe8 (diff) | |
download | ash-sbox-master.tar.gz |
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -24,11 +24,16 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <stddef.h> #include <sys/time.h> #include <time.h> #include "log.h" +#include "sds/sds.h" + +#define LOG_FILE_COL "\x1b[96m" +#define LOG_TIME_COL "\x1b[32m" static struct { FILE *fp; @@ -59,17 +64,19 @@ void log_log(int level, const char *file, int line, const char *fmt, ...) { if (L.quiet) return; + va_list args; + struct timeval tv; gettimeofday(&tv, NULL); - struct tm *lt = localtime(&tv.tv_sec); + struct tm *tp = localtime(&tv.tv_sec); - va_list args; char timebuf[16]; - timebuf[strftime(timebuf, sizeof(timebuf), "%H:%M:%S", lt)] = '\0'; + snprintf (timebuf, 16, "%02d:%02d:%02d.%04ld", + tp->tm_hour, tp->tm_min, tp->tm_sec, tv.tv_usec / 100); fprintf(stderr, - "%s.%04ld %s%-5s\x1b[0m \x1b[96m%s:%d:\x1b[0m ", - timebuf, tv.tv_usec / 100, level_colors[level], level_names[level], file, line); + LOG_TIME_COL "%s\x1b[0m %s%-5s\x1b[0m " LOG_FILE_COL "%s:%d\x1b[0m ", + timebuf, level_colors[level], level_names[level], file, line); va_start(args, fmt); vfprintf(stderr, fmt, args); |