color logging

This commit is contained in:
Devaev Maxim
2019-09-06 22:26:15 +03:00
parent 2dbaf08eb0
commit 93d5be6ffc
5 changed files with 64 additions and 40 deletions

View File

@@ -109,10 +109,12 @@ enum _OPT_VALUES {
_O_GPIO_WORKERS_BUSY_AT,
#endif
_O_LOG_LEVEL,
_O_PERF,
_O_VERBOSE,
_O_DEBUG,
_O_LOG_LEVEL
_O_FORCE_COLORS,
_O_NO_COLORS,
};
static const struct option _LONG_OPTS[] = {
@@ -174,12 +176,16 @@ static const struct option _LONG_OPTS[] = {
{"gpio-workers-busy-at", required_argument, NULL, _O_GPIO_WORKERS_BUSY_AT},
#endif
{"log-level", required_argument, NULL, _O_LOG_LEVEL},
{"perf", no_argument, NULL, _O_PERF},
{"verbose", no_argument, NULL, _O_VERBOSE},
{"debug", no_argument, NULL, _O_DEBUG},
{"log-level", required_argument, NULL, _O_LOG_LEVEL},
{"force-colors", no_argument, NULL, _O_FORCE_COLORS},
{"no-colors", no_argument, NULL, _O_NO_COLORS},
{"help", no_argument, NULL, _O_HELP},
{"version", no_argument, NULL, _O_VERSION},
{NULL, 0, NULL, 0},
};
@@ -340,15 +346,18 @@ int parse_options(int argc, char *argv[], struct device_t *dev, struct encoder_t
case _O_GPIO_WORKERS_BUSY_AT: OPT_NUMBER("--gpio-workers-busy-at", gpio_pin_workers_busy_at, 0, 256, 0);
# endif
case _O_PERF: OPT_SET(log_level, LOG_LEVEL_PERF);
case _O_VERBOSE: OPT_SET(log_level, LOG_LEVEL_VERBOSE);
case _O_DEBUG: OPT_SET(log_level, LOG_LEVEL_DEBUG);
case _O_LOG_LEVEL: OPT_NUMBER("--log-level", log_level, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, 0);
case _O_LOG_LEVEL: OPT_NUMBER("--log-level", log_level, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, 0);
case _O_PERF: OPT_SET(log_level, LOG_LEVEL_PERF);
case _O_VERBOSE: OPT_SET(log_level, LOG_LEVEL_VERBOSE);
case _O_DEBUG: OPT_SET(log_level, LOG_LEVEL_DEBUG);
case _O_FORCE_COLORS: OPT_SET(log_colored, true);
case _O_NO_COLORS: OPT_SET(log_colored, false);
case _O_HELP: _help(dev, encoder, server); return 1;
case _O_VERSION: _version(true); return 1;
case 0: break;
default: _help(dev, encoder, server); return -1;
case 0: break;
default: _help(dev, encoder, server); return -1;
}
}
@@ -539,6 +548,8 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
printf(" --perf ────────── Enable performance messages (same as --log-level=1). Default: disabled.\n\n");
printf(" --verbose ─────── Enable verbose messages and lower (same as --log-level=2). Default: disabled.\n\n");
printf(" --debug ───────── Enable debug messages and lower (same as --log-level=3). Default: disabled.\n\n");
printf(" --force-colors ── Force color logging. Default: colored if stdout is a TTY.\n\n");
printf(" --no-colors ───── Disable color logging. Default: ditto.\n\n");
printf("Help options:\n");
printf("═════════════\n");
printf(" -h|--help ─────── Print this text and exit.\n\n");