Filter LogCat to get only the messages from My Application in Android?
Asked Answered
W

38

484

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.

Waltraudwaltz answered 28/7, 2011 at 4:34 Comment(3)
All 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?Mannerly
https://mcmap.net/q/81015/-adb-shell-logcat-with-package-nameSalo
github.com/kashifrazzaqui/punt Try out this CLI tool - it makes filtering much easier.Mixon
D
328

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.

Depressor answered 28/7, 2011 at 4:43 Comment(12)
I know the question was about eclipse, but I'm in love with command line and always use it for logcat as well. Also use some tools for coloring the output like jsharkey.org/blog/2009/04/22/… makes it even usefulTaxicab
Testing on emulator : it stuck for me when i execute adb -e logcat com.example.example:I *:S, adb -d logcat System.out:I *:S working.Spaak
@Shubh What do you mean it was stuck? I posted this almost a year ago so something in Logcat may have changed since then.Depressor
might be possible, but happening is when I execute " execute adb -e logcat com.example.example:I *:S" for my emulator it not respond anything, might be i am giving wrong argument.Spaak
@Shubh I just tested it on a device running 4.0.4 and a 2.3.3 emulator; worked fine in both cases. Are you sure the tag you're using is "com.example.example"? Such as Log.i("com.example.example", "TESTING LOGGING"). That adb command is correct.Depressor
This method filters by tag, not by app. Tom's method filters by appAmperage
@JonasAlves You should read the original question again. OP asked for a way to filter out log output from applications other than his own, which assigning a unique tag accomplishes. Tom's method below accomplishes the same thing, but uses a more roundabout method which won't help you if you want to use the Logcat GUI in Eclipse. This doesn't make the info in my answer any less relevant or correct.Depressor
I agree with Jonas comments. I am an beginner, and I am learning from a book. The book suggests to use a specific TAG for each Activity, and I believe most of others do so. As a result, it is a common question 'can I logcat by filtering with my package name, e.g. com.xxx.myapp', and I am actually looking for the solution that Tom provided. ThanksPashto
@Flow Read the question and my answer again. The point was to set the logtag as the package name and then filter by that tag since the package name is guaranteed to be unique. If you read my answer more carefully you'll notice that I never claim to filter by package name. Take special note of the first edit.Depressor
By using 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"Evolution
The answer doesn't answer the question; lots of times you'll want messages from libraries and you aren't able to change the tag.Horseplay
This is not the good answer. Thanks for the comments here (highly rated) that clarify that this answer here is actually misleading. It is sad to see that this wrong answer got the highest ratings and approval, it shouldn'tLoiretcher
S
468

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://mcmap.net/q/79831/-filter-logcat-to-get-only-the-messages-from-my-application-in-android

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
Sensorimotor answered 26/3, 2012 at 9:26 Comment(22)
How to use this command in windows? specially the ` replacement in windows?Spineless
@BTRNaidu: You can install Cygwin or use git-bash (bash for windows)Pseudohermaphrodite
Is there any way to do this programmatically within the Andorid app? I'm trying to use Runtime.getRuntime().exec(THIS_COMMAND) but it hangs the app.Carnify
What do all those parameters mean?Kinnard
You can use this command if you want to get logs of your application just replace package-name with you app's package name "pid=$(adb shell ps | grep "package-name" | cut -c10-15) && adb logcat | grep $pid"Nashner
pid=$(adb shell ps | grep "package-name" | cut -c10-15) && adb logcat | grep $pidNashner
This works great when you have only one device plugged in, but unfortunately if you have > 1 android device plugged in, when you specify -s <deviceID> to adb, the command doesn't work. Anyone know how to incorporate with adb -s?Foppish
I had to add "-a" to the grep command. For some reason there was an occasional character that made grep think it was a binary file. "-a" forces text-mode.Anni
somtimes gc print the same number with pid number of a process when free memory. here is an another version adb logcat | grep `adb shell ps | grep org.videolan.vlc | awk '{print $2")"}'`Anele
Is there a way to modify this to include services and background tasks? I find they have different PID's than the actual application, yet Android Studio is able to capture full process-subprocess logs. Not sure how to accommodate this.Amil
On Windows you can do: adb logcat | findstr com.example.packageCoyote
I don't know if it's by a different version of adb, or just by running on Windows, but I had to use cut -c11-15. Works perfect!Annapolis
Just a minor change to your answer. I would suggest: adb logcat | grep `adb shell ps | grep com.example.package | tr -s [:space:] ' ' | cut -d' ' -f2` Fibrinous
I think this is the only-really-working-command-line in all this ocean of answers.Ticktacktoe
As @Fibrinous mentioned in his answer, I suggest to remove the double quotes since its not working for me, So the one-liner becomes for me: adb logcat | grep -F `adb shell ps | grep com.example.app | cut -c10-15` Dardanelles
No solution based on grep will work, since it assumes messages are on a single line.Horseplay
My version of this adb logcat | grep -i `adb shell ps | grep $1 | cut -c11-15` it's in a script and I just pass in the package nameJungjungfrau
The rare case where the windows example is simpler!!Hawsepiece
My version: adb logcat --pid=`adb shell ps -o PID,Name | grep com.example.app | cut -d' ' -f1`Balneology
@R. the --pid doesn't work if the program is not running at that moment. For example if you want to catch the crash of a program the PID only exists for a brief moment, you have to do it differently.Hartzog
The grep or findstr approach doesn't work in most cases, since the debug info for a package can be multi-line, and only the first (the title) will contain com.example.app.Hartzog
Yeah, I wrote this answer over 10 years ago. It was a reasonable approach at the time, but there are better mechanisms today. Personally, I use an alias that leverages the --uid flag, along with some adb shell pm magic to extract the correct uid.Sensorimotor
D
328

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.

Depressor answered 28/7, 2011 at 4:43 Comment(12)
I know the question was about eclipse, but I'm in love with command line and always use it for logcat as well. Also use some tools for coloring the output like jsharkey.org/blog/2009/04/22/… makes it even usefulTaxicab
Testing on emulator : it stuck for me when i execute adb -e logcat com.example.example:I *:S, adb -d logcat System.out:I *:S working.Spaak
@Shubh What do you mean it was stuck? I posted this almost a year ago so something in Logcat may have changed since then.Depressor
might be possible, but happening is when I execute " execute adb -e logcat com.example.example:I *:S" for my emulator it not respond anything, might be i am giving wrong argument.Spaak
@Shubh I just tested it on a device running 4.0.4 and a 2.3.3 emulator; worked fine in both cases. Are you sure the tag you're using is "com.example.example"? Such as Log.i("com.example.example", "TESTING LOGGING"). That adb command is correct.Depressor
This method filters by tag, not by app. Tom's method filters by appAmperage
@JonasAlves You should read the original question again. OP asked for a way to filter out log output from applications other than his own, which assigning a unique tag accomplishes. Tom's method below accomplishes the same thing, but uses a more roundabout method which won't help you if you want to use the Logcat GUI in Eclipse. This doesn't make the info in my answer any less relevant or correct.Depressor
I agree with Jonas comments. I am an beginner, and I am learning from a book. The book suggests to use a specific TAG for each Activity, and I believe most of others do so. As a result, it is a common question 'can I logcat by filtering with my package name, e.g. com.xxx.myapp', and I am actually looking for the solution that Tom provided. ThanksPashto
@Flow Read the question and my answer again. The point was to set the logtag as the package name and then filter by that tag since the package name is guaranteed to be unique. If you read my answer more carefully you'll notice that I never claim to filter by package name. Take special note of the first edit.Depressor
By using 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"Evolution
The answer doesn't answer the question; lots of times you'll want messages from libraries and you aren't able to change the tag.Horseplay
This is not the good answer. Thanks for the comments here (highly rated) that clarify that this answer here is actually misleading. It is sad to see that this wrong answer got the highest ratings and approval, it shouldn'tLoiretcher
M
197

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://mcmap.net/q/81016/-find-out-the-running-process-id-by-package-name

Musjid answered 28/12, 2017 at 8:25 Comment(9)
I tried all the 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!Snowfield
These 2 commands work as long as process "com.example.app" is running. However, error messages will show up if the process is not running. Just a side note to avoid surprises.Cellulitis
The only answer here which actually works and does as the OP asked. Although, the OP did ask in '11 and things likely changed a lot in 6 years, but this answer still works in 2020.Permanent
@Cellulitis it works for me when the app is not "running". Not sure what you mean?Rowen
Oh I see, a completely not running app won't have a PID!Rowen
@Ben Butterworth: Correct. When an app is not running, it does not have a PID. As a result, typing the above commands may result in an output message: pid out of range.Cellulitis
If pidof exists on the device.Concessive
Best solution so far!Jepson
FOR /F %A IN ('adb shell pidof -s com.example.package') DO adb logcat --pid=%~A This is how I made it work on windowsCellaret
S
56

Add filter

Add filter

Specify names

enter image description here

Choose your filter.

enter image description here

Synthetic answered 2/8, 2013 at 8:17 Comment(1)
It's quite important to be precise when you design development tools, since it's expected of the user to be precise. That's the package name, not the application name. >:(Raze
N
55

This works for me with USB debugging:

The solution was 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

Newby answered 31/1, 2017 at 14:10 Comment(3)
this saved me so much time and trouble. very concise, right to the point. thanks!Diarthrosis
This command will not show all the pid from the app, but only the logcat where it has your package name?Primavera
Yes. This one is basically a text filter, can be useful for system logs that are about your app, even if it's not running. If you need PID filter use other solutions.Newby
P
20

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

Plash answered 8/5, 2014 at 5:40 Comment(4)
1) Java code: Log.d("MyTAG", "i am hero"); Log.d("AndroidRunTime", "i am zero"); 2) to DEBUG login to Android $ adb -s RKSCWSOV5SAIEUSC shell; 3) $ logcat MyTAG:V AndroidRuntime:E *:S 4) now it will show verbose of MyTAG and errors of AndroidRuntimeOsmund
This is the only answer that worked for me on MacOS. Great job.Foti
@Foti thanks, I used Studio long time back and didn't know that it still has the issuePlash
In fact I'm not using Android Studio. I'm using Flutter, Android SDK, and Gradle. As an editor, VS Code. So this is an excellent way to know what's going on in my android phoneFoti
P
19
adb logcat -e "package-name" 

This works prefectly when filtering rows for one app only.

Paterfamilias answered 9/4, 2022 at 18:21 Comment(0)
A
13

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

enter image description here 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:

  1. Tools -> Android -> Enable ADB Integration.
    If it was already enabled, then toggle it off, and then back on

  2. Unplug 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.

Aeneous answered 20/4, 2012 at 2:44 Comment(1)
Look at all these things you have to do just to get logs for your app, not other apps. Plus, I really find it ridiculous that other people can see other people's logs. Are you telling me that there is nothing Google can do about it? Just make sure my logs are not seen by other people, and keep my logcat clean?Mystagogue
P
12

Ubuntu : adb logcat -b all -v color --pid=`adb shell pidof -s com.packagename` With color and continous log of app

Pressure answered 24/1, 2019 at 7:38 Comment(3)
The 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 commandCommence
try pgrep instead of pidofNewby
This works for me on OSX, extra points for -v colorHysterectomize
A
11

This has been working for me in git bash:

$ pid=$(adb shell ps | grep <package name> | cut -c11-15) ; adb logcat | grep $pid
Agist answered 9/3, 2014 at 0:48 Comment(0)
B
9

put 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

Bullyboy answered 5/8, 2014 at 18:41 Comment(1)
Here's a variation of the filter to capture multiline logs (if you've done 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 |).Stereoisomerism
S
8

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...

Sholom answered 28/5, 2016 at 8:15 Comment(0)
H
7

If you are using Android Studio you can select the process from which you want to receive logcats. Here is the screenshot.

enter image description here

Howbeit answered 17/11, 2013 at 7:35 Comment(1)
as from android studio ver 0.4.5 u will get messages from the app that is running only. Log cat has a new option (on by default) which creates an application filter automatically such that only the launched application's output is shownHowbeit
D
7

I 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

https://gist.github.com/kevinxucs/7340e1b1dd2239a2b04a

Doubleripper answered 23/5, 2014 at 1:46 Comment(0)
R
7

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 AlexeysActivity

That filters out everything that doesn't use the same tag.

Source

Rochette answered 14/5, 2016 at 11:46 Comment(1)
Don't assume you're writing the code. You may care about messages from libraries, and you can't change the log strings.Horseplay
W
7

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.

An output looks like enter image description here

Warfore answered 21/6, 2018 at 20:26 Comment(0)
M
6

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.

Mcbryde answered 13/11, 2011 at 20:27 Comment(0)
R
6

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.

Rissa answered 16/3, 2021 at 6:8 Comment(2)
This answer should work, but it doesn't for me. logcat just keeps spitting out every log message from every app.Luo
it should be adb logcat --pid=<pid>. you should be able to do adb logcat --pid=$(adb shell pidof <package name>)Panchito
S
6

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://mcmap.net/q/79831/-filter-logcat-to-get-only-the-messages-from-my-application-in-android) since that requires you to re-run the command each time the process is restarted.

Sensorimotor answered 25/6, 2023 at 18:19 Comment(0)
H
3

On Windows 10, using Ionic, what worked great to me was combine 'findstr' with the "INFO:CONSOLE" generated by all App messages. So, my command in command line is:

adb logcat | findstr INFO:CONSOLE
Handoff answered 21/12, 2017 at 23:33 Comment(0)
U
3

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"
Urion answered 18/8, 2021 at 10:55 Comment(1)
grep implementation helped a lot!Pencil
N
3

I have different approach, you can try access to local device's shell.

adb shell

and then follow by

logcat | grep com.package.name

This print all containing that package.

Alternatively, You can try flutter logs --verbose

Nazario answered 10/11, 2021 at 18:7 Comment(0)
P
3

Another way of getting logs of exact package name when you are inside the shell:

logcat --pid $(ps -ef | grep -E "com.example.app\$" | awk '{print $2}') 
Pigeonhearted answered 10/1, 2022 at 11:47 Comment(0)
F
2

I'm not sure there's a way to only see system messages regarding your app, but you can filter based on a string. If you're doing a log within the program, you can just include a certain unique keyword, and filter based on that word.

Foliole answered 28/7, 2011 at 4:39 Comment(0)
C
2

Try: Window -> Preferences -> Android -> LogCat. Change field "Show logcat view if ..." the value "VERBOSE". It helped me.

Canny answered 6/12, 2012 at 15:50 Comment(0)
S
2

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.

Stickney answered 25/1, 2013 at 1:12 Comment(0)
S
2

Give your log a name. I called mine "wawa".

enter image description here

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

enter image description here

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:

enter image description here enter image description here enter image description here

Scheld answered 20/4, 2015 at 19:47 Comment(0)
F
2

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`"
Furthermore answered 11/11, 2015 at 18:22 Comment(0)
S
2

