Skip to content Skip to sidebar Skip to footer

Filter Logcat To Get Only The Messages From My Application In Android?

I observed that when i use Logcat with Eclipse with ADT for Android, I get messages from many other applications as well. Is there a way to filter this and show only messages from

Solution 1:

Linux and OS X

Use ps/grep/cut to grab the PID, then grep for logcat entries with that PID. Here's the command I use:

adb logcat | grep -F "`adb shell ps | grep com.asanayoga.asanarebel  | tr -s [:space:] ' ' | cut -d' ' -f2`"

(You could improve the regex further to avoid the theoretical problem of unrelated log lines containing the same number, but it's never been an issue for me)

This also works when matching multiple processes.

Windows

On Windows you can do:

adb logcat | findstr com.example.package

Solution 2:

Package names are guaranteed to be unique so you can use the Log function with the tag as your package name and then filter by package name:

NOTE: As of Build Tools 21.0.3 this will no longer work as TAGS are restricted to 23 characters or less.

Log.<log level>("<your package name>", "message");

adb -d logcat <your package name>:<log level> *:S

-d denotes an actual device and -e denotes an emulator. If there's more than 1 emulator running you can use -s emulator-<emulator number> (eg, -s emulator-5558)

Example: adb -d logcat com.example.example:I *:S

Or if you are using System.out.print to send messages to the log you can use adb -d logcat System.out:I *:S to show only calls to System.out.

You can find all the log levels and more info here: https://developer.android.com/studio/command-line/logcat.html

http://developer.android.com/reference/android/util/Log.html

EDIT: Looks like I jumped the gun a little and just realized you were asking about logcat in Eclipse. What I posted above is for using logcat through adb from the command line. I'm not sure if the same filters transfer over into Eclipse.

Solution 3:

Since Android 7.0, logcat has --pid filter option, and pidof command is available, replace com.example.app to your package name. (ubuntu terminal / Since Android 7.0)

adb logcat --pid=`adb shell pidof -s com.example.app`

or

adb logcat --pid=$(adb shell pidof -s com.example.app)

For more info about pidof command: https://stackoverflow.com/a/15622698/7651532

Solution 4:

Add filter

Add filter

Specify names

enter image description here

Choose your filter.

enter image description here

Solution 5:

This works for me with USB debugging:

The solution is to use your device's own logcat directly via shell.

  1. Connect the device and use:

    adb shell

  2. Use logcat after the shell is set up:

    logcat | grep com.yourapp.packagename

Post a Comment for "Filter Logcat To Get Only The Messages From My Application In Android?"