Skip to content

๐Ÿ“ Kernel module that can be used as a replacement for syslog, logger or logwrapper

License

Notifications You must be signed in to change notification settings

tianyuanhao/kernel-syslog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Kernel logger

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.

Use cases

  • 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.

Why not kmsg or logger

  • kmsg could not add a tag
  • logger needs a backend

Quick start

  1. Compile and load this module
make
sudo insmod logger.ko
  1. 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

Usage in shell script

Just add the following to the beginning of your shell script:

exec > /dev/logger 2>&1

License

This project is licensed under GPL-2.0.