rotating log for doorbell.py
This commit is contained in:
@@ -5,10 +5,17 @@
|
|||||||
import serial
|
import serial
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import logging
|
import logging
|
||||||
|
import logging.handlers as handlers
|
||||||
import time
|
import time
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s')
|
logger = logging.getLogger('Rotating Log')
|
||||||
logging.info('Initializing')
|
logger.setLevel(logging.INFO)
|
||||||
|
logHandler = handlers.RotatingFileHandler('/media/hd/admin/doorbell/doorbell.log', maxBytes=1000000, backupCount=2)
|
||||||
|
logHandler.setLevel(logging.INFO)
|
||||||
|
logHandler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S'))
|
||||||
|
logger.addHandler(logHandler)
|
||||||
|
|
||||||
|
logger.info('Initializing')
|
||||||
|
|
||||||
|
|
||||||
arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=.1)
|
arduino = serial.Serial('/dev/ttyUSB0', 9600, timeout=.1)
|
||||||
@@ -21,8 +28,8 @@ while True:
|
|||||||
try:
|
try:
|
||||||
response = urllib.request.urlopen('http://192.168.178.51/bell/on', timeout=5).read().decode('utf-8')
|
response = urllib.request.urlopen('http://192.168.178.51/bell/on', timeout=5).read().decode('utf-8')
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error("Could not ring doorbell")
|
logger.error("Could not ring doorbell")
|
||||||
# logging.exception("Could not ring doorbell")
|
# logger.exception("Could not ring doorbell")
|
||||||
time.sleep(300)
|
time.sleep(300)
|
||||||
else:
|
else:
|
||||||
logging.info(data)
|
logger.info(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user