Logging

AbleLib has its own internal logging that helps you track what's going on and get detailed insight into all the steps that it takes and their results. There's also a simple way to pipe Able logging into your own, as well as to limit the log output with options. Each long entry has a textual message and a level.

Logging levels and options

Able logs are filtered by levels that correspond to how much data you want to see in the logs. Log levels are represented by the AbleLogLevel enum, which has the following values:

  • data - all the data exchanged between the phone and the peripheral.
  • debug - messages that might be helpful when debugging an issue, but might be too heavy or too frequent for production build logs.
  • info - messages that indicates that a certain important action is taking place. More suitable for production builds than debug.
  • warning - issues that aren't fatal or that the SDK can recover from (e.g, through retries).
  • error - issues that shouldn't happen under normal circumstainces.

You can set which messages will appear in the log using log options, which are basically sets of log levels. If a log level is not present within the option set, messages with that level won't be printed. AbleLogOptions has several pre-defined option sets that you can use:

  • full - all levels.
  • comm - data, info, warning and error. Suitable for logging all the comm-related data, but without the debug intricacies.
  • debugBuild - debug level and above.
  • productionBuild - info level and above.
  • issuess - warning level and above.
  • none - AbleLogs aren't printed.
  • custom - provide your own, custom options set.

You can set your preferred Able log options at any time in AbleManager:

AbleManager.shared.loggingOptions = AbleLogOptions.Issues

Piping logs to your own output

By default, Able logs are printed to standard output, meaning that you'll see them in Logcat (Android) or Console log (iOS). You can pipe the output to your own custom logging by providing a logging printer:

AbleManager.shared.loggingPrinter = { level, message -> 
        when (level) {
            DATA -> Log.v("myTag", message)
            DEBUG -> Log.d("myTag", message)
            INFO -> Log.i("myTag", message)
            WARNING -> Log.w("myTag", message)
            ERROR -> Log.e("myTag", message)
        }
}