Enable toggling info logging
This commit is contained in:
parent
a67257d740
commit
b4d5ae92cb
|
@ -39,14 +39,28 @@ typedef enum hbe_errcode {
|
|||
HBE_PARSE_EXPECTED_NOT_FOUND,
|
||||
} hbe_errcode_t;
|
||||
|
||||
static char *hbe_fatal_autodelete_file = NULL;
|
||||
static char *_hbe_fatal_autodelete_file = NULL;
|
||||
static int _hbe_info_enabled = 0;
|
||||
|
||||
void hbe_fatal_set_autodelete(char *path) {
|
||||
hbe_fatal_autodelete_file = path;
|
||||
_hbe_fatal_autodelete_file = path;
|
||||
}
|
||||
|
||||
void hbe_info_toggle(int log_info) {
|
||||
_hbe_info_enabled = log_info;
|
||||
}
|
||||
|
||||
void hbe_info(char *fmt, ...) {
|
||||
if (_hbe_info_enabled) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fprintf(stderr, PC_MAG "[INFO] " PC_RESET);
|
||||
vfprintf(stderr, fmt, args);
|
||||
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";
|
||||
|
@ -75,9 +89,9 @@ void hbe_fatal(hbe_errcode_t errcode, char *fmt, ...) {
|
|||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
|
||||
if (hbe_fatal_autodelete_file != NULL) {
|
||||
if (unlink(hbe_fatal_autodelete_file)) {
|
||||
hbe_warn("Failed to delete file %s with error %d", hbe_fatal_autodelete_file, errno);
|
||||
if (_hbe_fatal_autodelete_file != NULL) {
|
||||
if (unlink(_hbe_fatal_autodelete_file)) {
|
||||
hbe_warn("Failed to delete file %s with error %d", _hbe_fatal_autodelete_file, errno);
|
||||
} else {
|
||||
hbe_info("%s has been deleted", _hbe_fatal_autodelete_file);
|
||||
}
|
||||
|
|
|
@ -28,13 +28,14 @@ int main(int argc, char **argv) {
|
|||
static struct option long_options[] = {
|
||||
{"keep", no_argument, NULL, 'k'},
|
||||
{"buffer", no_argument, NULL, 'b'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"input", required_argument, NULL, 'i'},
|
||||
{"output", required_argument, NULL, 'o'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int option_index = 0;
|
||||
int c = getopt_long(argc, argv, "kbi:o:", long_options, &option_index);
|
||||
int c = getopt_long(argc, argv, "kbvi:o:", long_options, &option_index);
|
||||
|
||||
if (c == -1) {
|
||||
break;
|
||||
|
@ -56,6 +57,10 @@ int main(int argc, char **argv) {
|
|||
case 'b':
|
||||
config_buffer = 1;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
hbe_info_toggle(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue