2017-04-01

Enable DEBUG & VERBOSE for Huawei Android Logcat

I'm having Huawei Nova Plus I found that Huawei only prints to its Android log starting log level INFO. As per Huawei; this is done for performance optimization purposes.

Any Android developer requires logging level DEBUG & VERBOSE.

This post mainly states the trials I have done trying to solve this issue till reached a solution / workaround.

For the record my device information was:
Model number: HUAWEI MLA-L11
Build number: MLA-L11C185B131  &  MLA-L11C185B151
EMUI version: EMUI 4.1
Android version: 6.0

I found same issue in other Huawei models like GT3, Mate 8.

1- Huawei secret menu (Source link with screenshots in xda developers):
Type *#*#2846579#*#* in dialer application, when "ProjectMenu" appears -> 1.Background Settings -> 3. LOG Settings -> mark the check of "AP Log". Reboot your mobile.
Repeat above steps to access secret menu, and check the "AP Log" if you found it is still checked after reboot, your phone is ready :) otherwise try next method.
Note: It didn't work for me, maybe of a bug on Huawei.

2- Set log level for some application tags:

a- Open adb shell while your device is connected, usually located in ANDROID_SDK\platform-tools
adb shell

b- Set log level to verbose for specific tags (change below MYTAG to whatever important tag in your application)
C:\android\sdk\platform-tools>adb shell
shell@HWMLA:/ $ stop
shell@HWMLA:/ $ setprop log.tag.MYTAG VERBOSE
shell@HWMLA:/ $ start
shell@HWMLA:/ $


c- Test your application, and check logs, if it works make the above as script and set all your important tags to be VERBOSE. Downside of this script, is the need to apply it every-time your restart your phone.
Note: It didn't work for me, I don't know why.

3- Workaround using external logging framework (Timber):
a- I switched my code to use Timber (It was pretty easy refactor).

b- I made small customization to Timber.DebugTree & created a class HuaweiTree in my project. It simply switches log level of VERBOSE & DEBUG to INFO so Huawei will print it. The code is below:
package ...;

import android.util.Log;
import timber.log.Timber;


public class HuaweiTree extends Timber.DebugTree {
    @Override
    protected void log(int priority, String tag, String message, Throwable t) {
        if (priority == Log.VERBOSE || priority == Log.DEBUG)
            priority = Log.INFO;
        super.log(priority, tag, message, t);
    }
}


c- Plug this customization to your code, by adding it to your application class onCreate method
    @Override
    public void onCreate() {
        super.onCreate();
       
        // ... As early as possible ...

        if (BuildConfig.DEBUG) {
            String deviceManufacturer = android.os.Build.MANUFACTURER;
            if (deviceManufacturer.toLowerCase().contains("huawei")) {
                Timber.plant(new HuaweiTree());
            } else {
                Timber.plant(new Timber.DebugTree());
            }
        }
        // ... Continue your application ...
    }




I hope in future if I find better solution; I will try to keep this post updated.

12 comments:

  1. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
    Security Services in Chennai

    ReplyDelete
  2. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.

    Digital Marketing Company in Chennai

    ReplyDelete
  3. I am not sure the place you are getting your information, however good topic.I needs to spend some time studying more or understanding more.Thank you for wonderful information I was in search of this info for my mission.

    HR Consultancy in Chennai
    Recruitment Consultancy in Chennai
    Manpower Consultancy in Chennai

    ReplyDelete
  4. Really i enjoyed very much. And this may helpful for lot of peoples. So you are provided such a nice and great article within this.

    MSBI Training in Chennai

    Informatica Training in Chennai

    ReplyDelete
  5. There are lots of information about latest technology and how to get trained in them, like this have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies. By the way you are running a great blog. Thanks for sharing this.

    Laser Root Canal Treatment In Chennai

    Best Dental Clinic In Velachery

    ReplyDelete
  6. I do trust all of the concepts you’ve presented on your post. They’re really convincing and will definitely work. Still, the posts are too brief for newbies. May you please extend them a little from subsequent time?Also, I’ve shared your website in my social networks.
    Office Interiors in Chennai
    Home Interior Decorators in Chennai

    ReplyDelete
  7. Hey Ashraff, thanks for proposing a solution to the logcat problem as opposed to just staying quiet or recommending LOG settings.

    Im having the same issues as yourself, restarting the phone unchecks all of the log settings. Funnilly enough, it used to work before! I wonder if an update screwed things up.

    Do you have any updates regarding this issue? And is your timber solution working within the Android Studio Logcat?

    ReplyDelete
    Replies
    1. u r welcome.

      Updates: I have installed multiple updates till now, and same issue not fixed, I'm waiting for Android 7 with EMUI 5, I hope this might help.

      Solution: yes working perfectly inside Android Studio in the logcat. I found Timber really handy utility, so even if Huawei solved the issue, I will still use this great library but after removing the override ;) I recommend u start using it in all yr incoming projects.

      Delete
    2. Thanks man, I'm going to try this out. on another note, never buying huawei ever again

      Delete
  8. It's like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with some pics to drive the message home a little bit, but instead of that, this is fantastic blog. A great read. I will definitely be back.
    Office Interiors in Chennai
    Interior Decorators in Chennai

    ReplyDelete