Logging for Ruby 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 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.

require 'pubnub'
require 'logger'

def setup_logger
# Create a logger that outputs to STDOUT (console)
logger = Logger.new(STDOUT)

# Set the log level
# Available levels: DEBUG, INFO, WARN, ERROR, FATAL
logger.level = Logger::DEBUG

# Customize the log format
logger.formatter = proc do |severity, datetime, progname, msg|
date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
"[#{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.

Last updated on