Filter Logcat to Get Only the Messages from My Application in Android

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

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.

How to filter Android logcat by application?

Edit: The original is below. When one Android Studio didn't exist. But if you want to filter on your entire application I would use pidcat for terminal viewing or Android Studio. Using pidcat instead of logcat then the tags don't need to be the application. You can just call it with pidcat com.your.application

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.

How to filter logcat in Android Studio?

There are two ways to do this, both are in the Android tab at the bottom of the IDE (where the logcat output is displayed).

First, you can simply type something into the search box at the top and it should filter only messages containing the text you type.

Second, you can do advanced filtering by clicking on the dropdown at the top right, which should be displaying No Filters by default, and choose Edit Filter Configuration and specifying what to filter on. Using this method you also save the filters and can re-use them by selecting them in the dropdown.

Screenshot:

Search & Filter Logcat

adb logcat filter by package name

You can filter adb logcat output by process ID by using the --pid=<pid> option.

To get the process ID for your app, you can run adb shell ps | FINDSTR <app name> (for Windows) or adb shell ps | grep <app name> (for *nix and OSX) while the app is still running.

Since you are trying to get logcat output after the app has crashed, the ps command won't work. You can generally filter logcat output by running adb logcat | FINDSTR <search term> (for Windows) or adb logcat | grep <search term> (for *nix and OSX).

This way, you can still assign meaningful tags to your debug messages and further filter on them.

Hope this helps!

How do I filter logcat messages in the terminal without a tag?

You can always simply pipe the logcat to grep:

$ adb logcat | grep 'known error substring'

If you are on Windows, then use find instead:

C:\> adb logcat | find 'known error substring'

Filter out certain logs from logcat

Combining previous two answers with some checking of the documentation gave me a good solution to see the logs that I want.

adb -d logcat -v threadtime | grep -w 4451 | grep -v 4488

-d so I can limit the output to the logs from my currently connected device while I still have emulators running in the background.

-v threadtime So that I can see the Process ID and Thread ID and timestamp.

grep -w 4451 With 4451 being the Process ID. This makes sure I see only logs from my app.

grep -v 4488 With 4488 being the Thread ID of the error message I want to filter out. This removes all lines with the specified Thread ID. This works because in my case the error message only comes in a separate thread.

Now I can see all the logs from my application without all the noise from the error in the library.
(Not confirmed but I believe the logs will still disappear when the log file is full because of the constant stream of error messages from the library.)

This is a command line solution, so it is still not an optimal solution using logcat in android studio. But it does perfectly work from the Terminal tab in Android Studio.



Related Topics



Leave a reply



Submit