question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No logging framework implementation when enabling proguard on Android

See original GitHub issue

Hi, I’m using tinylog version 2.0.0 on Android and it worked great. However I recently released my new app and I found out that the log file never gets created. So I started to investigate the issue. What I found out is that as soon as I enable proguard on my release build I receive following output on the logcat when I log something

LOGGER WARN: No logging framework implementation found in classpath. Add tinylog-impl.jar for outputting log entries.

My tinylog.properties file looks like this

writer=rolling file
writer.file=/data/data/test.grill.com/files/test_logs/test_log.txt
writer.level=info
writer.policies=size: 5mb
writer.format={date: HH:mm:ss.SSS} [{thread}] {level}:\n{message}

and it is located in my resources folder. Everything is working when I’m not enabling proguard. Are there some proguard rules which needs to be added when using tinylog with proguard?

Edit: seems that the ServiceLoader could not get anyResourses

classLoader.getResources(name);

returns an empty Enumeration when enabling proguard.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pmwmediacommented, Nov 27, 2019

I found a workaround to tell ProGuard to keep the service files:

protected void onCreate(Bundle savedInstanceState) {
    ServiceLoader.load(LoggingProvider.class);
    ServiceLoader.load(Writer.class);
    ServiceLoader.load(Policy.class);

    super.onCreate(savedInstanceState);

    Logger.error("Test output");

    ...
}

ProGuard rules:

##---------------Begin: tinylog  ----------
-keepnames interface org.tinylog.**
-keepnames class * implements org.tinylog.**
-keepclassmembers class * implements org.tinylog.** { <init>(...); }
##---------------End: tinylog  ----------

I plan to add these ServiceLoader calls directly in tinylog 2.1 to make logging with tinylog for Android developers much more convenient when using ProGuard.

For tinylog 3, I’m experimenting with a builder concept for instantiation of logging providers, writers, and policies. Then, even no ProGuard rules nor any workaround will be required for tinylog. This will also solve #127.

1reaction
pmwmediacommented, Nov 25, 2019

The problem is that tinylog cannot find TinylogLoggingProvider and other classes, which are loaded by ServiceLoader, because Proguard renames all classes. If configure Proguard to keep all tinylog class names, logging should work again:

-keepnames public class org.tinylog.**
Read more comments on GitHub >

github_iconTop Results From Across the Web

No logging framework implementation when enabling ...
I found a workaround to tell ProGuard to keep the service files: protected void onCreate(Bundle savedInstanceState) { ServiceLoader.load ...
Read more >
Importance of Proguard for the Android platform and its ...
ProGuard is an open source command-line tool that detects and removes unused classes, fields, methods, and attributes.
Read more >
Use Proguard only to disable logging and for shrinking ...
I only want to remove log calls and enable shrinking of unused resources. proguard-rules.pro: -assumenosideeffects class android.util.Log { public static ...
Read more >
Understanding Logging | Android Open Source Project
This article covers the process of logging, including log standards, level guidelines, classes, purposes, and multistack approximations.
Read more >
How to Remove Debug Logging with ProGuard?
Your logging methods have a side effect - to output a log. So why do you then need to tell ProGuard to assume...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found