Logging for Python SDK
How to enable logging
Use this code to enable logging
import os
import logging
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
# Set up logging for PubNub at DEBUG level
logging.basicConfig(level=logging.DEBUG)
pubnub_logger = logging.getLogger('pubnub')
pubnub_logger.setLevel(logging.DEBUG)
# Configuration for PubNub instance
pn_config = PNConfiguration()
pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo') # Replace 'demo' with your subscribe key from the PubNub Admin Portal
pn_config.publish_key = os.getenv('PUBLISH_KEY', 'demo') # Replace 'demo' with your publish key from the PubNub Admin Portal
pn_config.user_id = os.getenv('USER_ID', 'my_debug_user_id')
show all 23 linesPackage-level function call
You should call the set_stream_logger()
function on the package level and not the PubNub instance.
For a practical example of enabling logging with subscription operations, see the Basic subscribe with logging section in the Publish and Subscribe document.