Giter Club home page Giter Club logo

slf4j-handroid's Introduction

slf4j-handroid's People

Contributors

mvysny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

slf4j-handroid's Issues

Crash on Android 7.1.2 that Log tag exceeds limit of 23 characters

Typical: the Android API specification is one thing, the implementation of some vendor (ASUS in this case) is something completely different. Quoting Log.isLoggable() javadoc:

IllegalArgumentException is thrown if the tag.length() > 23 for Nougat (7.0) releases (API <= 23) and prior, there is no tag limit of concern after this API level.

Guess what? ASUS_Z00UD with Android 7.1.2 (that is, on fucking API level 25) just failed with:

Caused by java.lang.IllegalArgumentException: Log tag "AedictKDP:sk.baka.aedictkanjidrawpractice.util.android.SodIndex" exceeds limit of 23 characters

       at android.util.Log.isLoggable(Log.java)
       at org.slf4j.impl.AndroidLoggerAdapter.isLoggable(AndroidLoggerAdapter.java:543)
       at org.slf4j.impl.HandroidLoggerAdapter.isLoggable(HandroidLoggerAdapter.java:96)
       at org.slf4j.impl.AndroidLoggerAdapter.log(AndroidLoggerAdapter.java:537)
       at org.slf4j.impl.AndroidLoggerAdapter.info(AndroidLoggerAdapter.java:281)
       at org.slf4j.impl.HandroidLoggerAdapter.info(HandroidLoggerAdapter.java:23)
       at sk.baka.aedictkanjidrawpractice.util.android.SodIndex.<init>(SodIndex.kt:54)
       at sk.baka.aedictkanjidrawpractice.util.android.SodCache.<init>(SodCache.kt:27)
       at sk.baka.aedictkanjidrawpractice.util.android.SodCacheKt.<clinit>(SodCache.kt:82)
       at sk.baka.aedictkanjidrawpractice.util.android.SodCacheKt.getSodCache(SodCache.kt:82)
       at sk.baka.aedictkanjidrawpractice.MainActivity.showKanji(MainActivity.kt:47)
       at sk.baka.aedictkanjidrawpractice.MainActivity.onCreate(MainActivity.kt:70)
       at android.app.Activity.performCreate(Activity.java:6684)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2637)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2751)
       at android.app.ActivityThread.-wrap12(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1496)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6186)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

Maybe in the fucked-up Android world, 25 is less or equal than 23. This is the typical example of Android fragmentation and how defensively one must do code in such environment. Don't anything for granted. What a load of shit.

Improve package shortening algorithm

The default package shortening algorithm which shortens sk.baka.aedict.united.KanjidicQuery to s*.b*.a*.u*.KanjidicQuery is next to useless, since shorter classes gets shortened to s*.b*.a*.uni*.Foo and thus it's hard to grep logs for particular lines. Consider this log cat:

12-11 22:53:47.320: I/PlayCommon(11656): [169] com.google.android.play.a.g.e(853): Preparing logs for uploading
12-11 22:53:47.321: I/PlayCommon(11656): [169] com.google.android.play.a.g.e(855): No file ready to send
12-11 22:53:48.736: I/s*.b*.a*.u*.LoaderEx(20011): Loader #53 KanjiMatchingLoader{3 strokes, fuzzy1out=false, fuzzy2out=false} canceled: canceled
12-11 22:53:48.742: I/s*.b*.a*.u*.LoaderEx(20011): Loader #54 KanjiMatchingLoader{1 strokes, fuzzy1out=false, fuzzy2out=false}: returned 1 item(s) in 5ms (scheduled: 0ms, running: 5ms)

I have no idea where the log came from, and I'm the author of the app! ;)

I propose to drop the package names altogether (since Android's limitation to 23 characters, WTF) and instead introduce a customized prefix, e.g. "AedDict" for "Aedict Dictionary", "Twitter", "AedKanjPad" for "Aedict Kanji Pad Extension"; the point is that the app will have to define this and it won't change in the runtime. Max 10 characters, so that there is one char left for a dot, and 12 characters for the name class. Ridiculous but it can't be helped. The logged names would then appear as "AedDict.KanjidicQuery"

Missing proguard rules for Crashlytics methods cause NoSuchMethodException

When the slf4j-handroid is loaded and it attempts to get the Crashlytics.log and Crashlytics.logException methods, it won't find them if they are not called directly within the application code and throw a NoSuchMethodException. These methods will have been removed during the build process and thus unavailable at runtime.
Because of where these methods are loaded by slf4j-handroid, this happens whether the caller wants Crashlytics integration or not.

Adding rules to the proguard-rules (proguard-rules.pro), keeping the Crashlytics static methods, fixes this problem.

-keep class com.crashlytics.android.Crashlytics {
    public static void log(int, java.lang.String, java.lang.String);
    public static void logException(java.lang.Throwable);
}

Thanks so much for putting this library together

Why use the example HandroidLoggerAdapter changes if it makes no difference?

HandroidLoggerAdapter.DEBUG = BuildConfig.DEBUG;
HandroidLoggerAdapter.ANDROID_API_LEVEL = Build.VERSION.SDK_INT;
HandroidLoggerAdapter.APP_NAME = "MyApp";

If the 23 character limit still exists on devices then why encourage setting the ANDROID_API_LEVEL at a high sdk value?

From the docs

Set this to 24 or higher, to notify Handroid that Android finally dropped the retarded 23 character limit on logger name.

Don't access Crashlytics eagerly

HandroidLoggerAdapter tries to eagerly detect the presence of Crashlytics in static initializer. However, it does so by calling Class.forName("com.crashlytics.android.Crashlytics"); which tries to load the Crashlytics class. But if Multidex is not yet installed and Crashlytics is present in classes-2.dex that function will fail and Crashlytics will fail to initialize later on, with a very cryptic message:

04-14 19:12:08.411 3609-3609/? E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.crashlytics.android.answers.Answers
        at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:29)
        at sk.baka.photoframe.App.onCreate(App.java:97)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
        at android.app.ActivityThread.access$1300(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.