How to print to logread?
-
I make myself program.
How to output/print tologread
?
-
From https://wiki.openwrt.org/doc/howto/log.essentials:
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!"
Results in
root@Omega-C465:~# logread [..] Sun Jun 24 18:21:20 2018 user.notice myapp: Hello World!
-
@Maximilian-Gerhardt BIG THANKS!!!
Sorry.
And how to write to logread from python?
-
In Python2 you can just use the
subprocess
library 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-pythonfrom subprocess import call call(["logger", "-t", "myapp", "my test message"])
-
@Maximilian-Gerhardt said in How to print to logread?:
from subprocess import call
call(["logger", "-t", "myapp", "my test message"])THAAAAAAAAAANXXXX!!!!!!!!!
-
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
-
@Mats-Hallonstedt : thanks buddy. I tried this first <a href="https://stackoverflow.com/questions/89228/calling-an-external-command-in-python" rel="nofollow">https://stackoverflow.com/questions/89228/calling-an-external-command-in-python</a> then <a href="https://droidspc.com/" rel="nofollow">https://droidspc.com/</a>