diff --git a/include/log.h b/include/log.h index 7199255b4..a8c498d79 100644 --- a/include/log.h +++ b/include/log.h @@ -26,6 +26,27 @@ #define ERROR RED("Error") #define STATS MAG("Stats") +/** Debug facilities. + * + * To be or-ed with the debug level + */ +enum debug_facilities { + DBG_POOL = (1 << 8), + DBG_QUEUE = (1 << 9), + DBG_CONFIG = (1 << 10), + DBG_HOOK = (1 << 11), + DBG_PATH = (1 << 12), + + /* Node-types */ + DBG_SOCKET = (1 << 16), + DBG_FILE = (1 << 17), + DBG_GTFPGA = (1 << 18), + DBG_NGSI = (1 << 19), + DBG_WEBSOCKET = (1 << 20), + DBG_OPAL = (1 << 21), + DBG_NODE = (0xFF << 16) +}; + /** Change log indention for current thread. * * The argument level can be negative! @@ -42,8 +63,9 @@ void log_outdent(int *); /** Set the verbosity level of debug messages. * * @param lvl The new debug level. + * @param fac The new mask for debug facilities. */ -void log_setlevel(int lvl); +void log_setlevel(int lvl, int fac); /** Reset the wallclock of debug messages. */ void log_init(); diff --git a/lib/cfg.c b/lib/cfg.c index df76f9036..3624aacdd 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -83,7 +83,7 @@ int config_parse_global(config_setting_t *cfg, struct settings *set) config_setting_lookup_int(cfg, "debug", &set->debug); config_setting_lookup_float(cfg, "stats", &set->stats); - log_setlevel(set->debug); + log_setlevel(set->debug, -1); return 0; } diff --git a/lib/log.c b/lib/log.c index 3cc516095..2986e3c15 100644 --- a/lib/log.c +++ b/lib/log.c @@ -26,7 +26,10 @@ /** Debug level used by the debug() macro. * It defaults to V (defined by the Makefile) and can be * overwritten by the 'debug' setting in the configuration file. */ -static int level = V; +static unsigned level = V; + +/** Debug facilities used by the debug() macro. */ +static unsigned facilities = ~0; /** A global clock used to prefix the log messages. */ static struct timespec epoch; @@ -48,7 +51,7 @@ void log_outdent(int *old) } #endif -void log_setlevel(int lvl) +void log_setlevel(int lvl, int fac) { level = lvl; debug(10, "Switched to debug level %u", level); @@ -107,11 +110,14 @@ void line() log_print("", "\b" ACS("%.*s"), LOG_WIDTH, buf); } -void debug(int lvl, const char *fmt, ...) +void debug(int class, const char *fmt, ...) { va_list ap; + + int lvl = class & 0xFF; + int fac = class & ~0xFF; - if (lvl <= level) { + if (((fac == 0) || (fac & facilities)) && (lvl <= level)) { va_start(ap, fmt); log_vprint(DEBUG, fmt, ap); va_end(ap);