Re: [master] logging: refactor printLogHeader

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



const char log_level_to_str = { ..., ... }
and keep it in sync with constant definitions of DEBUGLEVEL et al.?

On 08/13/2010 03:30 PM, Ales Kozumplik wrote:
> ---
>  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(&current_time, NULL);
>      t = gmtime(&current_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)

Steffen

Linux on System z Development

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list



[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux