Adds logging capabilities, lambda function, html templates
This commit is contained in:
@@ -4,6 +4,22 @@ import threading
|
||||
from device_base import deviceBase
|
||||
from utilities import get_public_ip_address
|
||||
import time
|
||||
import logging
|
||||
import sys
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
|
||||
logFile = './promagmbs.log'
|
||||
my_handler = RotatingFileHandler(logFile, mode='a', maxBytes=500*1024, backupCount=2, encoding=None, delay=0)
|
||||
my_handler.setFormatter(log_formatter)
|
||||
my_handler.setLevel(logging.INFO)
|
||||
logger = logging.getLogger('promagmbs')
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.addHandler(my_handler)
|
||||
|
||||
console_out = logging.StreamHandler(sys.stdout)
|
||||
console_out.setFormatter(log_formatter)
|
||||
logger.addHandler(console_out)
|
||||
|
||||
|
||||
_ = None
|
||||
@@ -18,7 +34,7 @@ class start(threading.Thread, deviceBase):
|
||||
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "1"
|
||||
self.version = "4"
|
||||
self.finished = threading.Event()
|
||||
self.forceSend = False
|
||||
threading.Thread.start(self)
|
||||
@@ -36,9 +52,9 @@ class start(threading.Thread, deviceBase):
|
||||
global persist
|
||||
wait_sec = 60
|
||||
for i in range(0, wait_sec):
|
||||
print("promagmbs driver will start in {} seconds".format(wait_sec - i))
|
||||
logger.info("promagmbs driver will start in {} seconds".format(wait_sec - i))
|
||||
time.sleep(1)
|
||||
print("BOOM! Starting promagmbs driver...")
|
||||
logger.warning("BOOM! Starting promagmbs driver...")
|
||||
|
||||
public_ip_address = get_public_ip_address()
|
||||
self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'promagmbs')
|
||||
@@ -48,12 +64,12 @@ class start(threading.Thread, deviceBase):
|
||||
watchdog_check_after = 5000
|
||||
while True:
|
||||
if self.forceSend:
|
||||
print "FORCE SEND: TRUE"
|
||||
logger.warning("FORCE SEND: TRUE")
|
||||
|
||||
print("promagmbs driver still alive...")
|
||||
logger.info("promagmbs driver still alive...")
|
||||
if self.forceSend:
|
||||
if send_loops > 2:
|
||||
print("Turning off forceSend")
|
||||
logger.warning("Turning off forceSend")
|
||||
self.forceSend = False
|
||||
send_loops = 0
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user