On this page

Logging for PHP SDK

This page explains how to enable logging in the PubNub PHP Software Development Kit (SDK) using Monolog.

How to enable logging

Required UUID

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

1<?php
2
3// Include Composer autoloader (adjust path if needed)
4require_once 'vendor/autoload.php';
5
6use Monolog\Level;
7use Monolog\Logger;
8use Monolog\Handler\StreamHandler;
9use Monolog\Handler\ErrorLogHandler;
10use Monolog\Formatter\LineFormatter;
11use PubNub\PNConfiguration;
12use PubNub\PubNub;
13use PubNub\Exceptions\PubNubException;
14
15/**
show all 101 lines

How to disable logging

You can disable the STDOUT print statements by ommiting configuration of logger. Default PSR/Log/NullLogger will be used.

Using this code sample you can discard all log message output:

1<?php
2
3// Include Composer autoloader (adjust path if needed)
4require_once 'vendor/autoload.php';
5
6use PubNub\PNConfiguration;
7use PubNub\PubNub;
8use PubNub\Exceptions\PubNubException;
9
10/**
11 * Basic PubNub PHP SDK Initialization Example
12 */
13try {
14 // Create a new configuration
15 $pnconf = new PNConfiguration();
show all 45 lines
Last updated on