journalctl:如何在其输出中显示颜色?

xuh*_*dev 16 systemd journalctl

journalctl没有颜色的输出确实看起来很乱。是否可以为其输出添加颜色?在我的系统上,似乎只有重要的行被突出显示。甚至dmesg可以通过添加--color开关来输出颜色!

小智 22

如果原始守护程序输出已经着色,但使用 时颜色丢失journalctl,该--output cat选项将恢复它们。有关更多详细信息,请参阅手册


小智 11

安装ccze,然后像这样使用它:

journalctl -b -k -f | ccze [-A] [-o nolookups]
Run Code Online (Sandbox Code Playgroud)

解释:

 -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.
Run Code Online (Sandbox Code Playgroud)

  • 请在您的答案中添加更多信息和示例。ccze 似乎是一个不错的实用程序,但一些有用的示例命令会改善您的答案 (3认同)

Mar*_*erg 7

的颜色支持journalctl记录在man journalctl

输出到 tty 时,根据优先级对行进行着色:级别 ERROR 及更高级别的行着色为红色;级别 NOTICE 和更高级别的行被突出显示;其他线路正常显示。

那来自 systemd 229。如手册页中所示,没有其他内置颜色控件用于journalctl.

  • 在 2020 年,现在来自“manjournalctl”:“SYSTEMD_COLORS=truejournalctl --boot > log.ansi” (4认同)

小智 7

我用于ccze所有日志。

带颜色的 jernalctl 示例。

journalctl -b -k -f | ccze
journalctl -b -k -f | ccze -A
Run Code Online (Sandbox Code Playgroud)

其他例子。

tail -f /etc/nginx/logs/access.log | ccze
tail -f /etc/unbound/unbound.log | ccze
Run Code Online (Sandbox Code Playgroud)

导出日志

将日志导出为 HTML 并将其保存到 /root/syslog.html:

ccze -h -o nolookups /root/syslog.html 
Run Code Online (Sandbox Code Playgroud)

希望对你有帮助。

  • 请将其编辑到您对此问题的其他答案中。这似乎是一个延续,不应该独立存在。 (3认同)

小智 6

长期寻找答案,我实际上找到了对我有用的方法(使用Rails日志和journalctl)\xe2\x80\x93只需添加--all选项。

\n
journalctl -u puma --all\n
Run Code Online (Sandbox Code Playgroud)\n

来自联机帮助页:

\n
\n
   -a, --all\n      Show all fields in full, even if they include unprintable characters \n      or are very long. By default, fields with unprintable characters \n      are abbreviated as "blob data". (Note that the pager may escape \n      unprintable characters again.)\n
Run Code Online (Sandbox Code Playgroud)\n
\n