Repository navigation
Add new --grep option to journalctl - #7881
Conversation
|
urks. regexes. yuck. Are we sure we want this? also, if we do, are we sure we want perl-compatible ones? why not stick to normal glibc regexes? |
There was a problem hiding this comment.
Maybe instead use -G for case-senstivie grepping, and -g for non-case-sensitive grepping?
There was a problem hiding this comment.
I though about that... that can always be added. But a separate option is still needed, because there are three cases: sensitive, insensitive, automatic. So g/G is not enough.
There was a problem hiding this comment.
hmm, indenting is different from other lines...
|
also, grep does coloring here, this patch does not, are we sure we want this in our code? Moreover, if we apply grepping to MESSAGES= only then using normal grep is exactly as good as our stuff... |
Well, it's a useful tool. We do all kinds of filtering, but there are many cases where that filtering is not enough. Of course it's not always applicable, but there are many many cases where it is. As random examples: finding all messages about firmware from the kernel and services and printing them, without destroying multiline messages; or finding all sshd messages referring to a certain user name.
I think it's quite useful.
Because they are the most powerful and the reason to use those older syntaxes is backwards compat which doesn't apply here.
I didn't think this would be particularly useful. I'd let people start playing with this, and maybe implement later if there's demand.
No, not really. I list a bunch of reasons in the initial message. In addition, doing this internally is faster, and this patch works with |
|
hmm, small call from the embedded people to have this optional... libpcre is not that big (~100k from a quick look at a yocto package) but it's still an increase of the actual space taken by systemd on minimalistic systems... systemd being a fundamental brick, any systemd dependency is a mandatory system dependancy for all practical purpose... |
|
my bad... it is optional |
|
Wouldn't it make more sense to just add a flag for enabling regexp in all the existing matching machinery? So you'd just use journalctl exactly as you do now, but what used to only be literal match fields now support regexp because you added a flag to enable the behavior. |
|
That would be a huge reworking. Right now when you ask for MESSAGE=foobar or MESSAGE_ID=something, there's no searching going on, because fields and field-value pairs are indexed. With regexp (or any other pattern matching) this all becomes impossible and the only way is to first find all the occurrences and them filter them. What you are suggesting would be interesting, but it's massively more work compared to this simple patch. |
|
Updated with some small fixes and one new feature: the matched pattern is now highlighted, similarly to what grep does. |
There was a problem hiding this comment.
please do --case-sensitive as --case-sensitive=
There was a problem hiding this comment.
this is indented unlike the other lines
Case sensitive or case insensitive matching can be requested using --case-sensitive[=yes|no]. Unless specified, matching is case sensitive if the pattern contains any uppercase letters, and case insensitive otherwise. This matches what forward-search does in emacs, and recently also --ignore-case in less. This works surprisingly well, because usually when one is wants to do case-sensitive matching, the pattern is usually camel-cased. In the less frequent case when case-sensitive matching is required with an all-lowercase pattern, --case-sensitive can be used to override the automatic logic.
Red is used for highligting, the same as grep does. Except when the line is highlighted red already, because it has high priority, in which case plain ansi highlight is used for the matched substring. Coloring is implemented for short and cat outputs, and not for other types. I guess we could also add it for verbose output in the future.
|
Updated. |
This uses the pcre2 libary, which is, as least on systems on which systemd is built with selinux support, essentially free, since selinux already links to it.
Using
--grepinstead of piping to grep is nice because our coloring and pager support is retained. Also, only the MESSAGE field is grepped, not the metadata.