This makes the loglevel_to_str array smaller and the logging functions safer to use. --- pyanaconda/isys/log.c | 18 +++++++++--------- pyanaconda/isys/log.h | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pyanaconda/isys/log.c b/pyanaconda/isys/log.c index c0150bf..e036524 100644 --- a/pyanaconda/isys/log.c +++ b/pyanaconda/isys/log.c @@ -37,13 +37,13 @@ static FILE * main_log_tty = NULL; static FILE * main_log_file = NULL; static FILE * program_log_file = NULL; -static int minLevel = INFO; +static enum loglevel_t minLevel = INFO; static const char * main_tag = "loader"; static const char * program_tag = "program"; static const int syslog_facility = LOG_LOCAL1; /* maps our loglevel to syslog loglevel */ -static int mapLogLevel(int level) +static int mapLogLevel(enum loglevel_t level) { switch (level) { case DEBUGLVL: @@ -70,7 +70,7 @@ const char *log_level_to_str[] = { [CRITICAL] = "CRIT" }; -static void printLogHeader(int level, const char *tag, FILE *outfile) { +static void printLogHeader(enum loglevel_t level, const char *tag, FILE *outfile) { struct timeval current_time; struct tm *t; int msecs; @@ -84,7 +84,7 @@ static void printLogHeader(int level, const char *tag, FILE *outfile) { 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) +static void printLogMessage(enum loglevel_t level, const char *tag, FILE *outfile, const char *s, va_list ap) { printLogHeader(level, tag, outfile); @@ -103,7 +103,7 @@ static void retagSyslog(const char* new_tag) openlog(new_tag, 0, syslog_facility); } -void logMessageV(enum logger_t logger, int level, const char * s, va_list ap) { +void logMessageV(enum logger_t logger, enum loglevel_t level, const char * s, va_list ap) { FILE *log_tty = main_log_tty; FILE *log_file = main_log_file; const char *tag = main_tag; @@ -137,7 +137,7 @@ void logMessageV(enum logger_t logger, int level, const char * s, va_list ap) { retagSyslog(main_tag); } -void logMessage(int level, const char * s, ...) { +void logMessage(enum loglevel_t level, const char * s, ...) { va_list args; va_start(args, s); @@ -145,7 +145,7 @@ void logMessage(int level, const char * s, ...) { va_end(args); } -void logProgramMessage(int level, const char * s, ...) { +void logProgramMessage(enum loglevel_t level, const char * s, ...) { va_list args; va_start(args, s); @@ -200,11 +200,11 @@ void closeLog(void) { } /* set the level. higher means you see more verbosity */ -void setLogLevel(int level) { +void setLogLevel(enum loglevel_t level) { minLevel = level; } -int getLogLevel(void) { +enum loglevel_t getLogLevel(void) { return minLevel; } diff --git a/pyanaconda/isys/log.h b/pyanaconda/isys/log.h index 88d0010..3df6cb0 100644 --- a/pyanaconda/isys/log.h +++ b/pyanaconda/isys/log.h @@ -23,27 +23,29 @@ #include <stdio.h> #include <stdarg.h> -#define DEBUGLVL 10 -#define INFO 20 -#define WARNING 30 -#define ERROR 40 -#define CRITICAL 50 +enum loglevel_t { + DEBUGLVL, + INFO, + WARNING, + ERROR, + CRITICAL +}; enum logger_t { MAIN_LOG = 1, PROGRAM_LOG = 2 }; -void logMessageV(enum logger_t logger, int level, const char * s, va_list ap) +void logMessageV(enum logger_t logger, enum loglevel_t level, const char * s, va_list ap) __attribute__ ((format (printf, 3, 0))); -void logMessage(int level, const char * s, ...) +void logMessage(enum loglevel_t level, const char * s, ...) __attribute__ ((format (printf, 2, 3))); -void logProgramMessage(int level, const char * s, ...) +void logProgramMessage(enum loglevel_t level, const char * s, ...) __attribute__ ((format (printf, 2, 3))); void openLog(); void closeLog(void); -void setLogLevel(int minLevel); -int getLogLevel(void); +void setLogLevel(enum loglevel_t minLevel); +enum loglevel_t getLogLevel(void); int loggingReady(void); extern int tty_logfd; -- 1.7.1.1 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list