diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-04-28 09:48:40 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-04-28 09:48:40 +0000 |
commit | 22bf9913a1831690504a0ff1c43c209c5f258cea (patch) | |
tree | a37de21a742386bdf4a4f9a1d585520aa9171149 /gacopyz | |
parent | b49ef04125f27858ffafd8be38f1e73d81fb1c27 (diff) | |
download | mailfromd-22bf9913a1831690504a0ff1c43c209c5f258cea.tar.gz mailfromd-22bf9913a1831690504a0ff1c43c209c5f258cea.tar.bz2 |
Bugfixes
git-svn-id: file:///svnroot/mailfromd/trunk@1389 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'gacopyz')
-rw-r--r-- | gacopyz/gacopyz.h | 7 | ||||
-rw-r--r-- | gacopyz/log.c | 20 | ||||
-rw-r--r-- | gacopyz/smfi.c | 14 |
3 files changed, 27 insertions, 14 deletions
diff --git a/gacopyz/gacopyz.h b/gacopyz/gacopyz.h index 578f25d4..0e40e171 100644 --- a/gacopyz/gacopyz.h +++ b/gacopyz/gacopyz.h @@ -127,7 +127,9 @@ extern "C" { #define SMI_LOG_FATAL 4 #define SMI_LOG_MASK(n) (1<<(n)) - +#define SMI_LOG_UPTO(n) ((1 << ((n)+1))-1) /* all levels through n */ +#define SMI_LOG_FROM(n) (SMI_LOG_UPTO(SMI_LOG_FATAL) & ~SMI_LOG_UPTO(n-1)) + #define SMI_DEFAULT_LOG_MASK SMI_LOG_MASK(SMI_LOG_INFO) \ | SMI_LOG_MASK(SMI_LOG_WARN) \ | SMI_LOG_MASK(SMI_LOG_ERR) \ @@ -310,6 +312,9 @@ void gacopyz_set_logger(void (*)(int, char *, va_list)); void gacopyz_stderr_log_printer(int level, char *fmt, va_list ap); void gacopyz_syslog_log_printer(int level, char *fmt, va_list ap); +int gacopyz_string_to_log_level(const char *str); +const char *gacopyz_log_level_to_string(int level); + /* Server */ typedef struct gacopyz_srv *gacopyz_srv_t; diff --git a/gacopyz/log.c b/gacopyz/log.c index 05144568..b1dd2348 100644 --- a/gacopyz/log.c +++ b/gacopyz/log.c @@ -54,10 +54,28 @@ static char *level_name[] = { "FATAL" }; +int +gacopyz_string_to_log_level(const char *str) +{ + int i; + for (i = 0; i < sizeof level_name / sizeof level_name[0]; i++) + if (strcasecmp (str, level_name[i]) == 0) + return i; + return -1; +} + +const char * +gacopyz_log_level_to_string(int level) +{ + if (level < 0 || level > sizeof level_name / sizeof level_name[0]) + return NULL; + return level_name[level]; +} + void gacopyz_stderr_log_printer(int level, char *fmt, va_list ap) { - fprintf(stderr, "Gacopyz %s: ", level_name[level]); + fprintf(stderr, "Gacopyz %s: ", gacopyz_log_level_to_string(level)); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); } diff --git a/gacopyz/smfi.c b/gacopyz/smfi.c index 72889436..60fb8439 100644 --- a/gacopyz/smfi.c +++ b/gacopyz/smfi.c @@ -36,18 +36,8 @@ smfi_setdbg(int level) int smfi_setlogmask(int logmask) { - switch (logmask) { - case SMI_LOG_DEBUG: - case SMI_LOG_INFO: - case SMI_LOG_WARN: - case SMI_LOG_ERR: - case SMI_LOG_FATAL: - __smfi_logmask = SMI_LOG_MASK(logmask); - return MI_SUCCESS; - - default: - return MI_FAILURE; - } + __smfi_logmask = logmask; + return MI_SUCCESS; } int |