diff options
-rw-r--r-- | include/osmocom/core/logging.h | 19 | ||||
-rw-r--r-- | src/logging.c | 16 | ||||
-rw-r--r-- | tests/logging/logging_test.c | 6 | ||||
-rw-r--r-- | tests/loggingrb/loggingrb_test.c | 6 |
4 files changed, 33 insertions, 14 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 139d2916..75650ba8 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -127,6 +127,25 @@ void logp(int subsys, const char *file, int line, int cont, const char *format, #define DLRSPRO -19 /*!< Osmocom Remote SIM Protocol */ #define OSMO_NUM_DLIB 19 /*!< Number of logging sub-systems in libraries */ +/* Colors that can be used in log_info_cat.color */ +#define OSMO_LOGCOLOR_NORMAL NULL +#define OSMO_LOGCOLOR_RED "\033[1;31m" +#define OSMO_LOGCOLOR_GREEN "\033[1;32m" +#define OSMO_LOGCOLOR_YELLOW "\033[1;33m" +#define OSMO_LOGCOLOR_BLUE "\033[1;34m" +#define OSMO_LOGCOLOR_PURPLE "\033[1;35m" +#define OSMO_LOGCOLOR_CYAN "\033[1;36m" +#define OSMO_LOGCOLOR_DARKRED "\033[31m" +#define OSMO_LOGCOLOR_DARKGREEN "\033[32m" +#define OSMO_LOGCOLOR_DARKYELLOW "\033[33m" +#define OSMO_LOGCOLOR_DARKBLUE "\033[34m" +#define OSMO_LOGCOLOR_DARKPURPLE "\033[35m" +#define OSMO_LOGCOLOR_DARKCYAN "\033[36m" +#define OSMO_LOGCOLOR_DARKGREY "\033[1;30m" +#define OSMO_LOGCOLOR_GREY "\033[37m" +#define OSMO_LOGCOLOR_BRIGHTWHITE "\033[1;37m" +#define OSMO_LOGCOLOR_END "\033[0;m" + /*! Configuration of single log category / sub-system */ struct log_category { uint8_t loglevel; /*!< configured log-level */ 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); diff --git a/tests/logging/logging_test.c b/tests/logging/logging_test.c index 8fd71d0c..b9cb57fb 100644 --- a/tests/logging/logging_test.c +++ b/tests/logging/logging_test.c @@ -37,19 +37,19 @@ static const struct log_info_cat default_categories[] = { [DRLL] = { .name = "DRLL", .description = "A-bis Radio Link Layer (RLL)", - .color = "\033[1;31m", + .color = OSMO_LOGCOLOR_RED, .enabled = 1, .loglevel = LOGL_NOTICE, }, [DCC] = { .name = "DCC", .description = "Layer3 Call Control (CC)", - .color = "\033[1;32m", + .color = OSMO_LOGCOLOR_GREEN, .enabled = 1, .loglevel = LOGL_NOTICE, }, [DMM] = { .name = NULL, .description = "Layer3 Mobility Management (MM)", - .color = "\033[1;33m", + .color = OSMO_LOGCOLOR_YELLOW, .enabled = 1, .loglevel = LOGL_NOTICE, }, }; diff --git a/tests/loggingrb/loggingrb_test.c b/tests/loggingrb/loggingrb_test.c index 3372c0c3..0b2ae5b5 100644 --- a/tests/loggingrb/loggingrb_test.c +++ b/tests/loggingrb/loggingrb_test.c @@ -34,19 +34,19 @@ static const struct log_info_cat default_categories[] = { [DRLL] = { .name = "DRLL", .description = "A-bis Radio Link Layer (RLL)", - .color = "\033[1;31m", + .color = OSMO_LOGCOLOR_RED, .enabled = 1, .loglevel = LOGL_NOTICE, }, [DCC] = { .name = "DCC", .description = "Layer3 Call Control (CC)", - .color = "\033[1;32m", + .color = OSMO_LOGCOLOR_GREEN, .enabled = 1, .loglevel = LOGL_NOTICE, }, [DMM] = { .name = NULL, .description = "Layer3 Mobility Management (MM)", - .color = "\033[1;33m", + .color = OSMO_LOGCOLOR_BLUE, .enabled = 1, .loglevel = LOGL_NOTICE, }, }; |