There are several ways to do this:
1. Editing the journalctl configuration file:
The file /etc/systemd/journald.conf by default only contains the line Storage=persistent.
- Open the journalctl configuration file:
sudo nano /etc/systemd/journald.conf
- Add the following lines to the
[Highlight]section:
# Journald configuration file
Storage=persistent
[Highlight]
Err=red
Error=red
# Case-insensitive highlighting
IgnoreCase=yes
- After adding these lines, the words «err» and «error» will be highlighted in red in the journalctl output.
- Save the file and restart the journald service:
sudo systemctl restart systemd-journald
- Now, when you enter the command:
sudo journalctl -u zetacored -f -n 100
- You should see that the words «err» and «error» are highlighted in red.
The IgnoreCase=yes setting in the /etc/systemd/journald.conf file does not affect the case sensitivity of commands entered using systemctl.
IgnoreCase=yes only affects the display of the words «err» and «error» in the output of the journalctl command.
2. Using the -i option:
- Use the
-ioption to ignore the case:
sudo journalctl -u myService.service -f -n 100 -i "err\|error"
Choose the method that works best for you.
Important:
- Changes to the journalctl configuration file will be applied to all users of the system.
- The
-ioption can be used to ignore the case when filtering.
Additional tips:
- You can change the ANSI code to use a different color for highlighting.
- You can add other words or phrases that will be highlighted.
Description of journald.conf functions
less /etc/systemd/journald.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See journald.conf(5) for details.
[Journal]
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=10000
#SystemMaxUse=
#SystemKeepFree=
#SystemMaxFileSize=
#SystemMaxFiles=100
#RuntimeMaxUse=
#RuntimeKeepFree=
#RuntimeMaxFileSize=
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
#ReadKMsg=yes
[Journal]:- This is the header of the configuration section, indicating that the parameters for configuring
systemd-journaldwill follow.
- This is the header of the configuration section, indicating that the parameters for configuring
#Storage=auto:- This parameter defines how the journal will be stored. In this case, the hash (
#) at the beginning of the line makes it a comment, rendering it inactive.automeans automatic selection of storage method.
- This parameter defines how the journal will be stored. In this case, the hash (
#Compress=yes:- This parameter determines whether the journal will be compressed.
yesindicates that compression is enabled.
- This parameter determines whether the journal will be compressed.
#Seal=yes:- This parameter determines whether the journal will be sealed, meaning it will not be subject to modifications.
#SplitMode=uid:- Specifies how the journals are split among users. In this case, commented out, indicating the use of the default value (
uid).
- Specifies how the journals are split among users. In this case, commented out, indicating the use of the default value (
#SyncIntervalSec=5m:- Defines the interval for syncing journal records to disk. Here, it is set to 5 minutes.
#RateLimitIntervalSec=30s:- Defines the time interval for rate-limiting journal entries. In this case, commented out, indicating the use of the default value (30 seconds).
#RateLimitBurst=10000:- Defines the maximum number of entries that can be added before rate-limiting takes effect.
#SystemMaxUse=:- Defines the maximum disk space that can be occupied by system journals.
#SystemKeepFree=:- Defines the minimum free disk space for system journals.
#SystemMaxFileSize=:- Defines the maximum file size for system journals.
#SystemMaxFiles=100:- Defines the maximum number of files for system journals.
#RuntimeMaxUse=and subsequent lines are similar to system settings but apply to user session journals.#MaxRetentionSec=:- Defines the maximum retention time for journal entries.
#MaxFileSec=1month:- Defines the maximum time each journal file will be retained.
#ForwardToSyslog=yes:- Specifies whether
systemd-journaldshould forward logs to the system syslog. In this case, it’s commented out, indicating the default behavior is used (yes).
- Specifies whether
#ForwardToKMsg=no:- Determines whether
systemd-journaldshould forward logs to the kernel message ring buffer (KMsg). Here, it’s disabled.
- Determines whether
#ForwardToConsole=no:- Defines whether
systemd-journaldshould forward logs to the console. In this case, it’s disabled.
- Defines whether
#ForwardToWall=yes:- Decides whether
systemd-journaldshould forward logs to the «wall,» which may mean output to all terminals. Here, it’s commented out, indicating the default behavior (yes).
- Decides whether
#TTYPath=/dev/console:- Specifies the path to the terminal (
TTY) to which logs will be sent. Here, it’s set to the system console.
- Specifies the path to the terminal (
#MaxLevelStore=debug:- Sets the maximum logging level that will be stored in the
systemd-journaldjournal. Here, the level is set todebug.
- Sets the maximum logging level that will be stored in the
#MaxLevelSyslog=debug:- Sets the maximum logging level that will be forwarded to the system syslog. Here, the level is set to
debug.
- Sets the maximum logging level that will be forwarded to the system syslog. Here, the level is set to
#MaxLevelKMsg=notice:- Sets the maximum logging level that will be forwarded to the kernel message ring buffer (
KMsg). Here, the level is set tonotice.
- Sets the maximum logging level that will be forwarded to the kernel message ring buffer (
#MaxLevelConsole=info:- Sets the maximum logging level that will be forwarded to the console. Here, the level is set to
info.
- Sets the maximum logging level that will be forwarded to the console. Here, the level is set to
#MaxLevelWall=emerg:- Sets the maximum logging level that will be forwarded to the «wall.» Here, the level is set to
emerg.
- Sets the maximum logging level that will be forwarded to the «wall.» Here, the level is set to
#LineMax=48K:- Specifies the maximum size of a single line in the
systemd-journaldjournal. Here, it’s set to a size of 48 kilobytes.
- Specifies the maximum size of a single line in the
#ReadKMsg=yes:- Determines whether
systemd-journaldshould read messages from the kernel message ring buffer (KMsg). Here, it’s set toyes.
- Determines whether