diff --git a/exec_command.py b/exec_command.py index 9b8ae94..7b73f6a 100644 --- a/exec_command.py +++ b/exec_command.py @@ -2,6 +2,7 @@ import config import json import logging import mqtt +import os import report import subprocess import time @@ -13,6 +14,14 @@ except ImportError: logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main') +my_handler = logging.handlers.RotatingFileHandler(os.path.join(config.__BASEPATH__, 'door_bell.log'), mode='a', maxBytes=5*1024*1024, backupCount=3, encoding=None, delay=0) +my_handler.setLevel(logging.INFO) +my_handler.setFormatter(logging.Formatter("%(asctime)s: %(message)s")) +bell_log = logging.getLogger('root') +bell_log.setLevel(logging.INFO) +bell_log.addHandler(my_handler) + + class exec_command(mqtt.mqtt_client): def __init__(self): self.__block_execution__ = False @@ -22,8 +31,10 @@ class exec_command(mqtt.mqtt_client): # Start a pseudo process self.process = subprocess.Popen(["sleep", "0"]) - def exec_command(self, cmd): + def exec_command(self, cmd, message): self.process = subprocess.Popen(cmd.split(" ")) + if 'bell' in message.topic: + bell_log.info('Door Bell activated (%s)', message.topic) def mqtt_rx(self, client, userdate, message): payload = None @@ -48,7 +59,7 @@ class exec_command(mqtt.mqtt_client): if self.process.poll() is None: self.process.kill() logger.debug("Starting execution in background...") - self.exec_command(config.EXEC_LIST[message.topic]['command']) + self.exec_command(config.EXEC_LIST[message.topic]['command'], message) if __name__ == '__main__':