You can use below command to fetch verbose logs for your application package

adb logcat com.example.myapp:V *:S

Also if you have rolled out your app and you want to fetch error logs from released app, you can use below command.

adb logcat AndroidRuntime:E *:S

Spier answered 16/12, 2020 at 5:13 Comment(0)
T
1

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"
Tachygraphy answered 31/8, 2015 at 16:10 Comment(0)
S
1

In addition to Tom Mulcahy's answer, if you want to filter by PID on Windows' console, you can create a little batch file like that:

@ECHO OFF

:: find the process id of our app (2nd token)
FOR /F "tokens=1-2" %%A IN ('adb shell ps ^| findstr com.example.my.package') DO SET PID=%%B

:: run logcat and filter the output by PID
adb logcat | findstr %PID%
Stepheniestephens answered 11/3, 2017 at 18:31 Comment(0)
W
1

This is obviously a question aimed at usage of Logcat from outside of the developer device, however if you want to display Logcat output on the device (programmatically), you just need this:

Runtime.getRuntime().exec("logcat " + android.os.Process.myPid() + " *:D");

The *:D at the end filters out every message below Debug log level but you can leave that out.

To direct the output to, say, a TextView, see for example here.

Wainscot answered 6/8, 2017 at 21:4 Comment(0)
S
1

