24

The output of journalctl really looks messy without colors. Is it possible to add colors to its output? On my system it seems only important lines are highlighted. Even dmesg can output with color by adding the --color switch!

xuhdev
  • 800
  • 2
  • 6
  • 19

6 Answers6

34

If the original daemon output is already colorized, but the colors are being lost when using journalctl, the --output cat option will restore them. See the manual for more details.

danielkza
  • 453
  • 4
  • 6
15

Install ccze, then use it like this:

journalctl -b -k -f | ccze [-A] [-o nolookups]

explanation:

 -A, --raw-ansi
        If one wants to enable raw ANSI color sequences instead of using curses, this option does just that.
 -o, --options OPTIONS...
        However,  lookups  is  an  option that might be better to disable. When on, ccze will try to look up usernames, service
        names, and lots of other stuff, which will slow down coloring a great deal. If one is piping a long log  through  ccze,
        this option might be turned off [nolookups]  to speed up the process.
eMPee584
  • 115
  • 4
user404151
  • 151
  • 1
  • 2
  • 3
    Please add some more information and examples to your answer. ccze seems like a nice utility but some useful example commands would improve your answer – Frederik Mar 07 '17 at 15:02
  • This should be the selected answer. – Nam G VU Jul 17 '18 at 03:06
  • While ccze is interesting, this answer drops the colors from journalctl and then asks ccze to _guess_ different colors. The `journalctl` flags are unrelated to the question. Look elsewhere. – MarcH May 21 '20 at 06:45
8

The color support of journalctl is documented in man journalctl:

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; other lines are displayed normally.

That's from systemd 229. As seen in the man page, There are no other built-in color controls for journalctl.

Mark Stosberg
  • 3,771
  • 23
  • 27
  • Can have color with `ccze` as discussed below https://serverfault.com/a/836777 – Nam G VU Jul 17 '18 at 03:05
  • 1
    Using different prio does the trick for me. Customised my terminal to display bold in a different color from normal. This gives three colors: prio0,1,2,3 prio 4,5 and prio6,7. Does the trick for me! – jorijnsmit Oct 09 '18 at 16:40
  • 2
    In 2020 there is now, from `man journalctl`: `SYSTEMD_COLORS=true journalctl --boot > log.ansi` – MarcH May 21 '20 at 06:42
5

I use ccze for all the logs.

Example for jornalctl with color.

journalctl -b -k -f | ccze
journalctl -b -k -f | ccze -A

Other examples.

tail -f /etc/nginx/logs/access.log | ccze
tail -f /etc/unbound/unbound.log | ccze

Exporting logs

to export the log to HTML and save it to /root/syslog.html:

ccze -h -o nolookups /root/syslog.html 

I hope you find it useful.

Katie
  • 103
  • 4
javier
  • 61
  • 1
  • 2
  • 3
    Please edit this into your other answer on this question. This seems to be a continuation and shouldn't stand on its own. – Henrik Pingel Mar 29 '17 at 20:36
3

Seeking long for the answer, I actually figured out what works for me (with Rails logs and journalctl) – just add --all option.

journalctl -u puma --all

From manpage:

   -a, --all
      Show all fields in full, even if they include unprintable characters 
      or are very long. By default, fields with unprintable characters 
      are abbreviated as "blob data". (Note that the pager may escape 
      unprintable characters again.)
urmurmur
  • 131
  • 1
1

It gives color to log files and command outputs.

ccze -A

tail -f /var/log/syslog | ccze dit to execute tail -f /var/log/syslog but here it shows with colors, another form could be ccze -A

ccze -A

ccze -h -o nolookups /root/syslog.html exports the log to HTML and saves it to /root/syslog.html.

javier
  • 61
  • 1
  • 2
  • 3
    Please edit this into your other answer on this question. This seems to be a continuation and shouldn't stand on its own. – chicks Mar 09 '17 at 02:10