--- pyanaconda/isys/log.c | 55 +++++++++++++++++++++++++----------------------- 1 files changed, 29 insertions(+), 26 deletions(-) diff --git a/pyanaconda/isys/log.c b/pyanaconda/isys/log.c index 96da57e..0a45bf3 100644 --- a/pyanaconda/isys/log.c +++ b/pyanaconda/isys/log.c @@ -27,6 +27,7 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> #include <sys/time.h> @@ -62,40 +63,42 @@ static int mapLogLevel(int level) } } +static void log_level_to_str(const int level, char* outbuf) +{ + switch (level) { + case DEBUGLVL: + strcpy(outbuf, "DEBUG"); + break; + case INFO: + strcpy(outbuf, "INFO"); + break; + case WARNING: + strcpy(outbuf, "WARN"); + break; + case ERROR: + strcpy(outbuf, "ERR"); + break; + case CRITICAL: + strcpy(outbuf, "CRIT"); + break; + default: + strcpy(outbuf, "(UNKNWN)"); + break; + } +} + static void printLogHeader(int level, const char *tag, FILE *outfile) { struct timeval current_time; struct tm *t; int msecs; + char level_name[10]; gettimeofday(¤t_time, NULL); t = gmtime(¤t_time.tv_sec); msecs = current_time.tv_usec / 1000; - switch (level) { - case DEBUGLVL: - fprintf (outfile, "%02d:%02d:%02d,%03d DEBUG %s: ", t->tm_hour, - t->tm_min, t->tm_sec, msecs, tag); - break; - - case INFO: - fprintf (outfile, "%02d:%02d:%02d,%03d INFO %s: ", t->tm_hour, - t->tm_min, t->tm_sec, msecs, tag); - break; - - case WARNING: - fprintf (outfile, "%02d:%02d:%02d,%03d WARN %s: ", t->tm_hour, - t->tm_min, t->tm_sec, msecs, tag); - break; - - case ERROR: - fprintf (outfile, "%02d:%02d:%02d,%03d ERR %s: ", t->tm_hour, - t->tm_min, t->tm_sec, msecs, tag); - break; - - case CRITICAL: - fprintf (outfile, "%02d:%02d:%02d,%03d CRIT %s: ", t->tm_hour, - t->tm_min, t->tm_sec, msecs, tag); - break; - } + log_level_to_str(level, level_name); + fprintf(outfile, "%02d:%02d:%02d,%03d %s %s: ", t->tm_hour, + t->tm_min, t->tm_sec, msecs, level_name, tag); } static void printLogMessage(int level, const char *tag, FILE *outfile, const char *s, va_list ap) -- 1.7.1.1 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list