systemd的journalctl:如何按消息过滤?

journalctl看起来像是一个很好的工具来查看日志,但我坚持什么感觉就像一个简单的问:我想看到包含短语update-ipsets所有cron消息。

当然,我可以做到这一点

 journalctl -u cron.service | grep update-ipsets 

但是你却失去了journalctl输出的所有其他好处(颜色编码,自动分页,实时查看等)

我试过了:

 journalctl -u cron.service MESSAGE=update-ipsets journalctl -u cron.service "MESSAGE=*update-ipsets*" journalctl -u cron.service "MESSAGE=.*update-ipsets.*" journalctl -u cron.service "MESSAGE=/.*update-ipsets.*/" 

而且你不想通过在MESSAGE=之后点击tab来实验 – 挂起(zsh / Debian Jessie)shell并且Ctrl-C也没有帮助!

我有点不敢相信它没有内置这个基本function,所以我肯定我一定错过了什么?

谢谢。

我有同样的问题,我认为journalctlsearch所有匹配NAME=VALUE作为parameter passing完全匹配。

我的调查:

  1. 手册页

    journalctl(1)

    该匹配的描述中没有提到该模式:

      [...] A match is in the format "FIELD=VALUE", eg "_SYSTEMD_UNIT=httpd.service", referring to the components of a structured journal entry. [...] 

    手册页仅在描述-u选项时引用了一个模式。

      -u, --unit=UNIT|PATTERN Show messages for the specified systemd unit UNIT (such as a service unit), or for any of the units matched by PATTERN. 
  2. 源代码

    src/journal的函数fnmatch仅在search单元时使用 。

  3. debuggingjournalctl

    启用debugging输出,您可以看到只有在使用-u时才会扩展该模式。

     $ SYSTEMD_LOG_LEVEL=debug journalctl -n1 -u gdm* ... Matched gdm.service with pattern _SYSTEMD_UNIT=gdm* Matched gdm.service with pattern UNIT=gdm* Journal filter: ((OBJECT_SYSTEMD_UNIT=gdm.service AND _UID=0) OR (UNIT=gdm.service AND _PID=1) OR (COREDUMP_UNIT=gdm.service AND _UID=0 AND MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1) OR _SYSTEMD_UNIT=gdm.service) ... 

    所有的比赛都被视为确切的,包括UNIT

     $ SYSTEMD_LOG_LEVEL=debug journalctl -n1 UNIT=gdm.* ... Journal filter: UNIT=gdm* ...