X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Futils%2Ferror.h;h=d00ee8c0f980b5abf8590b99f073a3344d0cdb1b;hb=HEAD;hp=73b48baacf2c1cdf9f5df66118166fc90c6df408;hpb=848efadda124a4778f08a84a082ff2436504d22c;p=sysdb.git diff --git a/src/include/utils/error.h b/src/include/utils/error.h index 73b48ba..d00ee8c 100644 --- a/src/include/utils/error.h +++ b/src/include/utils/error.h @@ -31,23 +31,19 @@ * will use its own memory region to store information about the last reported * error. * Once the error message has been passed to SysDB, it will log the entire - * message at once. XXX: currently, SysDB only supports printing the error to - * the standard error channel; support for other logging backends will be - * added later in a modular fashion. + * message at once. The message will be sent to all registered log functions. */ #ifndef SDB_UTILS_ERROR_H #define SDB_UTILS_ERROR_H 1 +#include +#include + #ifdef __cplusplus extern "C" { #endif -/* max length of any error message */ -#ifndef SDB_MAX_ERROR -# define SDB_MAX_ERROR 4096 -#endif /* ! SDB_MAX_ERROR */ - /* On Linux systems and possibly others, this should be the same as the LOG_ * constants defined by syslog. */ enum { @@ -66,8 +62,21 @@ enum { : ((prio) == SDB_LOG_INFO) ? "INFO" \ : ((prio) == SDB_LOG_DEBUG) ? "DEBUG" : "UNKNOWN") +#ifndef SDB_DEFAULT_LOGLEVEL +# define SDB_DEFAULT_LOGLEVEL SDB_LOG_INFO +#endif + +/* + * sdb_error_set_logger: + * Set the logging callback to be used for logging messages. By default (or + * when explicitely setting the logger to NULL), logs will be written to the + * stderr channel. + */ +void +sdb_error_set_logger(int (*f)(int, const char *)); + /* - * sdb_log: + * sdb_log, sdb_vlog: * Log the specified message. The string will be formatted in printf-style * using the specified format and arguments and logged with the specified * priority. In addition, the error message will be stored as the current @@ -76,7 +85,10 @@ enum { * on configuration, try a clean shut-down of the process. */ int -sdb_log(int prio, const char *fmt, ...); +sdb_log(int prio, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); +int +sdb_vlog(int prio, const char *fmt, va_list ap); /* * sdb_error_set, sdb_error_append: @@ -85,9 +97,18 @@ sdb_log(int prio, const char *fmt, ...); * be done. */ int -sdb_error_set(const char *fmt, ...); +sdb_error_set(const char *fmt, ...) + __attribute__((format(printf, 1, 2))); +int +sdb_error_append(const char *fmt, ...) + __attribute__((format(printf, 1, 2))); + +/* + * sdb_error_chomp: + * Remove all consecutive newline characters at the end of the error message. + */ int -sdb_error_append(const char *fmt, ...); +sdb_error_chomp(void); /* * sdb_error_log: @@ -114,6 +135,25 @@ 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 + * a pointer to the formatted error message is returned. + */ +char * +sdb_strerror(int errnum, char *strerrbuf, size_t buflen); + #ifdef __cplusplus } /* extern "C" */ #endif