Logging for Kotlin SDK
This page explains how to configure logging in the PubNub Kotlin Software Development Kit (SDK) using SLF4J and popular backends.
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.
Set the config property called logVerbosity to PNLogVerbosity.BODY to enable network calls logging. For more info on configuration, check the API reference page.
Configuration parameter details
The logVerbosity parameter is an optional configuration setting with a default value of PNLogVerbosity.NONE.
Available values:
PNLogVerbosity.NONE- Disables logging of network calls.PNLogVerbosity.BODY- Enables logging of network calls, including request and response details.
For more information about this and other configuration options, refer to the Configuration document.
Implement logging on Android
To implement logging on Android you need to add the following dependency to the project.
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.
log4j-slf4j2file which acts as a bridge betweenslf4jandlog4j.log4j-apifile, which provides the underlying logging framework API.log4j-corefile, which provides the underlying logging framework Implementation.
To enable network calls logging, set the PubNub config property called logVerbosity to PNLogVerbosity.BODY and add the following entry to the log4j2.xml configuration file:
See this example:
Implement logging using slf4j-simple
To implement logging using slf4j-simple you need to add the following references to the project.
SLF4J APIdependencySLF4J-Simpledependency which provides the underlying logging framework
Along with these references you need to add the simplelogger.properties file in the CLASSPATH.
See this example:
Example usage of slf4j-simple
Implement logging using logback-classic
To implement logging using logback, you need to add the following references to the project.
Logback classicandlogback-corejar files which provide the underlying logging frameworkLogback coredependency which provides the underlying logging framework
See an sample logback.xml logback config file:
See this example:
Implement logging using java.util.logging
To implement logging using java.util.logging you need to add the following references to the project.
SLF4J APIdependencySLF4J-JDK14dependency which acts as a bridge betweenslf4jandjava
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 APIdependencySLF4J-JCLdependency which acts as a bridge between slf4j and common-loggingcommons-loggingdependency 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:
-
Add the
SLF4J APIdependency which is the SLF4J API and nothing else. -
Add the
SLF4J APIdependency and then add a reference toSLF4J-nopdependency.