Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A Python logging handler using MQTT protocol

Project description

A Python logging handler using MQTT protocol.


pip install mqtthandler

Example usage

import mqtthandler
import logging
import time

mqtthdlr = mqtthandler.MQTTHandler('', 'topic/test')

logger = logging.getLogger()
logger.setLevel(logging.INFO)'test')  # Automatically connecting to the MQTT broker if not connected (equal to loop_start()) and sending log message to MQTT broker'test 2')

# Wait for log being sent to the MQTT broker
while True:

# You will only see
#   test 2
# on the broker if QoS = 0.

MQTTHandler will not wait for connected, you have to do it yourself. E.g.

mqtthdlr.loop_start()   # Manually connect to the MQTT server
import time; time.sleep(3)   # A dirty way to wait for MQTT connected'test')  # send log message to MQTT broker

MQTTHandler will create a thread to maintain the connection (automatically reconnecting if disconnected) itself. This will make your program never exit. You have to terminate MQTTHandler yourself to stop the MQTTHandler thread.

mqtthdlr.loop_stop()  # Stop MQTT thread




MQTTHandler(host, topic, port=1883, keepalive=60, bind_address='', client_id='', clean_session=True, userdata=None, protocol=mqttc.MQTTv311, qos=0, retain=False)

Reference to paho.mqtt.python.


tls_set(ca_certs, certfile=None, keyfile=None, cert_reqs=ss.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1, ciphers=None)
username_pw_set(username, password)
will_set(topic, payload=None, qos=0, retain=False)

Reference to paho.mqtt.python.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mqtthandler, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size mqtthandler-0.1.3.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page