filter journalctl messages by priority (Ubuntu)

In this article, we would cover how to filter journalctl messages by priority (Ubuntu). There are numerous messages generated by systemd journal. journalctl is the command-line utility which helps us read those messages. But, if we simply use journalctl without any options then it will show us all the messages generated. Now, there could be certain messages which may not be useful to us at all. On the contrary, some would require immediate resolution. Filtering out critical messages on our own is definitely time consuming activity.

So, what we can do about it? Just filter messages by priority. There are a total of seven priority levels which we can use with journalctl.

Priority levels

We can either use numeric or text value of priority level with journalctl.

0 or emerg – This is for all the emergency messages. If our system can’t be used anymore then, check for the messages which end up here.

1 or alert – These messages Alert us to take necessary action.

2 or crit – for critical conditions.

3 or err – it shows there has been an error, which needs to be taken care of. Not as severe as Alert. But, definitely needs attention.

4 or warning – if something is not heed to then, it may result in an error. So, we need to be cautious.

5 or notice – it merely shows that we are not doing something right. Things may escalate from here.

6 or info – These message are generated just to provide information.

7 or debug – these are debug messages, specifically useful to the developers.

Now that we have discussed various priority levels. Its time to see how to utilize the above information to our advantage.

filter journalctl messages by priority

Open a terminal and issue the following –

journalctl

It would show us all the generated messages. This is what we were talking about at the beginning of the article. Now, to filter these messages – we can either opt for numeric or text value with priority option.

journalctl --priority=<numeric_value/text_value>

For instance, to check for Emergency messages, we can use either of the following codes –

journalctl --priority=0

or,

journalctl --priority=emerg

If it doesn’t have anything to show –

-- No entries --

Otherwise, it shows the required messages. Similarly, we can use the command with other priority levels too.

In conclusion, we have discussed how to filter journalctl messages by priority (Ubuntu).