peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

Use dprint() for memory function #78

Closed bobveringa closed 2 years ago

bobveringa commented 2 years ago

Replace the original print function with a self.dprint() function. This should have no impact on existing users. Given that the memory function only prints if the client is in debug mode.

The reason for this change is that some users (like me) subclass the entire MQTTClient class to add additional features. One of the features is that it uses the ulogging module to print instead of regular print statements. The subclass simply overwrites .dprint() with something like this

import ulogging

logger = ulogging.getLogger(__name__)

class NewMQTTClient(MQTTClient):
    def __init__(self, config):
        # Additional logic

        super().__init__(config)

    def dprint(self, *args):
        logger.debug(*args)

This PR ensures that there are no changes needed to the library for users to add the logging module to it.