Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AndroidLogger can't be turned off via ADB #2014

Open
yogurtearl opened this issue Oct 2, 2024 · 0 comments
Open

AndroidLogger can't be turned off via ADB #2014

yogurtearl opened this issue Oct 2, 2024 · 0 comments

Comments

@yogurtearl
Copy link

yogurtearl commented Oct 2, 2024

Describe the bug

I would like to be able to toggle the koin logging level via ADB
e.g.
adb shell setprop log.tag.Koin ERROR should turn it off
adb shell setprop log.tag.Koin INFO should turn it on

for this to work you have to:

  1. check Log.isLoggable
  2. use a tag that doesn't contain special characters (i.e. [ ]) .

Here is the suggested fix:

const val KOIN_TAG = "Koin"
class AndroidLogger(level: Level = Level.INFO, val tag: String = KOIN_TAG) : Logger(level) {
    override fun display(level: Level, msg: MESSAGE) {
        when (level) {
            Level.DEBUG -> if (Log.isLoggable(tag, Log.DEBUG)) Log.d(tag, msg)
            Level.INFO -> if (Log.isLoggable(tag, Log.INFO)) Log.i(tag, msg)
            Level.WARNING -> if (Log.isLoggable(tag, Log.WARN)) Log.w(tag, msg)
            Level.ERROR -> if (Log.isLoggable(tag, Log.ERROR)) Log.e(tag, msg)
            Level.NONE -> { /* do nothing */ }
        }
    }
}

compare with the current AndroidLogger

class AndroidLogger(level: Level = Level.INFO) : Logger(level) {
override fun display(level: Level, msg: MESSAGE) {
when (level) {
Level.DEBUG -> Log.d(KOIN_TAG, msg)
Level.INFO -> Log.i(KOIN_TAG, msg)
Level.WARNING -> Log.w(KOIN_TAG, msg)
Level.ERROR -> Log.e(KOIN_TAG, msg)
else -> Log.e(KOIN_TAG, msg)
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants