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.
interface PrimerLogger {
var logLevel: PrimerLogLevel
fun log (primerLog: PrimerLog )
}
Parameters
override fun log (primerLog: PrimerLog )
Sealed interface PrimerLog
defines various log types for the logging system.
One of DEBUG
, INFO
, WARNING
, ERROR
or NONE
.
The contents of the log message.
Hide sealed interface PrimerLog
Represents a debug log with its log level and message.
Represents an info log with its log level and message.
Represents a warning log with its log level and message.
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:
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:
PrimerLogging.logger = ExampleLogger ()
If you want to change the logs that you receive based on log level, set the logLevel
property like
so:
// 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:
PrimerLogging.logger.logLevel = PrimerLogLevel.DEBUG