For windows, you can use my PowerShell script to show messages for your app only: https://github.com/AlShevelev/power_shell_logcat

Seclude answered 8/11, 2020 at 16:11 Comment(0)
D
0

Now is possible to type tag:nameofthetag or app:nameoftheapp to filter without adding new filters to the saved filters bar

Debbiedebbra answered 10/3, 2014 at 10:17 Comment(0)
S
0

In intelliJ (and probably in eclipse also) you can filter the logcat output by text webview, so it prints basically everything phonegap is producing

Scintillation answered 1/7, 2014 at 6:23 Comment(0)
E
0

Yet another variant of Gavriel's applog.sh with support of several devices and applications with multiple processes:

#!/bin/sh
PKG=$1
shift

APPIDS=`adb $@ shell ps | awk -v PKG="$PKG" '
    (NR == 1){appcolumn=2; for (i=1; i<=NF; i++) if ($i=="PID") {appcolumn=i}}
    index($0,PKG){print $(appcolumn)}' | paste -d \| -s`

echo "PID's: $APPIDS"
adb $@ logcat -v color | awk  "(\$3 ~ /$APPIDS/){print \$0}"

Usage: applog.sh com.example.my.package [-s <specific device>]

Expanse answered 2/4, 2016 at 3:30 Comment(0)
G
0

Windows CMD

For sample, if your application package name is: com.nader.chat

cd C:\Users\[your-username]\AppData\Local\Android\Sdk\platform-tools
adb shell logcat *:E | findstr /c:"at com.nader.chat"

enter image description here

  • :E just filter Erros from logs, you can replace it with V: Verbose (lowest priority), D: Debug, I: Info, W: Warning, F: Fatal.
  • at to find errors just in your written source code not for others related modules
Gob answered 3/10, 2022 at 19:32 Comment(0)
C
-2

In linux, this worked for me:

adb logcat | grep `adb shell ps | grep your.package | awk '{print $2}'`
Corkage answered 30/8, 2018 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.