From 3ef52b16b565e5342356aee31a74e06a4bca854e Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 7 Mar 2016 17:08:36 -0800 Subject: [PATCH] Log file and line number. --- adsbus/log.c | 4 ++-- adsbus/log.h | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/adsbus/log.c b/adsbus/log.c index 42709f9..fb000fb 100644 --- a/adsbus/log.c +++ b/adsbus/log.c @@ -90,10 +90,10 @@ bool log_reopen(const char *path) { return true; } -void log_write(char type, const uint8_t *id, const char *fmt, ...) { +void log_write(char type, const char *loc, const uint8_t *id, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - assert(fprintf(log_stream, "%c %s: ", type, id) > 0); + assert(fprintf(log_stream, "%c [%20s] %s: ", type, loc, id) > 0); assert(vfprintf(log_stream, fmt, ap) > 0); assert(fprintf(log_stream, "\n") == 1); va_end(ap); diff --git a/adsbus/log.h b/adsbus/log.h index 74682b4..47002da 100644 --- a/adsbus/log.h +++ b/adsbus/log.h @@ -3,11 +3,13 @@ #include #include -#define LOG(id, ...) log_write((log_module), (id), __VA_ARGS__) +#define LOG_STR(line) #line +#define LOG_LOC(file, line) (file ":" LOG_STR(line)) +#define LOG(id, ...) log_write((log_module), LOG_LOC(__FILE__, __LINE__), (id), __VA_ARGS__) void log_init(void); void log_init2(void); void log_cleanup(void); bool log_reopen(const char *); -void log_write(char, const uint8_t *, const char *, ...) - __attribute__ ((__format__ (__printf__, 3, 4))); +void log_write(char, const char *, const uint8_t *, const char *, ...) + __attribute__ ((__format__ (__printf__, 4, 5)));