Logcat log warning/errors

前端 未结 2 1471
名媛妹妹
名媛妹妹 2021-01-19 20:19

When I connect my galaxy s3 mini via ADB and try debug application with android studio I get endless error/warning messages in logcat, non-stop messages goes like crazy. Is

相关标签:
2条回答
  • 2021-01-19 20:32

    Simplest answer is that is normal to see all this verbose logging (the logcat contains info from everything on the phone, so can get quite verbose).

    You can filter what is shown in logcat by using filters. If using the command line, it might look something like this (don't forget the end S:* - which indicates to 'Silence' everything. A simple tag filter from command line might look like this (show only messages with tags SHOWTAG1, and SHOWTAG2:

    adb logcat SHOWTAG1:* SHOWTAG2:* S:*
    

    The eclipse tooling (and maybe Android Studio, not sure) also has a Logcat viewer, which allows you to apply tags to filter by, or otherwise, use Regex or other filtering mechanisms to modify what is shown.

    Bottom line, Logcat is verbose, you will need to filter it specifically to see what you want.

    0 讨论(0)
  • 2021-01-19 20:53

    Is that normal?

    Yes - the system itself as well as every app uses logging and that's what you're seeing. A bare-bones emulator won't have many apps with receivers and services running so you won't see the same amount of logging.

    How can I fix this problem?

    You can't as such but you can reduce it by force closing various apps from "Settings" on the device. Not necessarily a good idea but it's your choice.

    You can improve things by using package TAGs in your code and then applying a filter to only show logcat data with your TAGs.

    Example...

    package com.mycompany.mypackage
    
    public class MyActivity extends Activity {
    
        protected final String TAG = getClass().getName();
    
    }
    

    In the above TAG will be "com.mycompany.mypackage.MyActivity". Use protected as the modifier so any classes which extend MyActivity will automatically assign their own class name to TAG.

    When logging you just use `Log.d(TAG, "Some text");

    You then just need to filter on "com.mycompany.mypackage" to only see logging from your own app components.

    0 讨论(0)
提交回复
热议问题