a655fcd2858f275c937ed2444f40737082451fa9
[saartuer.git] / libtuer.py
1 import logging, logging.handlers, syslog, os
2
3 # logging function
4 class Logger:
5         def __init__ (self):
6                 import __main__ as main
7                 self.name = os.path.basename(main.__file__)
8                 self.logger = logging.getLogger(self.name)
9                 self.logger.setLevel(logging.INFO)
10                 self.handler = logging.handlers.SysLogHandler(address = '/dev/log', facility = logging.handlers.SysLogHandler.LOG_LOCAL0)
11                 self.logger.addHandler(self.handler)
12         def log (self, what):
13                 thestr = "%s[%d]: %s" % (self.name,os.getpid(),what)
14                 print (thestr)
15                 self.logger.info(thestr)
16
17 logger = Logger()
18
19 def log (what):
20         logger.log(what)
21