So I am a newbie to Android Studio and found the logcat feature to be very much helpful to me. But the logcat shows me way too much info than that was needed. Now how do i set it's filter to only show crash reports, exceptions and custom logs(EX : Log.d.(TAG, "onCreate : Successs.");
)

- 5
- 1
- 4
-
3Possible duplicate of [How to filter logcat in Android Studio?](https://stackoverflow.com/questions/19931987/how-to-filter-logcat-in-android-studio) – Ali Ahsan Jan 14 '19 at 17:54
4 Answers
@Johan Chersev here is a quick demo of working with the Logcat in Android Studio. In MainActivity an integer is being divided by zero. Java should raise an ArithmeticException i.e. java.lang.ArithmeticException: divide by zero; the goal is to log this exception to Logcat in the catch block.
Code snippet.
package com.example.logcatdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
// To be passed as the tag in calls to methods of the android.util.Log class
// e.g. Log.i(TAG, Message)
private static final String TAG = "LogcatDemo";
private int mNumber = 5;
private int mDivisor = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Divide an integer by zero
int result = mNumber / mDivisor;
} catch (ArithmeticException aex) {
// Send the exception details to logcat
Log.e(TAG, "An error occurred in onCreate(Bundle savedInstanceState). See Details:-\n" + aex);
}
}
}
To filter out unwanted log messages in Logcat do the following:-
Open the Logcat tool window which can be done by clicking the strip tool button with the name Logcat on it at the bottom of the IDE.
Strip tool button with Logcat label.
If for some reason you don't see the Logcat tool button strip hover over the gray square button in the bottom left corner of the IDE.
Gray square button in bottom left corner
Or go to View then hover over Tool Windows.
Now the fun part (Cause ain't no party like an android party ).
Once logcat is open ensure your device is selected in the device dropdown menu (which shows a list of connected devices).
Ensure your app's package name is selected in the dropdown menu that lists app packages.
You can specify the level of log messages displayed. In this demo I only want exceptions logged as I called log.e(tag, msg). So I'll select error in the log level dropdown menu.
If you want further precision and make finding your log messages easy peasy filter the logcat messages using a TAG constant as follows:-
Click the dropdown menu in the top right corner of the logcat pane that has the "Show only selected application" selected by default;its called the filter dropdown.
It currently only shows messages from your app.
In the resulting dropdown list select Edit Filter Configuration to create a new custom filter.
In the Create New Logcat Filter window give your filter a name in the Filter Name field and preferably enter the same name (for simplicity or easy recall) in the Log Tag field then click ok.
On returning to Logcat only logs with the selected tags will pop-up.
If this isn't the case click on the filter dropdown and select your log tag.
Thats it you are done. Go forth and log like a boss.

- 2,407
- 2
- 12
- 19
There is a section in the Logcat window, where you can type a Regular Expression to show what you want.
In this example, it isn't showing anything, since the word "Successs" doesn't appear in my particular log.
You can also use the menus and other items to set if ERROR or VERBOSE errors are displayed, or other filters.

- 18,579
- 7
- 55
- 72
P.S. I couldn't post more than eight image links. So the last two images of the answer are as follows.
In the Create New Logcat Filter window give your filter a name in the Filter Name field and preferably enter the same name (for simplicity or easy recall) in the Log Tag field then click ok.
On returning to Logcat only logs with the selected tags will pop-up.
If this isn't the case click on the filter dropdown and select your log tag.
Thats it you are done. Go forth and log like a boss.

- 2,407
- 2
- 12
- 19
You can press ^+Space to show suggestions:
For example, for errors you can use level:error

- 3,852
- 1
- 28
- 30