adafruit / Adafruit_CircuitPython_MiniMQTT

MQTT Client Library for CircuitPython
Other
73 stars 50 forks source link

use logger with NullHandler by default #146

Closed vladak closed 1 year ago

vladak commented 1 year ago

There is a lot blocks in MQTT that go like this:

    if self.logger is not None:
        self.logger.debug("Setting last will properties")

The check for the logger makes the code more difficult to read. Setting a logger with NullHandler by default and replacing the handler with StreamHandler in enable_logger() would avoid these contructs.

tekktrik commented 1 year ago

Sounds like a good improvement to readability!

tekktrik commented 1 year ago

Do you want to submit a PR for this?

dastels commented 1 year ago

The whole idea of a null handler (the null object pattern in general) is so you don't have to do checks like that. Someone didn't get the memo I guess.

vladak commented 1 year ago

Do you want to submit a PR for this?

Possibly, eventually. I have some other changes in the works that would merge badly with this change.