Skip to content

barK

A lightweight, extensible logging library for Kotlin Multiplatform.

Because every log deserves a good home ๐Ÿ•๐Ÿ 


Why barK?

  • Kotlin Multiplatform


    Full platform parity across Android and iOS from a single shared API.

  • Automatic tag detection


    No more manual TAG constants. barK reads the calling class name from the stack trace automatically.

  • Trainer system


    Plug in any number of output destinations: Logcat, NSLog, files, crash reporters, or your own.

  • Smart test detection


    Automatically switches between system output and colored console output depending on whether you're in a test run.


Installation

Add barK to your project via Maven Central:

build.gradle.kts
repositories {
    mavenCentral()
}

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("com.ivangarzab.bark:bark:<version>")
        }
    }
}
build.gradle
repositories {
    mavenCentral()
}

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                implementation 'com.ivangarzab.bark:bark:<version>'
            }
        }
    }
}

Latest version

Check the badge at the top of this page or Maven Central for the latest release.


Quick Start

Initialize once (e.g. in your Application class):

MyApplication.kt
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        if (BuildConfig.DEBUG) {
            Bark.train(AndroidLogTrainer())
        }
    }
}

Log anywhere:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Bark.d("Activity created")
        Bark.i("User logged in: ${user.name}")
        Bark.e("Network error", exception)
    }
}

Initialize once (e.g. in your App entry point):

MyApp.swift
@main
struct MyApp: App {
    init() {
        #if DEBUG
        Bark.train(trainer: NSLogTrainer())
        Bark.train(trainer: ColoredUnitTestTrainer())
        #else
        Bark.train(trainer: NSLogTrainer(minLevel: .warning))
        #endif
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

Log anywhere:

class UserRepository {
    func saveUser(user: User) {
        Bark.d("Saving user: \(user.name)")
        Bark.i("User saved successfully")
    }
}

Tip

Copy ios/BarkExtensions.swift into your app target for the clean Bark.d(...) syntax shown above.


Log Levels

Method Level Use for
Bark.v() VERBOSE Detailed diagnostic info
Bark.d() DEBUG Development debugging
Bark.i() INFO Key operations, state changes
Bark.w() WARNING Recoverable issues
Bark.e() ERROR Failures affecting functionality

Choose Your Platform