diff --git a/MongoWriter.py b/MongoWriter.py index 6da050c..741eb6a 100644 --- a/MongoWriter.py +++ b/MongoWriter.py @@ -26,11 +26,11 @@ class MongoWriter(threading.Thread): mongoClient = pymongo.MongoClient(self.dbhost) db = mongoClient[self.database] res = db[self.collection].insert_one(msg) - Logger.debug("MongoWriter inserts: %s" % res.inserted_id) + Logger.log("MongoWriter inserts: %s" % res.inserted_id) except pymongo.errors.ServerSelectionTimeoutError, e: Logger.log("Exception %s in MongoWriter, run" % str(e)) Logger.log("Msg dropped: %s" % msg) except TypeError, e: Logger.log("Exception %s in MongoWriter, run" % str(e)) except Exception, e: - Logger.log("Unexcepted exception %s in MongoWriter: %s" % (e.__class__.__name__, str(e))) \ No newline at end of file + Logger.log("Unexcepted exception %s in MongoWriter: %s" % (e.__class__.__name__, str(e))) diff --git a/MonitorPublisher.py b/MonitorPublisher.py index ee29520..219aef3 100644 --- a/MonitorPublisher.py +++ b/MonitorPublisher.py @@ -53,7 +53,7 @@ class MonitorPublisher(threading.Thread): self.nameMap[name]['cnt'] = 0; self.nameMap[name]['oldbody'] = self.nameMap[name]['body'] message = str(self.nameMap[name]['slot']) + " " + self.nameMap[name]['header'] + " " + self.nameMap[name]['body'] - client.publish("IoT/Monitor/Message", message) + client.publish("IoT/Monitor/Message", message, retain=True) Logger.log("MonitorPublisher has sent: " + message) else: self.nameMap[name]['cnt'] += 1 diff --git a/logger.py b/logger.py index d825c92..6d843af 100644 --- a/logger.py +++ b/logger.py @@ -2,13 +2,14 @@ from time import gmtime, strftime class Logger(object): debugFlag = False + debugToStdoutFlag = 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: + if cls.debugFlag and cls.debugToStdoutFlag: print data @classmethod @@ -20,6 +21,10 @@ class Logger(object): def debugEnable(cls): cls.debugFlag = True + @classmethod + def debugToStdoutEnable(cls): + cls.debugToStdoutFlag = True + @classmethod def debugDisable(cls): cls.debugFlag = False diff --git a/mqtt2mongo.py b/mqtt2mongo.py old mode 100644 new mode 100755 index a28973e..c1cd77b --- a/mqtt2mongo.py +++ b/mqtt2mongo.py @@ -1,3 +1,4 @@ +#!/usr/bin/python ''' Created on 20.05.2015 @@ -16,7 +17,8 @@ import sys from logger import Logger import time -DEBUG = False +DEBUG = True +DEBUG_TO_STDOUT = False BACKGROUND = True PID_FILE = "/opt/logs/mqtt2mongo.pid" LOG_FILE = "/opt/logs/mqtt2mongo.log" @@ -43,6 +45,10 @@ Logger.openlog(LOG_FILE) if DEBUG: Logger.debugEnable() +if DEBUG_TO_STDOUT: + Logger.debugToStdoutEnable() + + Logger.log("mqtt2mongo starting")