Logging for Python SDK
This page explains how to enable logging in the PubNub Python Software Development Kit (SDK).
How to enable logging
Use this code to enable logging
1import os
2import logging
3from pubnub.pnconfiguration import PNConfiguration
4from pubnub.pubnub import PubNub
5
6# Set up logging for PubNub at DEBUG level
7logging.basicConfig(level=logging.DEBUG)
8pubnub_logger = logging.getLogger('pubnub')
9pubnub_logger.setLevel(logging.DEBUG)
10
11# Configuration for PubNub instance
12pn_config = PNConfiguration()
13pn_config.subscribe_key = os.getenv('SUBSCRIBE_KEY', 'demo') # Replace 'demo' with your subscribe key from the PubNub Admin Portal
14pn_config.publish_key = os.getenv('PUBLISH_KEY', 'demo') # Replace 'demo' with your publish key from the PubNub Admin Portal
15pn_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. The example sets a stream logger at the DEBUG level and subscribes to a channel using a listener.