Mqtt2Mongo/logger.py

37 lines
793 B
Python
Raw Permalink 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
2016-10-31 16:27:39 +01:00
debugToStdoutFlag = False
2015-06-09 22:09:28 +02:00
@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))
2016-10-31 16:27:39 +01:00
if cls.debugFlag and cls.debugToStdoutFlag:
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
2016-10-31 16:27:39 +01:00
@classmethod
def debugToStdoutEnable(cls):
cls.debugToStdoutFlag = True
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