manawyrm has uploaded this change for review.

View Change

logging: ensure ANSI color escape is sent in same line/before newline

This fixes multi-line color clobbering in logging daemons like
systemd-journald, which work with single-lines only.

Change-Id: Ia7de9d88aa5ac48ec0d5c1a931a89d21c02c5433
---
M src/core/logging.c
1 file changed, 21 insertions(+), 1 deletion(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/75/34975/1
diff --git a/src/core/logging.c b/src/core/logging.c
index c6774f5..87654ac 100644
--- a/src/core/logging.c
+++ b/src/core/logging.c
@@ -616,7 +616,15 @@
}

if (target->use_color && c_subsys) {
- ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END);
+ /* Ensure the last color escape is sent before the newline
+ * (to not clobber journald, which works on single-lines only) */
+ if (offset > 0 && buf[offset - 1] == '\n') {
+ offset--; rem++;
+ ret = snprintf(buf + offset, rem, "%s\n", OSMO_LOGCOLOR_END);
+ } else {
+ ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END);
+ }
+
if (ret < 0)
goto err;
OSMO_SNPRINTF_RET(ret, rem, offset, len);

To view, visit change 34975. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia7de9d88aa5ac48ec0d5c1a931a89d21c02c5433
Gerrit-Change-Number: 34975
Gerrit-PatchSet: 1
Gerrit-Owner: manawyrm <osmocom.account@tbspace.de>
Gerrit-MessageType: newchange