diff options
author | Ran Benita <ran234@gmail.com> | 2012-07-20 13:10:13 +0300 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-07-23 00:45:34 +0300 |
commit | 70f35cfbc0e41ce5ddf1d5a9b7b0a7731e68d5bf (patch) | |
tree | 0d7553541568cba33b3f4c9a35493b91a843a32f /src/utils.h | |
parent | 71c2f2e0e2dce7e3ada36ee7399421eb18a2e302 (diff) |
Add logging API
Add new public API to provide the library users with some options to
control and customize the logging output from the library. It is based
upon the skeleton from the libabc demo libray:
https://git.kernel.org/?p=linux/kernel/git/kay/libabc.git
which is public domain and works pretty well.
This requires passing in the context object in every logging call, and
thus the conversion is done file by file. We also remove the global
warningLevel variable in favor of a verbosity level in the context,
which can be set by the user and is silent by default.
One issue is the ACTION calls, which, while nice, do not play very well
with line- and priority-based logging, and would require some
line continuation handling or keeping state or some other compromise. So
instead remove these and just inline them with their respective
warning/error. So instead of:
ERROR("Memory allocation failed\n")
ACTION("Removing all files on hardisk\n")
its something like that:
log_err("Memory allocation failed; Removing all files on harddisk\n")
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/utils.h')
-rw-r--r-- | src/utils.h | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/src/utils.h b/src/utils.h index 4ea703a..7d4e612 100644 --- a/src/utils.h +++ b/src/utils.h @@ -29,10 +29,6 @@ /***====================================================================***/ -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> - /* * We sometimes malloc strings and then expose them as const char*'s. This * macro is used when we free these strings in order to avoid -Wcast-qual @@ -73,33 +69,10 @@ #define ATTR_MALLOC #endif -extern bool -uSetErrorFile(char *name); - -#define INFO uInformation - -ATTR_PRINTF(1, 2) void -uInformation(const char *s, ...); - -#define ACTION uAction - -ATTR_PRINTF(1, 2) void -uAction(const char *s, ...); - -#define WARN uWarning - -ATTR_PRINTF(1, 2) void -uWarning(const char *s, ...); - -#define ERROR uError - -ATTR_PRINTF(1, 2) void -uError(const char *s, ...); - -/* WSGO stands for "Weird Stuff Going On" (wtf???) */ -#define WSGO uInternalError - -ATTR_PRINTF(1, 2) void -uInternalError(const char *s, ...); +#define INFO(...) xkb_log(NULL, LOG_INFO, __VA_ARGS__) +#define WARN(...) xkb_log(NULL, LOG_WARNING, __VA_ARGS__) +#define ERROR(...) xkb_log(NULL, LOG_ERR, __VA_ARGS__) +#define WSGO(...) xkb_log(NULL, LOG_CRIT, __VA_ARGS__) +#define ACTION(...) xkb_log(NULL, -1, __VA_ARGS__) #endif /* UTILS_H */ |