On this page

Error logging

How to enable logging

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.

By default, when you initialize Kotlin Chat SDK, logging is disabled (LogLevel.OFF).

Available logging options include:

ValueDescription
ERROR
Used for logging error messages.
WARN
Used for logging warning messages.
INFO
Usedfor logging informational messages.
DEBUG
Used for logging debug messages.
VERBOSE
The most detailed level of logging. It includes everything at the DEBUG level and more fine-grained information.

To start log events, set LogLevel to one of the above values by passing it in ChatConfiguration.

1val chatConfig = ChatConfiguration(logLevel = LogLevel.INFO)
2val pnConfiguration = PNConfiguration.builder(userId = UserId("myUserId"), subscribeKey = "mySubscribeKey").build()
3
4Chat.init(chatConfig, pnConfiguration).async { result ->
5 result.onSuccess { chat: Chat ->
6 println("Chat successfully initialized having logLevel: ${chatConfig.logLevel}")
7 }.onFailure { exception: PubNubException ->
8 println("Exception initialising chat: ${exception.message}")
9 }
10}

Implement logging on Android

Add the following dependency to the project and configure it.

Example configuration:

1

The logs will appear in Logcat.

Implement logging using log4j

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.

Along with these references you need to add the log4j.properties file in the CLASSPATH

Configure log4j.properties file to write the logs to a log file

1# Root logger option
2log4j.rootLogger=ALL, FILE
3
4# Direct log messages to a log file
5log4j.appender.FILE =org.apache.log4j.FileAppender
6log4j.appender.FILE.File=/Users/rajat/Projects/eclipsews/log4jloging.log
7log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
8log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Configure log4j.properties file to write the logs to console

1log4j.appender.console=org.apache.log4j.ConsoleAppender
2log4j.appender.console.Threshold=DEBUG
3log4j.appender.console.Target=System.out
4log4j.appender.console.layout=org.apache.log4j.PatternLayout
5log4j.appender.console.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n

More info can be found here.

Implement logging using slf4j

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

Along with these references you need to add the simplelogger.properties file in the CLASSPATH.

Sample simplelogger.properties

1org.slf4j.simpleLogger.logFile=System.out
2org.slf4j.simpleLogger.defaultLogLevel=debug
3org.slf4j.simpleLogger.showDateTime=true
4org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS

Implement logging using logback-classic

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

Implement logging using java.util.logging

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

JVM runtime provides the underlying logging framework.

Implement logging using commons-logging

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

The underlying logging framework is chosen dynamically by commons-logging.

Last updated on