https://github.com/tianyuanhao/kernel-syslog
📝 Kernel module that can be used as a replacement for syslog, logger or logwrapper
https://github.com/tianyuanhao/kernel-syslog
android bash dmesg embedded init init-system initramfs journal journalctl kernel kernel-module kernel-modules kmsg linux logger logging shell syslog systemd ttyprintk
Last synced: 7 months ago
JSON representation
📝 Kernel module that can be used as a replacement for syslog, logger or logwrapper
- Host: GitHub
- URL: https://github.com/tianyuanhao/kernel-syslog
- Owner: tianyuanhao
- License: gpl-2.0
- Created: 2021-02-20T01:42:26.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-25T06:57:04.000Z (about 4 years ago)
- Last Synced: 2024-11-01T07:33:30.445Z (about 1 year ago)
- Topics: android, bash, dmesg, embedded, init, init-system, initramfs, journal, journalctl, kernel, kernel-module, kernel-modules, kmsg, linux, logger, logging, shell, syslog, systemd, ttyprintk
- Language: C
- Homepage:
- Size: 11.7 KB
- Stars: 44
- Watchers: 7
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.](https://unix.stackexchange.com/questions/97580/init-syslog-and-stdout-stderr)
## Why not kmsg or logger
- kmsg could not add a tag
- `logger` needs a backend
## Quick start
1. Compile and load this module
```sh
make
sudo insmod logger.ko
```
2. Run a shell command to test it
```sh
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:
```sh
exec > /dev/logger 2>&1
```
## License
This project is licensed under [GPL-2.0](LICENSE).