Skip to content

SDK Integration Guide

barK is designed for SDK developers who need flexible, controllable logging that integrators can customize or disable.


Why barK for SDKs?

SDKs have unique logging requirements:

  • Flexibility โ€” Different environments need different logging strategies
  • Transparency โ€” Integrators want to see what your SDK is doing
  • Control โ€” Integrators want to control verbosity or disable it entirely
  • Non-intrusive โ€” SDK logs shouldn't pollute integrator's logs

barK addresses all of these through its trainer system, runtime control, and global tagging.


SDK Setup

Initialize barK in Your SDK

Use a global tag so all logs from your SDK are clearly identifiable:

MySDK.kt
fun initialize(context: Context) {
    if (BuildConfig.DEBUG) {
        Bark.train(AndroidLogTrainer(minLevel = Level.DEBUG))
    } else {
        Bark.train(CrashReportingTrainer(minLevel = Level.ERROR)) // (1)!
    }
    Bark.tag("MySDK") // (2)!
    Bark.i("SDK initialized v${BuildConfig.VERSION_NAME}")
}
  1. In production, only route errors to your crash reporter (don't spam the integrator's Logcat.)
  2. A global tag means every log from your SDK is clearly prefixed with [MySDK], making it easy for integrators to filter.

2. Log Throughout

class PaymentProcessor {
    fun processPayment(amount: Double) {
        Bark.d("Processing payment: $$amount")
        try {
            val result = apiClient.charge(amount)
            Bark.i("Payment successful: ${result.transactionId}")
        } catch (e: NetworkException) {
            Bark.e("Payment failed: network error", e)
            throw e
        }
    }
}

The Integrator's Side

Integrators who also use barK can interact with the same global Bark instance your SDK uses. This is both a feature and a responsibility โ€” document your SDK's logging behavior clearly.

Silence Your SDK's Logs

// In the integrator's app
Bark.muzzle()           // Silences all barK output, including your SDK's
MySdk.doSomething()     // No logs
Bark.unmuzzle()

Add Their Own Trainer

An integrator can stack their own trainer alongside yours:

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        Bark.train(SentryTrainer(minLevel = Level.WARNING)) // (1)!
    }
}
  1. Using Pack.CUSTOMaggregates into all other Trainers without disruption.

Replace Your System Trainer

An integrator can replace your SYSTEM trainer with their own:

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        Bark.train(AndroidLogTrainer(minLevel = Level.INFO)) // (1)!
    }
}
  1. Trains a new SYSTEM trainer :arrow-right: replaces whichever SYSTEM trainer your SDK registered.

Best Practices

  • Use a global tag โ€” makes your SDK's logs easy to identify and filter
  • Default to minimal production logging โ€” errors only, or muzzled entirely
  • Document Pack usage โ€” tell integrators which Pack your trainers use, so they know what they can replace