improve log when debugging.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 7 Jan 2012 21:25:03 +0000 (19:25 -0200)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Wed, 1 Feb 2012 00:01:00 +0000 (22:01 -0200)
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.

libkmod/libkmod.c

index d5bcab1..9c7c701 100644 (file)
@@ -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);
 }