-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bat for reading the systemd journal #2216
Comments
We had a request to highlight lines in log files differently, based on severity (identified by the line containing the text "warn" / "error" / "fatal" etc, so the solution for that could perhaps help with this feature request. See #2152 |
@keith-hall Good to know, that may be a starting point. Looking through my journal however, it recognizes lines such as this:
as warnings, it recognizes certain messages from
and more, but none of these carry any obvious markers or keywords afaict. I'll see if I can find more information about how |
I'm guessing because you are calling
You can force it to by setting As noted above
This output will not be rendered correctly in This can be rectified by disabling colors with To test you can try:
For For myself, I stuck with default systemd pager as I found the highlighting based on priority to be more useful. |
create a function |
You have to set
resources from $SYSTEMD_PAGER
Pager to use when --no-pager is not given; overrides $PAGER.
If neither $SYSTEMD_PAGER nor $PAGER are set, a set of
well-known pager implementations are tried in turn, including
less(1) and more(1), until one is found. If no pager
implementation is discovered no pager is invoked. Setting
this environment variable to an empty string or the value
"cat" is equivalent to passing --no-pager.
Note: if $SYSTEMD_PAGERSECURE is not set, $SYSTEMD_PAGER (as
well as $PAGER) will be silently ignored.
$SYSTEMD_PAGERSECURE
Takes a boolean argument. When true, the "secure" mode of the
pager is enabled; if false, disabled. If $SYSTEMD_PAGERSECURE
is not set at all, secure mode is enabled if the effective
UID is not the same as the owner of the login session, see
geteuid(2) and sd_pid_get_owner_uid(3). In secure mode,
LESSSECURE=1 will be set when invoking the pager, and the
pager shall disable commands that open or create new files or
start new subprocesses. When $SYSTEMD_PAGERSECURE is not set
at all, pagers which are not known to implement secure mode
will not be used. (Currently only less(1) implements secure
mode.) |
Hi,
I really like bat and I think it has a lot of great features. However I often find myself reading the systemd journal via
journalctl
and I think it would be nice to have some highlighting for that, too. The next-best thing at the moment seems to bebat -l syslog
. Now this makes reading the journal a lot nicer already, butjournalctl
in its default output does some special line handling depending on a lines "severity". From the man page:This makes spotting warnings and errors very easy. I find that
bat
has no equivalent yet, or am I missing something? I wonder if it would be possible to implement a separate highlighting for systemd that extends syslog and imitatesjournalctl
s behavior? Maybe the lines could be printed bold, or with highlighted background?As for how
journalctl
knows which lines are warnings or errors, I do not know. This seems to be a rather critical issue in implementing this. But do you think this would generally be feasible?On a related note, maybe this then also qualifies for a shell wrapper in bat-extras, something like
batjournal
that overrides the systemd pager? At the moment I cannot usebat
as a pager tojournalctl
, or at least I don't know how. This doesn't work:$ PAGER="bat -l syslog" journalctl -b
because it falls back to using
less
, even if I specify the full path to bat...The text was updated successfully, but these errors were encountered: