Logfile added
This commit is contained in:
parent
5736a42f6e
commit
ca1e61c155
@ -2,6 +2,7 @@ import config
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import mqtt
|
import mqtt
|
||||||
|
import os
|
||||||
import report
|
import report
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
@ -13,6 +14,14 @@ except ImportError:
|
|||||||
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
|
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):
|
class exec_command(mqtt.mqtt_client):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.__block_execution__ = False
|
self.__block_execution__ = False
|
||||||
@ -22,8 +31,10 @@ class exec_command(mqtt.mqtt_client):
|
|||||||
# Start a pseudo process
|
# Start a pseudo process
|
||||||
self.process = subprocess.Popen(["sleep", "0"])
|
self.process = subprocess.Popen(["sleep", "0"])
|
||||||
|
|
||||||
def exec_command(self, cmd):
|
def exec_command(self, cmd, message):
|
||||||
self.process = subprocess.Popen(cmd.split(" "))
|
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):
|
def mqtt_rx(self, client, userdate, message):
|
||||||
payload = None
|
payload = None
|
||||||
@ -48,7 +59,7 @@ class exec_command(mqtt.mqtt_client):
|
|||||||
if self.process.poll() is None:
|
if self.process.poll() is None:
|
||||||
self.process.kill()
|
self.process.kill()
|
||||||
logger.debug("Starting execution in background...")
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user