diff options
author | Daniel Stone <daniel@fooishbar.org> | 2012-08-08 14:01:46 +0200 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2012-08-08 16:23:31 +0200 |
commit | 5e276adb9209749f1b5152853c640ec444df7051 (patch) | |
tree | d6c77df81fe9dc3c8d470903c059e05330b4824c /src | |
parent | ba8458a9fd580d80d127ed1768f8f1d4a51ef251 (diff) |
Add xkb_log_level enum rather than using syslog
Instead of relying on people including syslog.h, add our own
XKB_LOG_LEVEL_* defines.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/context.c | 31 | ||||
-rw-r--r-- | src/xkb-priv.h | 20 |
2 files changed, 26 insertions, 25 deletions
diff --git a/src/context.c b/src/context.c index 864c6de..942fcc2 100644 --- a/src/context.c +++ b/src/context.c @@ -30,7 +30,6 @@ #include <stdarg.h> #include <stdio.h> #include <unistd.h> -#include <syslog.h> #include "xkb-priv.h" #include "atom.h" @@ -180,18 +179,16 @@ static const char * priority_to_prefix(int priority) { switch (priority) { - case LOG_DEBUG: + case XKB_LOG_LEVEL_DEBUG: return "Debug:"; - case LOG_INFO: + case XKB_LOG_LEVEL_INFO: return "Info:"; - case LOG_WARNING: + case XKB_LOG_LEVEL_WARNING: return "Warning:"; - case LOG_ERR: + case XKB_LOG_LEVEL_ERROR: return "Error:"; - case LOG_CRIT: - case LOG_ALERT: - case LOG_EMERG: - return "Internal error:"; + case XKB_LOG_LEVEL_CRITICAL: + return "Internal error (critical):"; default: return NULL; } @@ -218,15 +215,15 @@ log_priority(const char *priority) { if (errno == 0 && (endptr[0] == '\0' || isspace(endptr[0]))) return prio; if (strncasecmp(priority, "err", 3) == 0) - return LOG_ERR; + return XKB_LOG_LEVEL_ERROR; if (strncasecmp(priority, "warn", 4) == 0) - return LOG_WARNING; + return XKB_LOG_LEVEL_WARNING; if (strncasecmp(priority, "info", 4) == 0) - return LOG_INFO; + return XKB_LOG_LEVEL_INFO; if (strncasecmp(priority, "debug", 5) == 0) - return LOG_DEBUG; + return XKB_LOG_LEVEL_DEBUG; - return LOG_ERR; + return XKB_LOG_LEVEL_ERROR; } static int @@ -256,7 +253,7 @@ xkb_context_new(enum xkb_context_flags flags) ctx->refcnt = 1; ctx->log_fn = default_log_fn; - ctx->log_priority = LOG_ERR; + ctx->log_priority = XKB_LOG_LEVEL_ERROR; ctx->log_verbosity = 0; /* Environment overwrites defaults. */ @@ -327,14 +324,14 @@ xkb_set_log_fn(struct xkb_context *ctx, ctx->log_fn = (log_fn ? log_fn : default_log_fn); } -XKB_EXPORT int +XKB_EXPORT enum xkb_log_level xkb_get_log_priority(struct xkb_context *ctx) { return ctx->log_priority; } XKB_EXPORT void -xkb_set_log_priority(struct xkb_context *ctx, int priority) +xkb_set_log_priority(struct xkb_context *ctx, enum xkb_log_level priority) { ctx->log_priority = priority; } diff --git a/src/xkb-priv.h b/src/xkb-priv.h index 42b7fa1..68bbcb9 100644 --- a/src/xkb-priv.h +++ b/src/xkb-priv.h @@ -82,7 +82,6 @@ #include <stdbool.h> #include <string.h> #include <strings.h> -#include <syslog.h> #include <X11/extensions/XKB.h> #include "xkbcommon/xkbcommon.h" @@ -115,7 +114,7 @@ struct xkb_context { ATTR_PRINTF(3, 0) void (*log_fn)(struct xkb_context *ctx, int priority, const char *fmt, va_list args); - int log_priority; + enum xkb_log_level log_priority; int log_verbosity; void *user_data; @@ -549,12 +548,17 @@ xkb_log(struct xkb_context *ctx, int priority, const char *fmt, ...); * format is supplied without arguments. Not supplying it would still * result in an error, though. */ -#define log_dbg(ctx, ...) xkb_log_cond((ctx), LOG_DEBUG, __VA_ARGS__) -#define log_info(ctx, ...) xkb_log_cond((ctx), LOG_INFO, __VA_ARGS__) -#define log_warn(ctx, ...) xkb_log_cond((ctx), LOG_WARNING, __VA_ARGS__) -#define log_err(ctx, ...) xkb_log_cond((ctx), LOG_ERR, __VA_ARGS__) -#define log_wsgo(ctx, ...) xkb_log_cond((ctx), LOG_CRIT, __VA_ARGS__) +#define log_dbg(ctx, ...) \ + xkb_log_cond((ctx), XKB_LOG_LEVEL_DEBUG, __VA_ARGS__) +#define log_info(ctx, ...) \ + xkb_log_cond((ctx), XKB_LOG_LEVEL_INFO, __VA_ARGS__) +#define log_warn(ctx, ...) \ + xkb_log_cond((ctx), XKB_LOG_LEVEL_WARNING, __VA_ARGS__) +#define log_err(ctx, ...) \ + xkb_log_cond((ctx), XKB_LOG_LEVEL_ERROR, __VA_ARGS__) +#define log_wsgo(ctx, ...) \ + xkb_log_cond((ctx), XKB_LOG_LEVEL_CRITICAL, __VA_ARGS__) #define log_lvl(ctx, lvl, ...) \ - xkb_log_cond_lvl((ctx), LOG_WARNING, (lvl), __VA_ARGS__) + xkb_log_cond_lvl((ctx), XKB_LOG_LEVEL_WARNING, (lvl), __VA_ARGS__) #endif /* XKB_PRIV_H */ |