Feedback

JavaJava V4 SDK Troubleshooting Guide

 

These docs are for PubNub 4.0 for Java which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.0 for Java and PubNub 3.0 for Android.

If you have questions about the PubNub for Java SDK, please contact us at support@pubnub.com.

Pubnub implements swappable logging using SLF4J, which allows you to switch different logging frameworks easily. All the logging calls using SLF4J API will be delegated to the underlying logging framework.

setLogVerbosity to PNLogVerbosity.BODY. For more info on configuration, please check the API reference page.

PNConfiguration pnConfiguration = new PNConfiguration();

pnConfiguration.setLogVerbosity(PNLogVerbosity.BODY);

To implement logging using log4j you need to add the following references to the project. Using log4j you can log to console or a file or both.

  • slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API
  • slf4j-log4j jar file (e.g. slf4j-log4j-1.7.5.jar or a latest version) which acts as a bridge between slf4j and log4j
  • log4j jar file (log4j-1.2.17.jar or a latest version), which provides the underlying logging framework
Along with these references you need to add the log4j.properties file in the CLASSPATH
			# Root logger option
			log4j.rootLogger=ALL, FILE
			
			# Direct log messages to a log file
			log4j.appender.FILE =org.apache.log4j.FileAppender
			log4j.appender.FILE.File=/Users/rajat/Projects/eclipsews/log4jloging.log
			log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
			log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
		
			log4j.appender.console=org.apache.log4j.ConsoleAppender
			log4j.appender.console.Threshold=DEBUG
			log4j.appender.console.Target=System.out
			log4j.appender.console.layout=org.apache.log4j.PatternLayout
			log4j.appender.console.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n
		
More info can be found here.

To implement logging using simple slf4j you need to add the following references to the project:

  • slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API.
  • slf4j-simple jar file (e.g. slf4j-simple-1.7.5.jar or a latest version) which provides the underlying logging framework.
  • Along with these references you need to add the simplelogger.properties file in the CLASSPATH.
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS

To implement logging using logback-classic you need to add the following references to the project:

To implement logging using java.util.logging you need to add the following references to the project:

  • slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API.
  • slf4j-jdk14 jar file which acts as a bridge between slf4j and java.
JVM runtime provides the underlying logging framework.

To implement logging using commons-logging you need to add the following references to the project:

  • slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API.
  • slf4j-jcl jar file (e.g. slf4j-jcl-1.7.15.jar or a latest version) which acts as a bridge between slf4j and common-logging.
  • common-logging.jar file which acts as an abstraction layer.
The underlying logging framework is chosen dynamically by commons-logging.

To implement no logging you have two options:

  • Option 1:
    Add the reference of slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API and nothing else.
  • Option 2:
    • Add the reference of slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API.
    • And add a reference to slf4j-nop jar file (e.g. slf4j-nop-1.7.5.jar or a latest version).
    More info on SLF4J can be found here
CategoryDescription
PNBadRequestCategoryPubNub Java SDK will send PNBadRequestCategory when some parameter is missing like message, channel, subscribe key, publish key.
PNUnexpectedDisconnectCategoryThe SDK is not able to reach the PubNub Data Stream Network because the machine or device are not connected to Internet or this has been lost, your ISP (Internet Service Provider) is having to troubles or perhaps or the SDK is behind of a proxy.
PNTimeoutCategoryProcessing has failed because of request time out.
CategoryDescription
PNUnexpectedDisconnectCategoryThe SDK is not able to reach the PubNub Data Stream Network because the machine or device are not connected to Internet or this has been lost, your ISP (Internet Service Provider) is having to troubles or perhaps or the SDK is behind of a proxy.
PNUnknownCategory

PubNub SDK could return this Category if the URL was not found. Check the channel or channelGroup.

This call throw this Error:

pubNub.subscribe().withPresence().channels(Arrays.asList("awesomeChannel/")).execute();

PNBadRequestCategoryPubNub Java SDK will send PNBadRequestCategory when some parameter is missing like subscribe key, publish key.
PNTimeoutCategoryProcessing has failed because of request time out.
Check out PubNub's other Java-based SDKs, such as Java V4, Android V4