From f2644aee5525a6f889816c3e0d613e3c7145d01d Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 20 Nov 2019 04:00:29 +0100 Subject: logging.h: define ansi color constants It's hard to figure out what color logging categories have with those ANSI color code strings. Instead, define these OSMO_LOGCOLOR_* constants. Naming: commonly, the logging.h header has the "LOG" prefix in the name, but it seems saner to include the OSMO_ prefix: it seems too likely that some libosmocore user somewhere already has defined "LOGCOLOR_RED" somewhere. Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a --- src/logging.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/logging.c b/src/logging.c index b030f8a6..7baa7778 100644 --- a/src/logging.c +++ b/src/logging.c @@ -344,11 +344,11 @@ static const char* color(int subsys) } static const struct value_string level_colors[] = { - { LOGL_DEBUG, "\033[1;34m" }, - { LOGL_INFO, "\033[1;32m" }, - { LOGL_NOTICE, "\033[1;33m" }, - { LOGL_ERROR, "\033[1;31m" }, - { LOGL_FATAL, "\033[1;31m" }, + { LOGL_DEBUG, OSMO_LOGCOLOR_BLUE }, + { LOGL_INFO, OSMO_LOGCOLOR_GREEN }, + { LOGL_NOTICE, OSMO_LOGCOLOR_YELLOW }, + { LOGL_ERROR, OSMO_LOGCOLOR_RED }, + { LOGL_FATAL, OSMO_LOGCOLOR_RED }, { 0, NULL } }; @@ -428,7 +428,7 @@ static void _output(struct log_target *target, unsigned int subsys, ret = snprintf(buf + offset, rem, "%s%s%s%s ", target->use_color ? level_color(level) : "", log_category_name(subsys), - target->use_color ? "\033[0;m" : "", + target->use_color ? OSMO_LOGCOLOR_END : "", c_subsys ? c_subsys : ""); if (ret < 0) goto err; @@ -438,7 +438,7 @@ static void _output(struct log_target *target, unsigned int subsys, ret = snprintf(buf + offset, rem, "%s%s%s%s ", target->use_color ? level_color(level) : "", log_level_str(level), - target->use_color ? "\033[0;m" : "", + target->use_color ? OSMO_LOGCOLOR_END : "", c_subsys ? c_subsys : ""); if (ret < 0) goto err; @@ -501,7 +501,7 @@ static void _output(struct log_target *target, unsigned int subsys, } if (target->use_color) { - ret = snprintf(buf + offset, rem, "\033[0;m"); + ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END); if (ret < 0) goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); -- cgit v1.2.3