PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›kotlin

kotlin

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Access Manager
    • Channel Groups
    • Message Persistence
    • Mobile Push
    • Objects
    • Files
    • Message Actions
    • Miscellaneous
  • Status Events
  • Troubleshooting
  • Change Log
  • Feature Support
  • Platform Support

Troubleshooting PubNub Kotlin SDK

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.

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

val pnConfiguration = PNConfiguration()
pnConfiguration.logVerbosity = PNLogVerbosity.BODY

Implement logging on Android

To implement logging on Android you need to add the following dependency to the project.

  • SLF4J Android dependency

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.

  • SLF4J API dependency
  • SLF4J-LOG4J API dependency which acts as a bridge between slf4j and log4j
  • LOG4j dependency which provides the underlying logging framework

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

# 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

Configure log4j.properties file to write the logs to console

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

Implement logging using slf4j

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

  • SLF4J API dependency
  • SLF4J-Simple dependency which provides the underlying logging framework

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

Sample simplelogger.properties

org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.showDateTime=true
org.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.

  • SLF4J API dependency
  • Logback classic dependency which provides the underlying logging framework
  • Logback core dependency which provides the underlying logging framework

Implement logging using java.util.logging

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

  • SLF4J API dependency
  • SLF4J-JDK14 dependency which acts as a bridge between slf4j and java

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.

  • SLF4J API dependency
  • SLF4J-JCL dependency which acts as a bridge between slf4j and common-logging
  • commons-logging dependency which acts as an abstraction layer

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

No logging

To implement no logging you have two options:

Option 1: Add the SLF4J API dependency which is the SLF4J API and nothing else.

Option 2:

  1. Add the SLF4J API dependency.
  2. Then, add a reference to SLF4J-nop dependency.

More info can be found here.

← Status EventsChange Log →
  • How to enable logging
  • Implement logging on Android
  • Implement logging using log4j
    • Configure log4j.properties file to write the logs to a log file
    • Configure log4j.properties file to write the logs to console
  • Implement logging using slf4j
    • Sample simplelogger.properties
  • Implement logging using logback-classic
  • Implement logging using java.util.logging
  • Implement logging using commons-logging
  • No logging
© PubNub Inc. - Privacy Policy