Logging for JavaScript SDK

How to enable logging

Set logVerbosity to true on initialization.

Required UserId

Always set the userId to uniquely identify the user or device that connects to PubNub. This userId should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the userId, you won't be able to connect to PubNub.

const PubNub = require('pubnub');

// Initialize PubNub with demo keys and logging enabled
const pubnub = new PubNub({
subscribeKey: 'demo', // Replace with your Subscribe Key from the PubNub Admin Portal
publishKey: 'demo', // Replace with your Publish Key from the PubNub Admin Portal
userId: 'loggingDemoUser',
logVerbosity: true // Enable detailed logging
});

console.log("PubNub initialized with logging enabled");

// Helper function to demonstrate a time operation with logs
async function demonstrateTimeOperation() {
try {
show all 48 lines

For more detailed information about the logVerbosity configuration parameter, read the Configuration document.

Contact support

Copy the logs from the console output of the browser as text and submit to support@pubnub.com

Last updated on