Mqtt2Mongo/logger.py

32 lines
648 B
Python
Raw Normal View History

2015-06-09 22:09:28 +02:00
from time import gmtime, strftime
2015-06-09 17:01:20 +02:00
class Logger(object):
2015-06-09 22:09:28 +02:00
debugFlag = False
@classmethod
def log(cls, data):
t = strftime("%d %b %Y %H:%M:%S", gmtime())
with open(cls.logfile, 'a') as f:
f.write("%s %s\n" % (t, data))
if cls.debugFlag:
2015-06-09 17:01:20 +02:00
print data
2015-06-09 22:09:28 +02:00
@classmethod
def debug(cls, data):
if cls.debugFlag:
cls.log(data)
@classmethod
def debugEnable(cls):
cls.debugFlag = True
2015-06-09 17:01:20 +02:00
2015-06-09 22:09:28 +02:00
@classmethod
def debugDisable(cls):
cls.debugFlag = False
2015-06-09 17:01:20 +02:00
2015-06-09 22:09:28 +02:00
@classmethod
def openlog(cls, logfile):
cls.logfile = logfile
2015-06-09 17:01:20 +02:00