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
TAGconstants. 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:
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):
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Bark.train(AndroidLogTrainer())
}
}
}
Log anywhere:
Initialize once (e.g. in your App entry point):
@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
-
Android Guide
Get started using barK for Android.
-
iOS Guide
Get started using barK for iOS.