From: Sebastian Harl Date: Sun, 1 Feb 2015 09:36:18 +0000 (+0100) Subject: error utils: Add sdb_error_parse_priority(). X-Git-Tag: sysdb-0.7.0~26 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=76d4396d3e9d2593d76116b6275b1d7edc83e5d1 error utils: Add sdb_error_parse_priority(). --- diff --git a/src/include/utils/error.h b/src/include/utils/error.h index 49034eb..ae653af 100644 --- a/src/include/utils/error.h +++ b/src/include/utils/error.h @@ -131,6 +131,17 @@ sdb_error_get(void); int sdb_error_get_prio(void); +/* + * sdb_error_parse_priority: + * Parse the name of a log priority. + * + * Returns: + * - the numeric log priority on success + * - a negative value else + */ +int +sdb_error_parse_priority(char *prio); + /* * sdb_strerror: * This is a wrapper around the system's strerror function which ensures that diff --git a/src/utils/error.c b/src/utils/error.c index f940be6..2bc9901 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -276,6 +276,24 @@ sdb_error_get_prio(void) return ctx->prio; } /* sdb_error_get_prio */ +int +sdb_error_parse_priority(char *prio) +{ + if (! strcasecmp(prio, "EMERG")) + return SDB_LOG_EMERG; + else if (! strcasecmp(prio, "ERROR")) + return SDB_LOG_ERR; + else if (! strcasecmp(prio, "WARNING")) + return SDB_LOG_WARNING; + else if (! strcasecmp(prio, "NOTICE")) + return SDB_LOG_NOTICE; + else if (! strcasecmp(prio, "INFO")) + return SDB_LOG_INFO; + else if (! strcasecmp(prio, "DEBUG")) + return SDB_LOG_DEBUG; + return -1; +} /* sdb_error_parse_priority */ + char * sdb_strerror(int errnum, char *strerrbuf, size_t buflen) {