36

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!

2
  • 2
    The question would be improved if you provided some indication you'd checked the documentation of journalct before asking. Commented Sep 28, 2016 at 15:10
  • 1
    have the same problem, ccze too slow for me..
    – Kokizzu
    Commented Mar 25, 2017 at 7:51

6 Answers 6

11

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.

3
  • Can have color with ccze as discussed below serverfault.com/a/836777
    – Nam G VU
    Commented Jul 17, 2018 at 3: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!
    – gosuto
    Commented Oct 9, 2018 at 16:40
  • 5
    In 2020 there is now, from man journalctl: SYSTEMD_COLORS=true journalctl --boot > log.ansi
    – MarcH
    Commented May 21, 2020 at 6:42
46

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.

3
  • 1
    This is the correct answer, please.
    – fiatjaf
    Commented Feb 11, 2019 at 22:58
  • 1
    I came here to find this answer.
    – lubosz
    Commented Sep 8, 2020 at 22:57
  • 1
    This does not work for me and the original logs do have some color and bold formatting. What might I be doing wrong? Commented Nov 27, 2020 at 7:21
16

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.
3
  • 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
    Commented Mar 7, 2017 at 15:02
  • This should be the selected answer.
    – Nam G VU
    Commented Jul 17, 2018 at 3:06
  • 2
    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
    Commented May 21, 2020 at 6:45
6

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.

2
  • 5
    Please edit this into your other answer on this question. This seems to be a continuation and shouldn't stand on its own. Commented Mar 29, 2017 at 20:36
  • seems pager of journalctl will disable
    – yurenchen
    Commented Apr 7, 2023 at 16:55
6

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.)
-1

It gives color to log files and command outputs:

  1. ccze -A </etc/nsswitch.conf | cat shows nsswitch.conf with colors, another way could be cat /etc/nsswitch.conf | ccze -A

  2. 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 </var/log/syslog | less -R

  3. ccze -A </home/pepe.txt | less -R idem. To run less /home/pepe.txt but displays it with colors.

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

1
  • 7
    Please edit this into your other answer on this question. This seems to be a continuation and shouldn't stand on its own.
    – chicks
    Commented Mar 9, 2017 at 2:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .