Score:0

Setting the color for warnings from journalctl output

cn flag

The journalctl command will color-code its messages. From its manual page:

When outputting to a tty, lines are colored according to priority: lines of level ERROR and higher are colored red; lines of level NOTICE and higher are highlighted; lines of level DEBUG are colored lighter grey; other lines are displayed normally.

Red is red, on any of my systems. But the notion of 'highlighted' changes from system to system.

For instance gnome terminal (with TERM=xterm-256color) uses this yellow for one machine:

colors on local system

But when doing an ssh into a second machine, the same journalctl and the same TERM var, and the same terminal, shows as:

colors after ssh into remote system

So the colors of "highlighting" must have been set outside the terminal configuration, and is host dependent. The question is: where is it defined?

NOTE: There is a gnome terminal preference setting (Preferences/Profile/Colors/Highlight color) but this controls something completely different! When I set that, it changes the "selection color" so when I select text in the terminal with the mouse. Apparently the term highlight color is ambiguous here, and can mean different things.

Selection colour

The screenshot above shows "highlight color" but would be better called "selection color" as that is what changes when I set it.

How does systemctl define the "highlight color" for a terminal? And why does the terminal highlight color change when I login remotely into another system?

Both these systems run Ubuntu 23.04 OS.

Both systems run the same version of systemd.

Both systems have an empty configuration in /etc/systemd/journald.conf

cn flag
GNOME Terminal's "highlight color" is for the mouse selection and for search results. Calling it "selection color" might be more intuitive but not quite correct (as it would reflect only one of these two). If an app switches to a different color or bold typeface, obviously the terminal has no idea whether it happens for highlighting purposes or for some other purpose, it's just colors and font weight, as asked by the application (journalctl in this case). The difference should be somewhere in journalctl's configuration or built-in behavior (I can't help you with that, sorry), if at all...
cn flag
... By the way, are you sure that journalctl is configured differently at all? The two screenshots show different messages. Maybe both systems are configured identically, to use brown for "hpet_acpi_add", yellow for "ipni_si" etc. At least, this possibility can't be excluded based on your screenshots.
cn flag
When an app gives a piece of text to the terminal, it can tell it to switch to a certain (background and/or foreground) color or tell it to switch to another typeface (e.g. bold, italic), and sometimes (if you enable that legacy option at the bottom of the prefs window you show) bold typeface also implies a brighter version of the default foreground color. But (what you get conceptually wrong): there's no generic instruction to "highlight" a text, leaving it up to the terminal how it interprets that. There is no "notion of highlighted" as you imagine it.
Bram avatar
cn flag
@egmont In all fairness, that means the journalctl manual page gets it *conceptionally wrong* as you put it. Why state 'red' for error, but use the term 'highlight' for warning?
cn flag
Yup, you're right. As you've also elaborated in your answer, this is an error in its manual page.
Score:0
cn flag

First off, the manual page is confusing. When it says "lines of level NOTICE and higher are highlighted," it really means that it is colored yellow.

This is a documentation bug.

In the code, there is a concept of ansi_highlight_yellow() which caused this confusion in the manual page.

This yellow ANSI color code is hard-coded, and not configurable.

The reason that my two machines showed a different color for warnings in the system log is caused by color precision.

The environment variable SYSTEMD_COLORS is not just a boolean, as it takes special values 16 and 256.

Because one machine was set to output 256-colors and the other to output 16-colors, the result was different.

When I set the SYSTEMD_COLORS variable the same, I observe the same colors.

In conclusion, the colors cannot be set, they are simply RED, YELLOW, GREY and un-colored. How they appear on-screen depends on whether the terminal is showing 16-colors or 256-colors, which in turn depends on the environment variable.

cn flag
Again, poor wording in `journalctl`'s manual :( It begins by saying "Takes a boolean argument" and two sentences later it says it can also take 16 and 256. Geez, if the values 16 and 256 have special meaning then don't say it takes a boolean, dear systemd developers, just don't.
cn flag
Looks like by "highlighted" the systemd guys mean the escape sequence SGR 1, defined in ECMA-48 as "bold or increased intensity". Traditionally, due to hardware limitations, this was often implemented as "increased intensity" a.k.a. "bright", often combined with "bold" typeface as well. Recently, with 256-color support as well as truecolor RGB support emerging in terminal emulators, the behavior has shifted towards "bold" typeface only, not tampering with the colors. In GNOME Terminal this is subject to the "Show bold text in bright colors" at the bottom of your screenshot...
cn flag
Note, however, that brightening the colors only works (if enabled at all) for the 8 legacy colors (by switchting to their counterpart among the next 8 colors). Those second 8 colors of the 16-color palette, as well the extended 256-color or truecolor values aren't brightened. Also, the first 8 colors aren't brightened if they are referred to using the 256-color escape sequences. (Huhh, complicated, right?)
cn flag
In systemd's code, as you pointed, `_ANSI_HIGHLIGHT_YELLOW` (with an underscore prefix) is defined to use the legacy "yellow" (often brown), which is subject to this brigtening, thus becoming real yellow. But then the non-underscored `ANSI_HIGHLIGHT_YELLOW`, aliased to `KHAKI3`, won't be brightened by making it bold because it's slot 185 from the 256-color palette. It's easily possible that the two systems you're using have different systemd versions and thus emit a different variant of yellow.
Bram avatar
cn flag
@egmont, no, I use the same systemd. The difference is purely due to the different value for SYSTEMD_COLORS. When that var is the same, the behaviour is the same.
cn flag
Indeed, I didn't take your answer into account, my bad... I should have said that a different systemd version, if they changed the definition of their yellow, _could have been_ another cause for this symptom :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.