eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.17k stars 723 forks source link

How to log full MQTT packet when logging mode is DEBUG? #688

Closed eercanayar closed 8 months ago

eercanayar commented 1 year ago

Hi all,

The issue title itself is pretty clear but in summary; I would like to log the complete MQTT packet when logging mode is set to DEBUG. How can I implement this on paho.mqtt.python?

Thanks in advance for your guidance.

MattBrittan commented 8 months ago

This is not supported; current logging is:

if self._protocol == MQTTv5:
      self._easy_log(
          MQTT_LOG_DEBUG,
          "Received PUBLISH (d%d, q%d, r%d, m%d), '%s', properties=%s, ...  (%d bytes)",
          message.dup, message.qos, message.retain, message.mid,
          print_topic, message.properties, len(message.payload)
      )
  else:
      self._easy_log(
          MQTT_LOG_DEBUG,
          "Received PUBLISH (d%d, q%d, r%d, m%d), '%s', ...  (%d bytes)",
          message.dup, message.qos, message.retain, message.mid,
          print_topic, len(message.payload)
      )

Logging the payload would be counterproductive in many cases (it's binary so there is no guarantee it's printable and it might be huge!).

If you have a specific requirement for this I'd suggest logging it in your on_message handler.

As this issue is over a year old (sorry about the delay!) I'm going to close it (as I believe the above answers your question and don't believe it's likely that we will begin logging the message body).

Note: This is part of an exercise to clean up old issues so that the project can move forwards. Due to the number of issues being worked through mistakes will be made; please feel free to reopen this issue (or comment) if you believe it's been closed in error.