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 /xkbcommon | |
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 'xkbcommon')
-rw-r--r-- | xkbcommon/xkbcommon.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/xkbcommon/xkbcommon.h b/xkbcommon/xkbcommon.h index 42f70ad..8c772ae 100644 --- a/xkbcommon/xkbcommon.h +++ b/xkbcommon/xkbcommon.h @@ -249,6 +249,77 @@ xkb_context_unref(struct xkb_context *context); /** @} */ /** + * @defgroup logging Logging handling + * These functions allow you to manipulate how logging from this library + * will be handled. + * + * @{ + */ + +/** + * Sets the function to be called for logging messages, instead of the + * default logger which writes to stderr. + **/ +void +xkb_set_log_fn(struct xkb_context *context, + void (*log_fn)(struct xkb_context *context, int priority, + const char *format, va_list args)); +/** + * Sets the current logging priority. The value controls which messages + * are logged. + * + * The value should be one of LOG_ERR, LOG_WARNING, LOG_DEBUG, etc., see + * syslog(3) or syslog.h. The default priority is LOG_ERR. + * The environment variable XKB_LOG, if set, overrides the default value + * and may be specified as a priority number or name. + */ +void +xkb_set_log_priority(struct xkb_context *context, int priority); + +/** + * Returns the current logging priority. + */ +int +xkb_get_log_priority(struct xkb_context *context); + +/** + * Sets the current logging verbosity, a value from 0 to 10. + * + * The library can generate a number of warnings which are not helpful to + * ordinary users of the library. The verbosity may be increased if more + * information is desired (e.g. when developing a keymap). Defaults to 0. + * The environment variable XKB_VERBOSITY, if set, overrdies the default + * value. + * + * Note that most verbose messages are of priority LOG_WARNING or lower. + */ +void +xkb_set_log_verbosity(struct xkb_context *ctx, int verbosity); + +/** + * Returns the current logging verbosity. + */ +int +xkb_get_log_verbosity(struct xkb_context *ctx); + +/** + * Retrieves stored data pointer from the context. This might be useful + * to access from callbacks like a custom logging function. + * + * If context is NULL, returns NULL. + **/ +void * +xkb_get_user_data(struct xkb_context *context); + +/** + * Store custom user data in the context. + */ +void +xkb_set_user_data(struct xkb_context *context, void *user_data); + +/** @} */ + +/** * @defgroup map Keymap management * These utility functions allow you to create and deallocate XKB keymaps. * |