How to filter Android logcat by application? [dupl

2019-01-04 19:43发布

This question already has an answer here:

How can I filter Android logcat output by application? I need this because when I attach a device, I can't find the output I want due to spam from other processes.

27条回答
走好不送
2楼-- · 2019-01-04 19:47

On my Windows 7 laptop, I use 'adb logcat | find "com.example.name"' to filter the system program related logcat output from the rest. The output from the logcat program is piped into the find command. Every line that contains 'com.example.name' is output to the window. The double quotes are part of the find command.

To include the output from my Log commands, I use the package name, here "com.example.name", as part of the first parameter in my Log commands like this:

Log.d("com.example.name activity1", "message");

Note: My Samsung Galaxy phone puts out a lot less program related output than the Level 17 emulator.

查看更多
倾城 Initia
3楼-- · 2019-01-04 19:47

This is probably the simplest solution.

On top of a solution from Tom Mulcahy, you can further simplify it like below:

alias logcat="adb logcat | grep `adb shell ps | egrep '\bcom.your.package.name\b' | cut -c10-15`"

Usage is easy as normal alias. Just type the command in your shell:

logcat

The alias setup makes it handy. And the regex makes it robust for multi-process apps, assuming you care about the main process only.

Of coz you can set more aliases for each process as you please. Or use hegazy's solution. :)

In addition, if you want to set logging levels, it is

alias logcat-w="adb logcat *:W | grep `adb shell ps | egrep '\bcom.your.package.name\b' | cut -c10-15`"
查看更多
等我变得足够好
4楼-- · 2019-01-04 19:48

Yes now you will get it automatically....
Update to AVD 14, where the logcat will automatic session filter
where it filter log in you specific app (package)

查看更多
Deceive 欺骗
5楼-- · 2019-01-04 19:48

to filter the logs on command line use the below script

adb logcat com.yourpackage:v

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-04 19:50

I use to store it in a file:

        int pid = android.os.Process.myPid();
        File outputFile = new File(Environment.getExternalStorageDirectory() + "/logs/logcat.txt");
        try {
            String command = "logcat | grep " + pid + " > " + outputFile.getAbsolutePath();
            Process p =  Runtime.getRuntime().exec("su");
            OutputStream os = p.getOutputStream();
            os.write((command + "\n").getBytes("ASCII"));
        } catch (IOException e) {
            e.printStackTrace();
        }
查看更多
虎瘦雄心在
7楼-- · 2019-01-04 19:52

Hi I got the solution by using this :

You have to execute this command from terminal. I got the result,

adb logcat | grep `adb shell ps | grep com.package | cut -c10-15`
查看更多
登录 后发表回答