Add logging capability to mqtt_sender script #162
This commit is contained in:
parent
b5c67f1c91
commit
f8f9bb9b7b
1 changed files with 11 additions and 10 deletions
|
|
@ -7,17 +7,18 @@ import time
|
|||
import signal
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
||||
|
||||
def sigint_handler(signal, frame):
|
||||
print 'Interrupted'
|
||||
logging.warning('Interrupted')
|
||||
sys.exit(0)
|
||||
os._exit(0)
|
||||
|
||||
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print("Connected with result code "+str(rc))
|
||||
logging.info("Connected with result code "+str(rc))
|
||||
client.subscribe("$SYS/#")
|
||||
|
||||
|
||||
|
|
@ -34,13 +35,13 @@ def getRedis(i):
|
|||
data = r.brpop("events", 10)
|
||||
if data:
|
||||
info = data[1].split('|')
|
||||
print "Channel: " + info[0] + " message: " + info[1]
|
||||
logging.info("Channel: " + info[0] + " message: " + info[1])
|
||||
client.publish(info[0], info[1])
|
||||
|
||||
|
||||
|
||||
def sigint_handler(signal, frame):
|
||||
print 'Interrupted'
|
||||
logging.warning('Interrupted')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
|
@ -49,8 +50,6 @@ def main():
|
|||
client.on_connect = on_connect
|
||||
client.on_publish = on_publish
|
||||
|
||||
|
||||
|
||||
client.tls_set(
|
||||
"/etc/letsencrypt/live/resqaws.jankstudio.com/fullchain.pem", cert_reqs=ssl.CERT_NONE,
|
||||
tls_version=ssl.PROTOCOL_TLSv1)
|
||||
|
|
@ -64,7 +63,9 @@ def main():
|
|||
client.loop_forever()
|
||||
|
||||
|
||||
|
||||
pid = "/tmp/mqtt_sender.pid"
|
||||
daemon = Daemonize(app="mqtt_sender", pid=pid, action=main)
|
||||
daemon.start()
|
||||
logging.basicConfig(filename='/tmp/mqtt_sender.log', level=logging.INFO)
|
||||
logging.info('Started mqtt_sender')
|
||||
#pid = "/tmp/mqtt_sender.pid"
|
||||
#daemon = Daemonize(app="mqtt_sender", pid=pid, action=main)
|
||||
#daemon.start()
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue