Skip to content

Commit

Permalink
logging: Make log_err_func* use a message ID
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Sep 24, 2024
1 parent ca2c677 commit ef65939
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
15 changes: 10 additions & 5 deletions src/compose/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ xkb_compose_table_new_from_file(struct xkb_context *ctx,
bool ok;

if (flags & ~(XKB_COMPOSE_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

if (format != XKB_COMPOSE_FORMAT_TEXT_V1) {
log_err_func(ctx, "unsupported compose format: %d\n", format);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unsupported compose format: %d\n", format);
return NULL;
}

Expand Down Expand Up @@ -133,12 +135,14 @@ xkb_compose_table_new_from_buffer(struct xkb_context *ctx,
bool ok;

if (flags & ~(XKB_COMPOSE_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

if (format != XKB_COMPOSE_FORMAT_TEXT_V1) {
log_err_func(ctx, "unsupported compose format: %d\n", format);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unsupported compose format: %d\n", format);
return NULL;
}

Expand Down Expand Up @@ -166,7 +170,8 @@ xkb_compose_table_new_from_locale(struct xkb_context *ctx,
bool ok;

if (flags & ~(XKB_COMPOSE_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

Expand Down
12 changes: 6 additions & 6 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ xkb_context_sanitize_rule_names(struct xkb_context *ctx,
xkb_log_with_code((ctx), XKB_LOG_LEVEL_INFO, 0, id, __VA_ARGS__)
#define log_warn(ctx, id, ...) \
xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, 0, id, __VA_ARGS__)
#define log_vrb(ctx, vrb, id, ...) \
xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, (vrb), id, __VA_ARGS__)
#define log_err(ctx, id, ...) \
xkb_log_with_code((ctx), XKB_LOG_LEVEL_ERROR, 0, id, __VA_ARGS__)
#define log_wsgo(ctx, id, ...) \
xkb_log_with_code((ctx), XKB_LOG_LEVEL_CRITICAL, 0, id, __VA_ARGS__)
#define log_vrb(ctx, vrb, id, ...) \
xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, (vrb), id, __VA_ARGS__)

/*
* Variants which are prefixed by the name of the function they're
* called from.
* Here we must have the silly 1 variant.
*/
#define log_err_func(ctx, fmt, ...) \
log_err(ctx, XKB_LOG_MESSAGE_NO_ID, "%s: " fmt, __func__, __VA_ARGS__)
#define log_err_func1(ctx, fmt) \
log_err(ctx, XKB_LOG_MESSAGE_NO_ID, "%s: " fmt, __func__)
#define log_err_func(ctx, id, fmt, ...) \
log_err(ctx, id, "%s: " fmt, __func__, __VA_ARGS__)
#define log_err_func1(ctx, id, fmt) \
log_err(ctx, id, "%s: " fmt, __func__)

#endif
27 changes: 18 additions & 9 deletions src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ xkb_keymap_new_from_names(struct xkb_context *ctx,

ops = get_keymap_format_ops(format);
if (!ops || !ops->keymap_new_from_names) {
log_err_func(ctx, "unsupported keymap format: %d\n", format);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unsupported keymap format: %d\n", format);
return NULL;
}

if (flags & ~(XKB_KEYMAP_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

Expand Down Expand Up @@ -176,17 +178,20 @@ xkb_keymap_new_from_buffer(struct xkb_context *ctx,

ops = get_keymap_format_ops(format);
if (!ops || !ops->keymap_new_from_string) {
log_err_func(ctx, "unsupported keymap format: %d\n", format);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unsupported keymap format: %d\n", format);
return NULL;
}

if (flags & ~(XKB_KEYMAP_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

if (!buffer) {
log_err_func1(ctx, "no buffer specified\n");
log_err_func1(ctx, XKB_LOG_MESSAGE_NO_ID,
"no buffer specified\n");
return NULL;
}

Expand Down Expand Up @@ -217,17 +222,20 @@ xkb_keymap_new_from_file(struct xkb_context *ctx,

ops = get_keymap_format_ops(format);
if (!ops || !ops->keymap_new_from_file) {
log_err_func(ctx, "unsupported keymap format: %d\n", format);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unsupported keymap format: %d\n", format);
return NULL;
}

if (flags & ~(XKB_KEYMAP_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

if (!file) {
log_err_func1(ctx, "no file specified\n");
log_err_func1(ctx, XKB_LOG_MESSAGE_NO_ID,
"no file specified\n");
return NULL;
}

Expand All @@ -254,7 +262,8 @@ xkb_keymap_get_as_string(struct xkb_keymap *keymap,

ops = get_keymap_format_ops(format);
if (!ops || !ops->keymap_get_as_string) {
log_err_func(keymap->ctx, "unsupported keymap format: %d\n", format);
log_err_func(keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
"unsupported keymap format: %d\n", format);
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t kc,
case XKB_CONSUMED_MODE_GTK:
break;
default:
log_err_func(state->keymap->ctx,
log_err_func(state->keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized consumed modifiers mode: %d\n", mode);
return 0;
}
Expand Down
6 changes: 4 additions & 2 deletions src/x11/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,12 +1143,14 @@ xkb_x11_keymap_new_from_device(struct xkb_context *ctx,
const enum xkb_keymap_format format = XKB_KEYMAP_FORMAT_TEXT_V1;

if (flags & ~(XKB_KEYMAP_COMPILE_NO_FLAGS)) {
log_err_func(ctx, "unrecognized flags: %#x\n", flags);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"unrecognized flags: %#x\n", flags);
return NULL;
}

if (device_id < 0 || device_id > 127) {
log_err_func(ctx, "illegal device ID: %d\n", device_id);
log_err_func(ctx, XKB_LOG_MESSAGE_NO_ID,
"illegal device ID: %d\n", device_id);
return NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion src/x11/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ xkb_x11_state_new_from_device(struct xkb_keymap *keymap,
struct xkb_state *state;

if (device_id < 0 || device_id > 255) {
log_err_func(keymap->ctx, "illegal device ID: %d", device_id);
log_err_func(keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
"illegal device ID: %d", device_id);
return NULL;
}

Expand Down

0 comments on commit ef65939

Please sign in to comment.