How to print to logread?
I make myself program.
How to output/print to
Who logs? The syslogd acts as the server and any program can act as the client and send log messages to it. For example logger can be used to manually write messages to the system log. Some scripts in /etc/init.d/ actually use this.
In the Omega2's shell:
root@Omega-C465:~# logger -h logger: unrecognized option: h BusyBox v1.25.1 () multi-call binary. Usage: logger [OPTIONS] [MESSAGE] Write MESSAGE (or stdin) to syslog -s Log to stderr as well as the system log -t TAG Log using the specified tag (defaults to user name) -p PRIO Priority (numeric or facility.level pair)
When doing e.g.
root@Omega-C465:~# logger -t "myapp" "Hello World!"
root@Omega-C465:~# logread [..] Sun Jun 24 18:21:20 2018 user.notice myapp: Hello World!
@Maximilian-Gerhardt BIG THANKS!!!
And how to write to logread from python?
In Python2 you can just use the
subprocesslibrary to invoke a shell command as if you would type it in the shell. See https://stackoverflow.com/questions/89228/calling-an-external-command-in-python
from subprocess import call call(["logger", "-t", "myapp", "my test message"])
from subprocess import call
call(["logger", "-t", "myapp", "my test message"])
There is an option to the "call" procedure when logging from Python:
import syslog # Log messages to "LOCAL0" facility syslog.openlog(facility=syslog.LOG_LOCAL0) # Write something to the logfile syslog.syslog(syslog.LOG_INFO, "This is a logged message") syslog.closelog()
You may then filter these from the shell:
root@Omega:~# logread -l 800 | grep "local0" Thu Dec 13 09:02:24 2018 local0.info log.py: This is a logged message