Kernel logger is a kernel module that can be used as a replacement for logger
or logwrapper
.
Its log is similar to systemd's journal and can be read by dmesg
or journalctl
.
- You need to record the logs of initramfs and hope that journald can keep these logs.
- You want a logger, but do not want or cannot make any changes to a program.
- You find it annoying to type
logger
again and again in a shell script.
Here is a very suitable use case.
- kmsg could not add a tag
logger
needs a backend
- Compile and load this module
make
sudo insmod logger.ko
- Run a shell command to test it
vagrant@ubuntu-focal:/vagrant$ echo "This is just a test" > /dev/logger
vagrant@ubuntu-focal:/vagrant$
vagrant@ubuntu-focal:/vagrant$ dmesg | grep "This is just a test"
[ 55.750168] bash[1289]: This is just a test
vagrant@ubuntu-focal:/vagrant$
vagrant@ubuntu-focal:/vagrant$ journalctl -b | grep "This is just a test"
Mar 04 02:13:46 ubuntu-focal bash[1289]: This is just a test
Just add the following to the beginning of your shell script:
exec > /dev/logger 2>&1
This project is licensed under GPL-2.0.