diff options
author | Gustavo Sverzut Barbieri <barbieri@profusion.mobi> | 2012-01-07 19:25:03 -0200 |
---|---|---|
committer | Gustavo Sverzut Barbieri <barbieri@profusion.mobi> | 2012-01-31 22:01:00 -0200 |
commit | e3cb0900dd58a4b3a5c85ef52983b1e65931150b (patch) | |
tree | 162f386c49d1b78eac8a2a9eb7740955bf7dc327 | |
parent | 9226ddad2c8db413c85bb102c47c34ca040934e4 (diff) | |
download | kmod-e3cb0900dd58a4b3a5c85ef52983b1e65931150b.tar.gz kmod-e3cb0900dd58a4b3a5c85ef52983b1e65931150b.zip |
improve log when debugging.
Some messages may happen more than once in the same function and
discovering the line is hard. Now we print the actual log priority
that exposed the message as well as filename and line.
NOTE: We should consider printing the log priority in the non-debug
version as well.
-rw-r--r-- | libkmod/libkmod.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index d5bcab1..9c7c701 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -102,7 +102,42 @@ static void log_filep(void *data, const char *fn, const char *format, va_list args) { FILE *fp = data; +#ifdef ENABLE_DEBUG + char buf[16]; + const char *priname; + switch (priority) { + case LOG_EMERG: + priname = "EMERGENCY"; + break; + case LOG_ALERT: + priname = "ALERT"; + break; + case LOG_CRIT: + priname = "CRITICAL"; + break; + case LOG_ERR: + priname = "ERROR"; + break; + case LOG_WARNING: + priname = "WARNING"; + break; + case LOG_NOTICE: + priname = "NOTICE"; + break; + case LOG_INFO: + priname = "INFO"; + break; + case LOG_DEBUG: + priname = "DEBUG"; + break; + default: + snprintf(buf, sizeof(buf), "L:%d", priority); + priname = buf; + } + fprintf(fp, "libkmod: %s %s:%d %s: ", priname, file, line, fn); +#else fprintf(fp, "libkmod: %s: ", fn); +#endif vfprintf(fp, format, args); } |