On this page

Logging for Ruby SDK

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

How to enable logging

By default the PubNub SDK keeps logs in pubnub.log located in the script directory. You can pass a custom logger as :logger parameter during initialization of the client.

Required User ID

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.

1require 'pubnub'
2require 'logger'
3
4def setup_logger
5 # Create a logger that outputs to STDOUT (console)
6 logger = Logger.new(STDOUT)
7
8 # Set the log level
9 # Available levels: DEBUG, INFO, WARN, ERROR, FATAL
10 logger.level = Logger::DEBUG
11
12 # Customize the log format
13 logger.formatter = proc do |severity, datetime, progname, msg|
14 date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
15 "[#{date_format}] #{severity}: #{msg}\n"
show all 84 lines
Configuration parameter

The logger parameter is one of many available configuration options when initializing the PubNub client. For a complete list of configuration parameters and their descriptions, see the Configuration document.

Protect sensitive data

Never enable Logger::DEBUG in production environments that handle sensitive information.

DEBUG logs may expose:

  • Complete request URLs, including Access Manager signature and auth token query parameters used for signed requests
  • The full token string returned by grant_token calls, since request/response details are logged in full
  • API keys, user identifiers, and message content

Use Logger::DEBUG only in development environments, and set the logger level to Logger::WARN or Logger::ERROR in production.