What's new

logger from Python?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Teddyz

Occasional Visitor
I have installed entware and Python on my AC68U.
And this night I learned that I can send logger-events that can be seen in the gui.
Is there a simple way to send them from my Python-scripts as well?
 
I have installed entware and Python on my AC68U.
And this night I learned that I can send logger-events that can be seen in the gui.
Is there a simple way to send them from my Python-scripts as well?
Here's one way to do it:
Python:
import subprocess
...

subprocess.run("/usr/bin/logger -t 'MyEventLogMsgTag' 'Logging events from my Python script...'", shell=True, check=True)

Just to double-check that the msg was logged using Python:
Python:
subprocess.run("grep -i 'MyEventLogMsgTag' /tmp/syslog.log", shell=True)
Note that in some newer router models the path of the system log file (syslog.log) may be different from older models, but in your RT-AC68U the above path should work.

And here's another way using variables (e.g. if you wanted to make calls from a function)
Python:
import subprocess
...

logCmd = '/usr/bin/logger'
logTag = ' -t "MyEventLogMsgTag"'
logMsg = ' "Testing logging from Python..."'

theFullLogCmd = logCmd + logTag + logMsg

subprocess.run(theFullLogCmd, shell=True, check=True)

HTH.
 
Last edited:

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top