mirror of https://gerrit.osmocom.org/libosmocore
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 Closes: OS#6249
This commit is contained in:
parent
4ca0f62cc4
commit
11a416827d
|
@ -616,7 +616,15 @@ static int _output_buf(char *buf, int buf_len, struct log_target *target, unsign
|
|||
}
|
||||
|
||||
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, OSMO_LOGCOLOR_END "\n");
|
||||
} else {
|
||||
ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
OSMO_SNPRINTF_RET(ret, rem, offset, len);
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
[1;31mYou should see this
|
||||
[0;m[1;32mYou should see this
|
||||
[0;m
|
||||
[1;31mYou should see this[0;m
|
||||
[1;32mYou should see this[0;m
|
||||
|
|
Loading…
Reference in New Issue