From e41c7556c22bda359c2b97cd98d59082110add95 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 22 Feb 2017 14:31:16 -0800 Subject: Add --color_warnings to make warnings/errors like clang This adds new (WARN|KATI_WARN|ERROR)_LOC log macro variants that take a location as the first argument, and will prefix that location information to the warning/error lines. When --color_warnings is enabled, it reformats them to have a standard warning:/error: infix, and adds colors in order to match the warnings/errors produced by clang. --- log.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'log.h') diff --git a/log.h b/log.h index 11cf0e5..58c733a 100644 --- a/log.h +++ b/log.h @@ -21,6 +21,7 @@ #include #include "flags.h" +#include "log.h" #include "stringprintf.h" using namespace std; @@ -73,4 +74,22 @@ extern string* g_last_error; #define CHECK(c) if (!(c)) ERROR("%s:%d: %s", __FILE__, __LINE__, #c) +// Set of logging functions that will automatically colorize lines that have +// location information when --color_warnings is set. +void ColorWarnLog(const char* file, int line, const char *msg); +void ColorErrorLog(const char* file, int line, const char *msg); + +#define WARN_LOC(loc, ...) do { \ + ColorWarnLog(LOCF(loc), StringPrintf(__VA_ARGS__).c_str()); \ + } while (0) + +#define KATI_WARN_LOC(loc, ...) do { \ + if (g_flags.enable_kati_warnings) \ + ColorWarnLog(LOCF(loc), StringPrintf(__VA_ARGS__).c_str()); \ + } while(0) + +#define ERROR_LOC(loc, ...) do { \ + ColorErrorLog(LOCF(loc), StringPrintf(__VA_ARGS__).c_str()); \ + } while (0) + #endif // LOG_H_ -- cgit v1.2.3