Change in libosmocore[master]: logging.h: define ansi color constants
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/16156 ) Change subject: logging.h: define ansi color constants .. Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16156 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a Gerrit-Change-Number: 16156 Gerrit-PatchSet: 2 Gerrit-Owner: neels Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Reviewer: laforge Gerrit-Comment-Date: Sat, 23 Nov 2019 07:58:29 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: logging.h: define ansi color constants
laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/16156 ) Change subject: logging.h: define ansi color constants .. 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 --- M include/osmocom/core/logging.h M src/logging.c M tests/logging/logging_test.c M tests/loggingrb/loggingrb_test.c 4 files changed, 33 insertions(+), 14 deletions(-) Approvals: laforge: Looks good to me, approved fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 139d291..75650ba 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -127,6 +127,25 @@ #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 b030f8a..7baa777 100644 --- a/src/logging.c +++ b/src/logging.c @@ -344,11 +344,11 @@ } 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 @@ 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 @@ 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 @@ } 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 8fd71d0..b9cb57f 100644 --- a/tests/logging/logging_test.c +++ b/tests/logging/logging_test.c @@ -37,19 +37,19 @@ [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 =
Change in libosmocore[master]: logging.h: define ansi color constants
fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/16156 ) Change subject: logging.h: define ansi color constants .. Patch Set 2: On the other hand, we may want to use these constants from other osmo-* projects... -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16156 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a Gerrit-Change-Number: 16156 Gerrit-PatchSet: 2 Gerrit-Owner: neels Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-CC: laforge Gerrit-Comment-Date: Fri, 22 Nov 2019 15:07:09 + Gerrit-HasComments: No Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in libosmocore[master]: logging.h: define ansi color constants
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/16156 ) Change subject: logging.h: define ansi color constants .. Patch Set 2: (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/16156/2//COMMIT_MSG Commit Message: https://gerrit.osmocom.org/c/libosmocore/+/16156/2//COMMIT_MSG@12 PS2, Line 12: the "LOG" prefix > Do we really need to expose these color constants? If no, you can just put > them into logging_interna […] very good idea! -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16156 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a Gerrit-Change-Number: 16156 Gerrit-PatchSet: 2 Gerrit-Owner: neels Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-CC: laforge Gerrit-Comment-Date: Fri, 22 Nov 2019 10:42:59 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: fixeria Gerrit-MessageType: comment
Change in libosmocore[master]: logging.h: define ansi color constants
fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/16156 ) Change subject: logging.h: define ansi color constants .. Patch Set 2: Code-Review+1 (1 comment) https://gerrit.osmocom.org/c/libosmocore/+/16156/2//COMMIT_MSG Commit Message: https://gerrit.osmocom.org/c/libosmocore/+/16156/2//COMMIT_MSG@12 PS2, Line 12: the "LOG" prefix Do we really need to expose these color constants? If no, you can just put them into logging_internal.h, so there would be no need to use 'OSMO_' prefix. -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16156 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a Gerrit-Change-Number: 16156 Gerrit-PatchSet: 2 Gerrit-Owner: neels Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-Comment-Date: Fri, 22 Nov 2019 09:01:32 + Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in libosmocore[master]: logging.h: define ansi color constants
Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/16156 to look at the new patch set (#2). Change subject: logging.h: define ansi color constants .. 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 --- M include/osmocom/core/logging.h M src/logging.c M tests/logging/logging_test.c M tests/loggingrb/loggingrb_test.c 4 files changed, 33 insertions(+), 14 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/56/16156/2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16156 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a Gerrit-Change-Number: 16156 Gerrit-PatchSet: 2 Gerrit-Owner: neels Gerrit-Reviewer: Jenkins Builder Gerrit-MessageType: newpatchset
Change in libosmocore[master]: logging.h: define ansi color constants
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/16156 ) Change subject: logging.h: define ansi color constants .. 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 --- M include/osmocom/core/logging.h 1 file changed, 18 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/56/16156/1 diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index 139d291..0846c1b 100644 --- a/include/osmocom/core/logging.h +++ b/include/osmocom/core/logging.h @@ -127,6 +127,24 @@ #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" + /*! Configuration of single log category / sub-system */ struct log_category { uint8_t loglevel; /*!< configured log-level */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/16156 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I03b6b1f73ae7ee61d37ff921e071a3d0881d3e9a Gerrit-Change-Number: 16156 Gerrit-PatchSet: 1 Gerrit-Owner: neels Gerrit-MessageType: newchange