Helper key-value info logging

This commit is contained in:
Wilson Lin 2018-07-06 17:01:50 +12:00
parent 379bc32985
commit cd306005bb
1 changed files with 12 additions and 0 deletions

View File

@ -17,6 +17,8 @@
#define PC_RESET "\x1B[0m"
#define PC_BOLD "\e[1m"
#define _HBE_KV_LOGLINE_LEFTWIDTH "35"
typedef enum hbe_errcode {
HBE_INTERR_PEEK_OFFSET_GEQ_ZERO = 1,
@ -51,6 +53,16 @@ void hbe_debug(char *fmt, ...) {
fprintf(stderr, "\n");
va_end(args);
}
void hbe_info_kv_boolean(char *name, int state) {
const char *color = state ? (PC_BOLD PC_GRN) : PC_MAG;
const char *label = state ? "ON" : "OFF";
hbe_info("%-" _HBE_KV_LOGLINE_LEFTWIDTH "s%s%s" PC_RESET, name, color, label);
}
void hbe_info_kv_string(char *name, char *value) {
hbe_info("%-" _HBE_KV_LOGLINE_LEFTWIDTH "s" PC_BOLD "%s" PC_RESET, name, value);
}
void hbe_warn(char *fmt, ...) {
va_list args;