Advanced Usage
This section covers barK's deeper configuration options: log Level control, tagging strategies, runtime control, and the trainer system internals.
Tagging
Auto-Detection
barK reads the calling class name from the stack trace on every log call:
class PaymentService {
fun processPayment() {
Bark.d("Processing payment") // Tag: [PaymentService]
}
}
class UserRepository {
fun saveUser(user: User) {
Bark.i("Saving user: ${user.name}") // Tag: [UserRepository]
}
}
Note
While this functionality is defaulted in Android, iOS auto-detection needs to enabled manually due to its processing cost.
Global Tag Override
Set a fixed tag that applies across all classes:
Bark.tag("PAYMENTS")
// All calls now use [PAYMENTS]
class PaymentService { fun process() { Bark.d("Processing") } }
class RefundService { fun refund() { Bark.d("Refunding") } }
Bark.untag() // Return to auto-detection
MinLevel Control
Each trainer has an independent minLevel threshold. Logs below the threshold are silently ignored by that trainer, but may still be handled by others:
Bark.train(AndroidLogTrainer(minLevel = Level.VERBOSE)) // (1)!
Bark.train(FileTrainer(minLevel = Level.WARNING, logFile = File("app.log"))) // (2)!
Bark.train(CrashReportingTrainer(minLevel = Level.ERROR)) // (3)!
Bark.v("Logcat only") // (4)!
Bark.w("Logcat + file")
Bark.e("All three trainers")
- Logcat receives everything —
VERBOSEand above. - The file trainer only writes
WARNINGand above, keeping the log file focused on actionable issues. - The crash reporter only activates on
ERRORand above — high-signal, low-noise. - A
VERBOSElog reaches only Logcat. As severity increases, more trainers pick it up.
Level hierarchy:
| Level | Function |
|---|---|
VERBOSE |
Bark.v() |
DEBUG |
Bark.d() |
INFO |
Bark.i() |
WARNING |
Bark.w() |
ERROR |
Bark.e() |
CRITICAL |
Bark.wtf() |
Runtime Control
Muzzle / Unmuzzle
Silence all output without removing trainers:
Bark.muzzle()
Bark.d("This won't appear anywhere")
Bark.e("Neither will this")
Bark.unmuzzle()
Bark.d("Back to normal")