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

Tag character limit on Android 6 #339

Closed
dkarv opened this issue Jul 21, 2023 · 3 comments
Closed

Tag character limit on Android 6 #339

dkarv opened this issue Jul 21, 2023 · 3 comments

Comments

@dkarv
Copy link

dkarv commented Jul 21, 2023

I tried to use the logger on an Android 6 device and receive an exception:

FATAL EXCEPTION: main
Process: <package>, PID: 10196
java.lang.RuntimeException: Unable to start activity ComponentInfo{<package>/<package>.LoginActivity}: java.lang.IllegalArgumentException: Log tag "<package>.LoginViewModel" exceeds limit of 23 characters

	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
	at android.app.ActivityThread.-wrap11(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:148)
	at android.app.ActivityThread.main(ActivityThread.java:5466)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Log tag "<package>.LoginViewModel" exceeds limit of 23 characters

	at android.util.Log.isLoggable(Native Method)
	at io.github.oshai.internal.KLoggerAndroid.<init>(KLoggerAndroid.kt:104)
	at io.github.oshai.KotlinLogging.logger(KotlinLogging.kt:34)
	at io.github.oshai.KotlinLogging.logger(KotlinLogging.kt:13)
	at <package>.LoginViewModel.<init>(LoginViewModel.kt:25)
        ...

I removed the full package name and replaced it with . The package + class name (LoginViewModel) has 46 characters.

Android documentation:
https://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String,%20int)

It seems like Logback for Android handles the character limit:
https://github.com/tony19/logback-android/blob/d6ed2017fb87e30e8b32d794523ac29c24123c87/logback-android/src/main/java/ch/qos/logback/classic/android/LogcatAppender.java#L46

Is there any workaround we could use?

@github-actions
Copy link

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

@oshai
Copy link
Owner

oshai commented Jul 21, 2023

what version of kotlin-logging are you using? the default we use is slf4j (in v5) which can be redirect to logback which will handle this (unless add -Dkotlin-logging-to-android-native).

@dkarv
Copy link
Author

dkarv commented Jul 21, 2023

Sorry my fault, we were still using the 4.0.0-beta-27 version. After upgrading to 5.0.0 it works as expected. The logs are sent to slf4j / logback-android and the tag is shortened.
Thanks for your quick help!

@oshai oshai closed this as completed Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants