Currently you do not notice when an error message appears in the log dmesg
or journalctl
,
Auto desktop-notification of error log might help to make you notice easily.
Installation
journalctl-desktop-notification-git
is available in AUR
Configuration is located in /etc/journalctl-desktop-notification.conf
-
Exclusive annoying spam errors.
ERROR_FILTER="Spam1|Spam2|Spam3"
-
Time frequency (secound) of the check journalctl
TIME_INTERVAL="2"
-
Custom terminal app will be opened.
Example: konsole for KDE terminal
TERMINAL="konsole"
-
Custom icon of error message.
ERROR_ICON="system-error"
-
Custom log level: Warning level is 4, error level is 3, critical level is 2.
LOG_LEVEL="3"
How to enable it for autostart:
cp /usr/share/applications/journalctl-desktop-notification.desktop ~/.config/autostart/
OR
Manual without installing AUR package
-
Install
dunst
that is for desktop-notification provided by most desktop environments -
Create a new script
/usr/local/bin/journal-desktop-notify
#!/bin/env bash
get_timestamp_from_log()
{
timestamp=$(journalctl --output=short-unix -p 3 -n 1 | grep -m1 '' | cut -d ' ' -f 1)
}
sleep 3
get_timestamp_from_log
OLD_TIMESTAMP_LINE=$timestamp
while sleep 2; do
get_timestamp_from_log
TIMESTAMP_LINE=$timestamp
if [ -n "$TIMESTAMP_LINE" ] && [ "$TIMESTAMP_LINE" != "$OLD_TIMESTAMP_LINE" ]; then
MESSAGE=$(journalctl --output=cat -p 3 -n 1)
ACTION=$(dunstify --appname="Detected the error!" --icon=system-error --action="default,Reply" --action="openAction,Open" --action="disableAction,Disable" --action="closeAction,Close" "Please check journalctl!" "$MESSAGE")
if [ "disableAction" == "$ACTION" ]; then
echo "Disabled"
break
elif [ "closeAction" == "$ACTION" ]; then
echo "Closed"
elif [ -x "$(which gnome-terminal)" ]; then
# Terminal will be opened when clicking the notification
case "$ACTION" in
"default")
gnome-terminal -e "journalctl --no-page -p err -b -f"
;;
"openAction")
gnome-terminal -e "journalctl --no-page -p err -b -f"
;;
esac
elif [ -x "$(which konsole)" ]; then
case "$ACTION" in
"default")
konsole -e "journalctl --no-page -p err -b -f"
;;
"openAction")
konsole -e "journalctl --no-page -p err -b -f"
;;
esac
elif [ -x "$(which xterm)" ]; then
case "$ACTION" in
"default")
xterm -e "journalctl --no-page -p err -b -f"
;;
"openAction")
xterm -e "journalctl --no-page -p err -b -f"
;;
esac
fi
get_timestamp_from_log
OLD_TIMESTAMP_LINE=$timestamp
fi
done
- Make this script executable:
sudo chmod +x /usr/local/bin/journal-desktop-notify
- Create a new script as Desktop app:
~/.local/share/applications/journal-notify.desktop
[Desktop Entry]
Name=Journal Notify
Comment=Auto notification of journalctl
Icon=system-error
Exec=/usr/local/bin/journal-desktop-notify
Terminal=false
Type=Application
Categories=Utility
- Create a new symlink for startup:
ln -s /home/$USER/.local/share/applications/journal-notify.desktop ~/.config/autostart/
- Reboot
How to test:
echo 'BTRFS error test' | systemd-cat -p err
KDE:
Gnome:
Notification appears when which error messages are excluded or included
How to exclude error messages like spams:
Just add grep -iEv 'spam1|spam2'
behind journalctl
in this script /usr/local/bin/journal-desktop-notify
Example:
Change
get_timestamp_from_log()
{
timestamp=$(journalctl --output=short-unix -p 3 -n 1 | grep -m1 '' | cut -d ' ' -f 1)
}
to
get_timestamp_from_log()
{
timestamp=$(journalctl --output=short-unix -p 3 -n 1 | grep -m1 '' | grep -iEv 'dolphin|systemd-coredump' | cut -d ' ' -f 1)
}
How to include some error messages only:
Just add grep -iE 'keyword1|keyword2'
behind journalctl
in the function get_timestamp_from_log()
Example:
timestamp=$(journalctl --output=short-unix -p 3 -n 1 | grep -m1 '' | grep -iE 'BTRFS' | cut -d ' ' -f 1)
How to remove timeout of notification
Notification disappears after the default timeout, but you might miss it when you are not there or distracted somewhere else.
If you do not want timeout of notification, then adding the option -u "critical"
in the script:
Change
ACTION=$(dunstify --appname="Detected the error!" --icon=system-error --action="default,Reply" --action="openAction,Open" --action="closeAction,Close" "Please check journalctl!" "$MESSAGE" )
to
ACTION=$(dunstify -u "critical" --appname="Detected the error!" --icon=system-error --action="default,Reply" --action="openAction,Open" --action="closeAction,Close" "Please check journalctl!" "$MESSAGE" )
Troubleshooting
KDE Plasma notification is automatically replaced with “knopwob dunst” notification after some Manjaro update.
If you want to switch back KDE default notification, just reinstall knotifications
and knotifyconfig
to reset the config of KDE notification, then reboot.
If it does not work, try to do the other solution: