---
source_url: https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/features/error-logging
title: Error logging
updated_at: 2026-06-15T12:11:32.282Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Error logging

## How to enable logging

PubNub implements swappable logging using `SLF4J`, allowing you to switch logging frameworks easily. By default, the log level is set to `LogLevel.WARN` when you [initialize Chat SDK](https://www.pubnub.com/docs/chat/kotlin-chat-sdk/build/configuration#initialize-pubnub).

Available logging options include:

| Value | Description |
| --- | --- |
| `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. Includes everything at `DEBUG` level and more fine-grained information. |

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

```kotlin
val chatConfig = ChatConfiguration(logLevel = LogLevel.INFO)
val pnConfiguration = PNConfiguration.builder(userId = UserId("myUserId"), subscribeKey = "mySubscribeKey").build()

Chat.init(chatConfig, pnConfiguration).async { result ->
    result.onSuccess { chat: Chat ->
        println("Chat successfully initialized having logLevel: ${chatConfig.logLevel}")
    }.onFailure { exception: PubNubException ->
        println("Exception initialising chat: ${exception.message}")
    }
}
```

## Implement logging on Android

Add the following dependency to the project and configure it.

* [Logback Android dependency](https://mvnrepository.com/artifact/com.github.tony19/logback-android/2.0.1)

Example configuration:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- Android LogCat appender with simple pattern -->
    <appender name="LOGCAT" class="ch.qos.logback.classic.android.LogcatAppender">
        <encoder>
            <pattern>%logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- Set DEBUG level for PubNub packages -->
    <logger name="com.pubnub" level="TRACE" />

    <!-- Root logger -->
    <root level="INFO">
        <appender-ref ref="LOGCAT" />
    </root>
</configuration>
```

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](https://mvnrepository.com/artifact/org.slf4j/slf4j-api)
* [SLF4J-LOG4J API dependency](https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12) which acts as a bridge between slf4j and log4j
* [LOG4j dependency](https://mvnrepository.com/artifact/log4j/log4j) 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

```kotlin
# 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

```kotlin
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](https://www.tutorialspoint.com/log4j/log4j_configuration.htm).

## Implement logging using slf4j

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

* [SLF4J API dependency](https://mvnrepository.com/artifact/org.slf4j/slf4j-api)
* [SLF4J-Simple dependency](https://mvnrepository.com/artifact/org.slf4j/slf4j-simple) which provides the underlying logging framework

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

### Sample simplelogger.properties

```kotlin
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](https://mvnrepository.com/artifact/org.slf4j/slf4j-api)
* [Logback classic dependency](https://mvnrepository.com/artifact/ch.qos.logback/logback-classic) which provides the underlying logging framework
* [Logback core dependency](https://mvnrepository.com/artifact/ch.qos.logback/logback-core) 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](https://mvnrepository.com/artifact/org.slf4j/slf4j-api)
* [SLF4J-JDK14 dependency](https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14) 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](https://mvnrepository.com/artifact/org.slf4j/slf4j-api)
* [SLF4J-JCL dependency](https://mvnrepository.com/artifact/org.slf4j/slf4j-jcl) which acts as a bridge between slf4j and common-logging
* [commons-logging dependency](https://mvnrepository.com/artifact/commons-logging/commons-logging) which acts as an abstraction layer

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