summaryrefslogtreecommitdiff
path: root/utils/log.h
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-05-28 16:08:46 +0100
committerVincent Sanders <vince@kyllikki.org>2015-05-28 16:08:46 +0100
commitc105738fa36bb2400adc47399c5b878d252d1c86 (patch)
tree138eeb449e1bf51ee1726b5f820740aada0ccd0b /utils/log.h
parent20f2c86a511f7913cf858e7bd3668b0b59663ba0 (diff)
downloadnetsurf-c105738fa36bb2400adc47399c5b878d252d1c86.tar.gz
netsurf-c105738fa36bb2400adc47399c5b878d252d1c86.tar.bz2
Change LOG() macro to be varadic
This changes the LOG macro to be varadic removing the need for all callsites to have double bracketing and allows for future improvement on how we use the logging macros. The callsites were changed with coccinelle and the changes checked by hand. Compile tested for several frontends but not all. A formatting annotation has also been added which allows the compiler to check the parameters and types passed to the logging.
Diffstat (limited to 'utils/log.h')
-rw-r--r--utils/log.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/utils/log.h b/utils/log.h
index 673419b66..1fd1415fd 100644
--- a/utils/log.h
+++ b/utils/log.h
@@ -44,7 +44,7 @@ typedef bool(nslog_ensure_t)(FILE *fptr);
extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
#ifdef NDEBUG
-# define LOG(x) ((void) 0)
+# define LOG(format, ...) ((void) 0)
#else
/**
@@ -53,7 +53,8 @@ extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
* \return formatted string of the time since first log call
*/
extern const char *nslog_gettime(void);
-extern void nslog_log(const char *format, ...);
+
+extern void nslog_log(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
# ifdef __GNUC__
# define LOG_FN __PRETTY_FUNCTION__
@@ -66,12 +67,12 @@ extern void nslog_log(const char *format, ...);
# define LOG_LN __LINE__
# endif
-#define LOG(x) \
+#define LOG(format, args...) \
do { \
if (verbose_log) { \
nslog_log("%s " __FILE__ " %s %i: ", \
nslog_gettime(), LOG_FN, LOG_LN); \
- nslog_log x; \
+ nslog_log(format , ##args); \
nslog_log("\n"); \
} \
} while(0)