> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PrimerLogger

To gather useful information from the SDK, you can either use default SDK Logger or
implement and assign a logger that the SDK will use to send log messages.

Log messages are assigned one of five levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `NONE`.

This allows simple and powerful filtering of log messages so that you can, for example, print
debug messages to the local console and send error messages to an external aggregator.

```kotlin KOTLIN theme={"dark"}
interface PrimerLogger {
  var logLevel: PrimerLogLevel
  fun log(primerLog: PrimerLog)
}
```

### Parameters

```kotlin KOTLIN theme={"dark"}
override fun log(primerLog: PrimerLog)
```

Sealed interface `PrimerLog` defines various log types for the logging system.

**Parameters**

**logLevel** `PrimerLogLevel` *required*

One of `DEBUG`, `INFO`, `WARNING`, `ERROR` or `NONE`.

**message** `String` *required*

The contents of the log message.

**primerLog** `PrimerLog` *required*

**sealed interface PrimerLog**

**Debug**

Represents a debug log with its log level and message.

**Info**

Represents an info log with its log level and message.

**Warning**

Represents a warning log with its log level and message.

**Error**

Represents an error log with its log level, message and optional Throwable.

### Implementing your own custom logger

To implement a logger, create a class that implements `PrimerLogger`, like so:

```kotlin KOTLIN theme={"dark"}
class ExampleLogger : PrimerLogger {

  override var logLevel: PrimerLogLevel = PrimerLogLevel.DEBUG

  override fun log(primerLog: PrimerLog) {
    when (primerLog) {
      is PrimerLog.Debug -> Log.d(EXAMPLE_TAG, primerLog.message)
      is PrimerLog.Info -> Log.i(EXAMPLE_TAG, primerLog.message)
      is PrimerLog.Warning -> Log.w(EXAMPLE_TAG, primerLog.message)
      is PrimerLog.Error -> Log.e(EXAMPLE_TAG, primerLog.message, primerLog.throwable)
    }
    /* ... Your custom logging logic here ... */
  }

  private companion object {
    const val EXAMPLE_TAG = "EXAMPLE"
  }
}
```

Then assign an instance to the `logger` property:

```kotlin KOTLIN theme={"dark"}
PrimerLogging.logger = ExampleLogger()
```

If you want to change the logs that you receive based on log level, set the `logLevel` property like
so:

```kotlin KOTLIN theme={"dark"}
// Only `WARNING` and `ERROR` level logs will be sent to your logger
PrimerLogging.logger.logLevel = PrimerLogLevel.WARNING
```

If you don't want to receive any logs, set the log level to `PrimerLogLevel.NONE`.

### Default SDK logger

Note that the default behaviour of the default logger is not to send any logs at all.

You can easily assign `DEBUG` or any other log level to the default logger by simply calling:

```kotlin KOTLIN theme={"dark"}
PrimerLogging.logger.logLevel = PrimerLogLevel.DEBUG
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.