Re: [master] logging: refactor printLogHeader

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

 



> +const char *log_level_to_str[LOGLEVEL_MAX + 1] = {

This isn't needed, just keep the brackets empty and the compiler will do its job to allocate only the smallest array neccessary.

--
Martin Sivák
msivak@xxxxxxxxxx
Red Hat Czech
Anaconda team / Brno, CZ

----- "Ales Kozumplik" <akozumpl@xxxxxxxxxx> wrote:

> ---
>  pyanaconda/isys/log.c |   39 +++++++++++++--------------------------
>  pyanaconda/isys/log.h |    1 +
>  2 files changed, 14 insertions(+), 26 deletions(-)
> 
> diff --git a/pyanaconda/isys/log.c b/pyanaconda/isys/log.c
> index 96da57e..0421684 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,26 @@ static int mapLogLevel(int level)
>      }
>  }
>  
> +const char *log_level_to_str[LOGLEVEL_MAX + 1] = {
> +    [DEBUGLVL] = "DEBUG",
> +    [INFO] = "INFO",
> +    [WARNING] = "WARN",
> +    [ERROR] = "ERR",
> +    [CRITICAL] = "CRIT"
> +};
> +
>  static void printLogHeader(int level, const char *tag, FILE *outfile)
> {
>      struct timeval current_time;
>      struct tm *t;
>      int msecs;
> +    const char *level_name;
>  
>      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;
> -    }
> +    level_name = log_level_to_str[level];
> +    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)
> diff --git a/pyanaconda/isys/log.h b/pyanaconda/isys/log.h
> index 88d0010..910fd9a 100644
> --- a/pyanaconda/isys/log.h
> +++ b/pyanaconda/isys/log.h
> @@ -28,6 +28,7 @@
>  #define WARNING  30
>  #define ERROR    40
>  #define CRITICAL 50
> +#define LOGLEVEL_MAX CRITICAL
>  
>  enum logger_t {
>      MAIN_LOG = 1,
> -- 
> 1.7.1.1
> 
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

_______________________________________________
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