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 my own application only.
-
1All the answers suggest filtering for messages from the app being debugged. Even with these filters on, the Logcat spam from other apps soon fills the log buffer no matter how large it is. Is there a way to tell Eclipse to not collect these messages at all or to keep deleting them periodically?Price– Price2015-05-17 08:32:50 +00:00Commented May 17, 2015 at 8:32
-
1stackoverflow.com/a/32737594/1778421Alex P.– Alex P.2018-06-25 01:18:48 +00:00Commented Jun 25, 2018 at 1:18
-
github.com/kashifrazzaqui/punt Try out this CLI tool - it makes filtering much easier.keios– keios2021-03-09 11:22:24 +00:00Commented Mar 9, 2021 at 11:22
40 Answers
Note: The following answer is over 10 years old. It's probably not the best answer anymore. My current preferred way of accomplishing this is https://stackoverflow.com/a/76551835/1292598
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, to get full logs, you can do:
adb logcat | findstr com.example.package
Logcat logs has got levels at which to get info:
V — Verbose, D — Debug, I — Info, W — Warning, E — Error, F — Fatal, S — Silent
So to get only error logs related to the app, you can update the above command as follows:
adb logcat *:E | findstr com.example.package
23 Comments
pid=$(adb shell ps | grep "package-name" | cut -c10-15) && adb logcat | grep $pidadb logcat | grep `adb shell ps | grep org.videolan.vlc | awk '{print $2")"}'`adb logcat | findstr com.example.packageadb logcat | grep `adb shell ps | grep com.example.package | tr -s [:space:] ' ' | cut -d' ' -f2` Package names are guaranteed to be unique so you can use the Log function with your package name in place of the <tag> and then filter by tag:
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>("<tag>", "message");
adb -d logcat <tag>:<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.
12 Comments
logcat <your package name>:<log level> the answer suggests that it's possible to use the package name as valid filter. I needed to read the answer twice to comprehend what it's actually saying, therefore I recommend to simply change the first line to something like "logcat <tag>:<log level> where <tag> can be your package name if you used also as tag in android.util.Log"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
10 Comments
grep and findstr options, but they are only filtering logs with some value excluding a lot of messages. Your answer is the real one, show all log about the app without excluding log message from another libraries. It's like Android Studio current 'Show only selected' filter. Thanks!pidof exists on the device.This works for me with USB debugging:
The solution was to use your device's own logcat directly via shell.
Connect the device and use:
adb shellUse logcat after the shell is set up:
logcat | grep com.yourapp.packagename
2 Comments
Add filter

Specify names

Choose your filter.

1 Comment
For a debuggable application, I suggest
adb shell run-as my.package.name logcat
run-as doesn't work for non-debuggable applications, so for those I use the --uid flag. Unfortunately there isn't a uidof, so I need to extract it from pm. Here's a small sh script to do that:
function logcat {
pkg="$1"
shift
if [ -z "$pkg" ]; then
>&2 echo 'Usage: logcat pkg ...'
return 1
fi
uid="$(adb shell pm list package -U $pkg | sed 's/.*uid://')"
if [ -z "$uid" ]; then
>&2 echo "pkg '$pkg' not found"
return 1
fi
adb logcat --uid="$uid" "$@"
}
Usage is logcat my.package.name. It accepts additional arguments like normal logcat.
I prefer this to the --pidof based solution (see https://stackoverflow.com/a/48004086/1292598) since that requires you to re-run the command each time the process is restarted.
2 Comments
run-as method is convenient, but unfortunately it sometimes brings up a dialog on the device screen asking whether you want to allow it to access all device logs or just that user's. This blocks the logcat command until you either answer the dialog or allow it to time out.For me this works in mac Terminal
Got to the folder where you have adb then type below command in terminal
./adb logcat MyTAG:V AndroidRuntime:E *:S
Here it will filter all logs of MyTAG and AndroidRuntime
4 Comments
Update May 17
It's been a few years, and thing have changed. And Eclipse is no longer officially supported. So here's two more up-to-date approaches:
1. Android Studio
In the Android monitor toolbox, you can filter logcat per debuggable process. Normally, when you develop an application it is a debuggable process. Every once in a while I am having issues with this, and a do the following:
Tools->Android->Enable ADB Integration.
If it was already enabled, then toggle it off, and then back onUnplug and replug your mobile device.
There are also options to filter via regex and the debug level
2. logcat-color
This is a nice python wrapper on top of adb logcat if you want to use a terminal based solution. The good thing about it is that you can save multiple configurations and simply reuse them. Filtering by tags is quite reliable. You can also filter by package to see logs of one or more apps only, but you start logcat-color right before launching your app.
Old Answer:
It seems that I can't comment to previous answers, so I will post a new one.
This is a comment to Tom Mulcahy's answer, that shows how the command should change so as to work on most devices, since adb shell ps PID column is variable.
NOTE: The command below works for the cases where you have connected many devices. So device id is needed. Otherwise, you can simply omit the brackets '[', ']'
1. To find out the column of pid, type:
adb [-s DEVICE_ID] shell ps | head -n 1
Now memorise the column number for the PID. Numbering starts from 1.
2. Then type the following:
adb [-s DEVICE_ID] logcat | grep $(adb [-s DEVICE_ID] shell ps \
| grep "com.example" | awk -F" " ' {print $PUT_COLUMN_HERE}')
Simply put the column you memorised in PUT_COLUMN_HERE, e.g. $5
Caveat
Each time you re-run your application, you have to re-run the 2nd command, because the application gets a new PID from the OS.
1 Comment
Ubuntu : adb logcat -b all -v color --pid=`adb shell pidof -s com.packagename` With color and continous log of app
3 Comments
adb shell pidof ... bit didn't work for me so I adb shell ed into the device and ran top copied the PID for my app there and then replaced it in your commandpgrep instead of pidofput this to applog.sh
#!/bin/sh
PACKAGE=$1
APPPID=`adb -d shell ps | grep "${PACKAGE}" | cut -c10-15 | sed -e 's/ //g'`
adb -d logcat -v long \
| tr -d '\r' | sed -e '/^\[.*\]/ {N; s/\n/ /}' | grep -v '^$' \
| grep " ${APPPID}:"
then:
applog.sh com.example.my.package
1 Comment
log.d("TAG", "multine\nlog") for example): adb -d logcat -v long | sed -Ene '/^\[.*'" (${APPID}):"'.*\]/ { N; s/\n/ /; p; :a;' -e 'n; p; s/^.+$/foo/; t a;' -e ' }' | grep -v '^$' - I left out the tr, I'm assuming it's needed on Windows systems, and I wrapped the APPID in parentheses to allow mulitple pids (separated by |).Using Windows command prompt: adb logcat -d | findstr <package>.
*This was first mentioned by jj_, but it took me ages to find it in the comments...
Comments
In order to access the logcats you first need to install ADB command-line tool. ADB command-line tool is a part of android studio platform tools and can be downloaded from here. After this, you need to set the path/environment variable for adb tools. Now you can access logcat from eclipse terminal/ intellij terminal or mac terminal in case you are using a macbook.
adb logcat : To get entire logcat.
adb shell pidof 'com.example.debug' : To get the process id of your app.
adb logcat pid=<pid> : To get logcat specific to your app.
adb logcat pid=<pid>|grep 'sometext' : To filter logcat on basis of some text.
For more info about filtering logcats read this.
LogCat Application messages
As a variant you can use third party script PID Cat by Jake Wharton. This script has two major advantages:
- shows log entries for processes from a specific application package
- color logcat
From documentation:
During application development you often want to only display log messages coming from your app. Unfortunately, because the process ID changes every time you deploy to the phone it becomes a challenge to grep for the right thing.
This script solves that problem by filtering by application package.
Comments
If you are using Android Studio you can select the process from which you want to receive logcats. Here is the screenshot.

