diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-03-16 11:22:58 +0100 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-03-16 11:22:58 +0100 |
commit | a4180c0fb3a5f7e763c0757cedc791b4e2f9e633 (patch) | |
tree | 93fa94925406b588e546ffab80414fd87a469940 | |
parent | 197dd3a9a4bda2f604b437aa395098622678c416 (diff) | |
download | systemd-a4180c0fb3a5f7e763c0757cedc791b4e2f9e633.tar.gz |
journald-console: Add colors when forwarding to console
Let's color output when we're forwarding to the console. To make this
work, we inherit TERM from pid 1 and use it to decide whether we should
output colors or not.
-rw-r--r-- | src/journal/journald-console.c | 8 | ||||
-rw-r--r-- | units/systemd-journald.service.in | 1 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c index c8a3e18360..8595ba3e45 100644 --- a/src/journal/journald-console.c +++ b/src/journal/journald-console.c @@ -38,13 +38,13 @@ void server_forward_console( const char *message, const struct ucred *ucred) { - struct iovec iovec[5]; + struct iovec iovec[7]; struct timespec ts; char tbuf[STRLEN("[] ") + DECIMAL_STR_MAX(ts.tv_sec) + DECIMAL_STR_MAX(ts.tv_nsec)-3 + 1]; char header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t)]; _cleanup_free_ char *ident_buf = NULL; _cleanup_close_ int fd = -EBADF; - const char *tty; + const char *tty, *color_on = "", *color_off = ""; int n = 0; assert(s); @@ -81,8 +81,12 @@ void server_forward_console( iovec[n++] = IOVEC_MAKE_STRING(": "); } + get_log_colors(LOG_PRI(priority), &color_on, &color_off, NULL); + /* Fourth: message */ + iovec[n++] = IOVEC_MAKE_STRING(color_on); iovec[n++] = IOVEC_MAKE_STRING(message); + iovec[n++] = IOVEC_MAKE_STRING(color_off); iovec[n++] = IOVEC_MAKE_STRING("\n"); tty = s->tty_path ?: "/dev/console"; diff --git a/units/systemd-journald.service.in b/units/systemd-journald.service.in index ece872c770..79ec60c937 100644 --- a/units/systemd-journald.service.in +++ b/units/systemd-journald.service.in @@ -47,6 +47,7 @@ SystemCallArchitectures=native SystemCallErrorNumber=EPERM SystemCallFilter=@system-service Type=notify +PassEnvironment=TERM {{SERVICE_WATCHDOG}} # In case you're wondering why CAP_SYS_PTRACE is needed, access to |