Home/Support/Support Forum/How to log from python?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How to log from python?

0 votes
Hi. What logging options are available for python scripts on a Transport WR41 gateway? Is there any way to log to the device's main event log?

Thanks!
asked Jun 9, 2015 in Python by aragon New to the Community (2 points)

Please log in or register to answer this question.

3 Answers

+1 vote
I read it the other way around.

To write to the event log:

from BaseWizard import write_cli

eventlog =write_cli('setevent "this is a test"')
answered Jun 9, 2015 by NicholasWilson Veteran of the Digi Community (1,001 points)
Thank you for replying.  I get an error when trying to import BaseWizard:

ss200496>Python 2.6.1 (r261:67515, May 07 2013, 10:54:58) [C] on digiSarOS
Type "help", "copyright", "credits" or "license" for more information.
>>> from BaseWizard import write_cli
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named BaseWizard
You must be on a super old version.  What firmware are you running ("id" command)?

You can get the latest from here:  http://www.digi.com/support/productdetail?pid=5500&type=firmware
I was on version 5176.  I've upgraded to 5.2.10.9 and your code snippet is working.  Thank you!!
0 votes
It depends what you are trying to achieve...

from BaseWizard import write_cli

eventlog = write_cli ("type eventlog.txt")
print eventlog

or you could do

eventlog = open("/eventlog.txt")
eventlog_contents = eventlog.read()
print (eventlog_contents)
answered Jun 9, 2015 by NicholasWilson Veteran of the Digi Community (1,001 points)
0 votes
In case this helps anyone, threw this together. Should work the same as any python logging handler.
Code:
class DigiEventLogHandler (logging.Handler): def __init__ (self): logging.Handler.__init__(self) from BaseWizard import write_cli self.write_cli = write_cli def emit (self, record): if not hasattr(self, 'write_cli'): return msg = self.format(record) self.write_cli('setevent "%s"' % msg)
answered Jun 10, 2015 by aragon New to the Community (2 points)
...