1 Comment
Log cat has a new option (on by default) which creates an application filter automatically such that only the launched application's output is shownI wrote a shell script for filtering logcat by package name, which I think is more reliable than using
ps | grep com.example.package | cut -c10-15
It uses /proc/$pid/cmdline to find out the actual pid, then do a grep on logcat
Comments
Use -s !
You should use your own tag, look at: http://developer.android.com/reference/android/util/Log.html
Like.
Log.d("AlexeysActivity","what you want to log");And then when you want to read the log use>
adb logcat -s AlexeysActivityThat filters out everything that doesn't use the same tag.
1 Comment
ADT v15 for Eclipse let you specify an application name (which is actually the package value in your androidmanifest.xml).
I love being able to filter by app, but the new logcat has a bug with the autoscroll. When you scroll up a little to look at previous logs, it automatically scrolls back to the bottom in a couple seconds. It seems scrolling 1/2 way up the log does keep it from jumping back to the bottom, but that's often useless.
EDIT: I tried specifying an app filter from the command-line -- but no luck. If someone figures this out OR how to stop the autoscroll, please let me know.
Comments
I am usually adding something in the log messages to make it distinct. Or for example unity app you can use "Unity" as matching string.
For mac :
adb logcat | grep "MyUniqueString"
for Windows (powershell ):
adb logcat | Select-String "MyUniqueString"
1 Comment
grep implementation helped a lot!If you are using Eclipse, press the green + sign in the logCat window below and put your package name (com.example.yourappname) in the by Application Name box. Also, choose any name comfortable to you in Filter Name box and click ok. You will see only messages related to your application when the filter you just added is chosen from the left pane in the logCat.
Comments
Give your log a name. I called mine "wawa".

In Android Studio, go to Android-> Edit Filter Configurations

Then type in the name you gave the logs. In my case, it's called "wawa". Here are some examples of the types of filters you can do. You can filter by System.out, System.err, Logs, or package names:

Comments
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`"
Comments
I tried to use Tom Mulcahy's answer but unfortunately it was not working for applications with multiple processes so I edit it to fit my needs.
#!/bin/bash
if [ "$#" -ne 1 ]; then echo "Illegal number of parameters"; exit 1; fi
echo "Lof for package name: $1"
PROCESSES=`adb shell ps | grep "$1" | cut -c10-15`
NUM_OF_PROCESSES=`echo "$PROCESSES" | wc -l`
if [ $NUM_OF_PROCESSES -eq 0 ]; then echo "The application is not running!"; exit 1; fi
COUNTER=1
for process in $PROCESSES; do
if [ $COUNTER -eq 1 ]; then GREP_TEXT="("; fi
GREP_TEXT+=$process
if [ $COUNTER -eq $NUM_OF_PROCESSES ]; then GREP_TEXT+=")"; else GREP_TEXT+="|"; fi
let COUNTER=COUNTER+1
if [ $COUNTER -gt $NUM_OF_PROCESSES ]; then break; fi
done
adb logcat | grep -E "$GREP_TEXT"
