[MERGED] libosmocore[master]: logging: color the log category according to level

2018-01-17 Thread Harald Welte
Harald Welte has submitted this change and it was merged.

Change subject: logging: color the log category according to level
..


logging: color the log category according to level

When log_set_use_color() is enabled, color the log category string according to
the log level. The log line before and after the log category is printed in the
category's configured color.

ERROR and FATAL are red, NOTICE is yellow, INFO is green and DEBUG is blue.

The default behavior remains unchanged; If color is enabled, the category
string will now always be colored in the log level color, not the log category
color, and will stand out from the rest of the line.

Change-Id: I84f886ac880e9056a666bbb231ae06cbaaf65f44
---
M src/logging.c
1 file changed, 5 insertions(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/logging.c b/src/logging.c
index c01294c..a6aa7eb 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -366,7 +366,11 @@
OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
if (target->print_category) {
-   ret = snprintf(buf + offset, rem, "%s ", 
log_category_name(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" : "",
+  c_subsys ? c_subsys : "");
if (ret < 0)
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);

-- 
To view, visit https://gerrit.osmocom.org/5811
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I84f886ac880e9056a666bbb231ae06cbaaf65f44
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder


libosmocore[master]: logging: color the log category according to level

2018-01-16 Thread Harald Welte

Patch Set 1: Code-Review+2

-- 
To view, visit https://gerrit.osmocom.org/5811
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I84f886ac880e9056a666bbb231ae06cbaaf65f44
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-HasComments: No


[PATCH] libosmocore[master]: logging: color the log category according to level

2018-01-15 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/5811

logging: color the log category according to level

When log_set_use_color() is enabled, color the log category string according to
the log level. The log line before and after the log category is printed in the
category's configured color.

ERROR and FATAL are red, NOTICE is yellow, INFO is green and DEBUG is blue.

The default behavior remains unchanged; If color is enabled, the category
string will now always be colored in the log level color, not the log category
color, and will stand out from the rest of the line.

Change-Id: I84f886ac880e9056a666bbb231ae06cbaaf65f44
---
M src/logging.c
1 file changed, 5 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/11/5811/1

diff --git a/src/logging.c b/src/logging.c
index c01294c..a6aa7eb 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -366,7 +366,11 @@
OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
if (target->print_category) {
-   ret = snprintf(buf + offset, rem, "%s ", 
log_category_name(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" : "",
+  c_subsys ? c_subsys : "");
if (ret < 0)
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);

-- 
To view, visit https://gerrit.osmocom.org/5811
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I84f886ac880e9056a666bbb231ae06cbaaf65f44
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr