mirror of
https://github.com/dyne/FreeJ.git
synced 2026-02-08 22:09:17 +01:00
Logging example for python
Provide a small example for logging. Signed-off-by: Luca Bigliardi <shammash@artha.org>
This commit is contained in:
30
scripts/python/examples/python_logger.py
Executable file
30
scripts/python/examples/python_logger.py
Executable file
@@ -0,0 +1,30 @@
|
||||
import freej
|
||||
|
||||
class MyLogger(freej.WrapperLogger):
|
||||
""" This is a basic example for a python logger.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, *args):
|
||||
super(MyLogger, self).__init__(*args)
|
||||
|
||||
def logmsg(self, level, msg):
|
||||
""" Override this method to handle log messages
|
||||
|
||||
"""
|
||||
if level == freej.ERROR:
|
||||
print "ERROR from python: %s" % msg
|
||||
else:
|
||||
print "I will just print: %s" % msg
|
||||
|
||||
|
||||
m = MyLogger()
|
||||
|
||||
# Register in GlobalLogger to have all messages redirected to your logger (you
|
||||
# can also register to an instance of a Loggable subclass to receive only
|
||||
# messages from that object).
|
||||
freej.GlobalLogger.register_logger(m)
|
||||
|
||||
# Set the maximum loglevel GlobalLogger should print/redirect
|
||||
freej.GlobalLogger.set_loglevel(freej.DEBUG)
|
||||
|
||||
Reference in New Issue
Block a user