summaryrefslogtreecommitdiffstats
path: root/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'log.c')
-rw-r--r--log.c53
1 files changed, 22 insertions, 31 deletions
diff --git a/log.c b/log.c
index 77b81c5..75165f1 100644
--- a/log.c
+++ b/log.c
@@ -24,14 +24,14 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+
+#include <sys/time.h>
#include <time.h>
#include "log.h"
static struct {
- void *udata;
FILE *fp;
- int level;
int quiet;
} L;
@@ -41,7 +41,7 @@ static const char *level_names[] = {
};
static const char *level_colors[] = {
- "\x1b[94m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[35m"
+ "\x1b[35m", "\x1b[36m", "\x1b[32m", "\x1b[33m", "\x1b[31m", "\x1b[91m"
};
@@ -50,39 +50,30 @@ void log_set_fp(FILE *fp) {
}
-void log_set_level(int level) {
- L.level = level;
-}
-
-
void log_set_quiet(int enable) {
L.quiet = enable ? 1 : 0;
}
void log_log(int level, const char *file, int line, const char *fmt, ...) {
- if (level < L.level) {
+ if (L.quiet)
return;
- }
-
- /* Get current time */
- time_t t = time(NULL);
- struct tm *lt = localtime(&t);
-
- /* Log to stderr */
- if (!L.quiet) {
- va_list args;
- char buf[16];
- buf[strftime(buf, sizeof(buf), "%H:%M:%S", lt)] = '\0';
-
- fprintf(
- stderr, "%s %s%-5s\x1b[0m \x1b[96m%s:%d:\x1b[0m ",
- buf, level_colors[level], level_names[level], file, line);
-
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- va_end(args);
- fprintf(stderr, "\n");
- fflush(stderr);
- }
+
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ struct tm *lt = localtime(&tv.tv_sec);
+
+ va_list args;
+ char timebuf[16];
+ timebuf[strftime(timebuf, sizeof(timebuf), "%H:%M:%S", lt)] = '\0';
+
+ 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);
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+ fprintf(stderr, "\n");
+ fflush(stderr);
} \ No newline at end of file