응용 프로그램별로 Android logcat을 필터링하는 방법은 무엇입니까? [복제]
이 질문에는 이미 답변이 있습니다.
애플리케이션별로 Android logcat 출력을 필터링하려면 어떻게해야합니까? 장치를 연결할 때 다른 프로세스의 스팸으로 인해 원하는 출력을 찾을 수 없기 때문에 이것이 필요합니다.
편집 : 원본이 아래에 있습니다. 하나의 Android Studio가 존재하지 않을 때. 그러나 전체 응용 프로그램을 필터링하려면 터미널보기 또는 Android Studio에 pidcat을 사용합니다. logcat 대신 pidcat을 사용하면 태그가 응용 프로그램 일 필요는 없습니다. 당신은 그것을 호출 할 수 있습니다pidcat com.your.application
자신의 태그를 사용해야합니다. http://developer.android.com/reference/android/util/Log.html
처럼.
Log.d("AlexeysActivity","what you want to log");
그런 다음 로그 사용을 읽으려면>
adb logcat -s AlexeysActivity
동일한 태그를 사용하지 않는 모든 것을 걸러냅니다.
http://developer.android.com/tools/debugging/debugging-log.html 에 따르면 :
다음은 "Info"이상의 우선 순위에 "ActivityManager"태그가있는 메시지를 제외한 모든 로그 메시지와 "MyApp"태그가 있고 "Debug"이상의 우선 순위를 가진 모든 로그 메시지를 표시하지 않는 필터 표현식의 예입니다.
adb logcat ActivityManager:I MyApp:D *:S
위 표현식 * : S의 마지막 요소는 모든 태그의 우선 순위 레벨을 "자동"으로 설정하므로 "보기"및 "MyApp"가있는 로그 메시지 만 표시됩니다.
- V — 상세 (가장 낮은 우선 순위)
- D — 디버그
- 나 — 정보
- W — 경고
- E — 오류
- F — 치명적
- S — 무음 (가장 높은 인쇄 우선 순위)
안녕하세요, 이것을 사용하여 해결책을 얻었습니다.
터미널에서이 명령을 실행해야합니다. 결과를 얻었습니다.
adb logcat | grep `adb shell ps | grep com.package | cut -c10-15`
Android Studio에서 작업 중이며 패키지 이름을 사용하여 메시지를 얻는 좋은 옵션이 있습니다. "필터 구성 편집"에서 "패키지 이름 별"에 패키지 이름을 추가하여 새 필터를 작성할 수 있습니다.
추가 터미널 창에서 로그를 보내고 있다는 사실을 알 수 있다면 pidcat을 추천 할 수 있습니다 (패키지 이름 만 취하고 PID 변경 사항을 추적하십시오).
이름이 MyApp 인 애플리케이션에 다음 구성 요소가 포함되어 있다고 가정하십시오.
- MyActivity1
- MyActivity2
- MyActivity3
- MyService
logcat을 사용하여 애플리케이션 MyApp의 로깅 출력을 필터링하려면 다음을 입력하십시오.
adb logcat MyActivity1:v MyActivity2:v MyActivity3:v MyService:v *:s
그러나이를 위해서는 응용 프로그램 이름 MyApp을 사용하여 필터링하는 대신 응용 프로그램의 모든 구성 요소에 대한 TAG 이름을 알아야합니다. 자세한 내용은 logcat 을 참조하십시오 .
응용 프로그램 수준에서 필터링을 허용하는 한 가지 솔루션은 고유 한 각 TAG에 접두사를 추가하는 것입니다.
- MyAppActivity1
- MyAppActivity2
- MyAppActivity3
- MyAppService
이제 TAG 접두사를 사용하여 logcat 출력의 와일드 카드 필터를 수행 할 수 있습니다.
adb logcat | grep MyApp
결과는 전체 응용 프로그램의 출력입니다.
이것을 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}:"
그때: applog.sh com.example.my.package
When we get some error from our application, Logcat will show session filter automatically. We can create session filter by self. Just add a new logcat filter, fill the filter name form. Then fill the by application name with your application package. (for example : my application is "Adukan" and the package is "com.adukan", so I fill by application name with application package "com.adukan")
If you use Eclipse you are able to filter by application just like it is possible with Android Studio as presented by shadmazumder.
Just go to logcat, click on Display Saved Filters view, then add new logcat filter. It will appear the following:
Then you add a name to the filter and, at by application name you specify the package of your application.
On my Windows 7 laptop, I use 'adb logcat | find "com.example.name"' to filter the system program related logcat output from the rest. The output from the logcat program is piped into the find command. Every line that contains 'com.example.name' is output to the window. The double quotes are part of the find command.
To include the output from my Log commands, I use the package name, here "com.example.name", as part of the first parameter in my Log commands like this:
Log.d("com.example.name activity1", "message");
Note: My Samsung Galaxy phone puts out a lot less program related output than the Level 17 emulator.
I use to store it in a file:
int pid = android.os.Process.myPid();
File outputFile = new File(Environment.getExternalStorageDirectory() + "/logs/logcat.txt");
try {
String command = "logcat | grep " + pid + " > " + outputFile.getAbsolutePath();
Process p = Runtime.getRuntime().exec("su");
OutputStream os = p.getOutputStream();
os.write((command + "\n").getBytes("ASCII"));
} catch (IOException e) {
e.printStackTrace();
}
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`"
Yes now you will get it automatically....
Update to AVD 14, where the logcat will automatic session filter
where it filter log in you specific app (package)
On the left in the logcat view you have the "Saved Filters" windows. Here you can add a new logcat filter by Application Name (for example, com.your.package)
What I usually do is have a separate filter by PID which would be the equivalent of the current session. But of course it changes every time you run the application. Not good, but it's the only way the have all the info about the app regardless of the log tag.
Generally, I do this command "adb shell ps" in prompt (allows to see processes running) and it's possible to discover aplication's pid. With this pid in hands, go to Eclipse and write pid:XXXX (XXXX is the application pid) then logs output is filtered by this application.
Or, in a easier way... in logcat view on Eclipse, search for any word related with your desired application, discover the pid, and then do a filter by pid "pid:XXXX".
you can achieve this in Eclipse logcat by entering the following to the search field.
app:com.example.myapp
com.example.myapp is the application package name.
my .bash_profile function, it may be of any use
logcat() {
if [ -z "$1" ]
then
echo "Process Id argument missing."; return
fi
pidFilter="\b$1\b"
pid=$(adb shell ps | egrep $pidFilter | cut -c10-15)
if [ -z "$pid" ]
then
echo "Process $1 is not running."; return
fi
adb logcat | grep $pid
}
alias logcat-myapp="logcat com.sample.myapp"
Usage:
$ logcat-myapp
$ logcat com.android.something.app
In Android Studio in the Android Monitor window: 1. Select the application you want to filter 2. Select "Show only selected application"
use first parameter as your application name. Log.d("your_Application_Name","message");
and in LogCat : create Filter ---> Filter Name & by Log Tag: is equal to 'your_Application_Name' it will create new tab for your application.
Use fully qualified class names for your log tags:
public class MyActivity extends Activity {
private static final String TAG = MyActivity.class.getName();
}
Then
Log.i(TAG, "hi");
Then use grep
adb logcat | grep com.myapp
The Android Device Monitor application available under sdk/tools/monitor has a logcat option to filter 'by Application Name' where you enter the application package name.
On Linux/Un*X/Cygwin you can get list of all tags in project (with appended :V
after each) with this command (split because readability):
$ git grep 'String\s\+TAG\s*=\s*' | \
perl -ne 's/.*String\s+TAG\s*=\s*"?([^".]+).*;.*/$1:V/g && print ' | \
sort | xargs
AccelerometerListener:V ADNList:V Ashared:V AudioDialog:V BitmapUtils:V # ...
It covers tags defined both ways of defining tags:
private static final String TAG = "AudioDialog";
private static final String TAG = SipProfileDb.class.getSimpleName();
And then just use it for adb logcat.
I have found an app on the store which can show the name / process of a log. Since Android Studio just puts a (?) on the logs being generated by the other processes, I found it useful to know which process is generating this log. But still this app is missing the filter by the process name. You can find it here.
Add your application's package in "Filter Name" by clicking on "+" button on left top corner in logcat.
to filter the logs on command line use the below script
adb logcat com.yourpackage:v
이러한 인수를 사용하여 패키지의 메시지 만 표시하도록 log cat 출력을 필터링 할 수 있습니다.
adb com.your.package : I * : s
편집-나는 곧 말했다.
adb com.your.package:v
참고 URL : https://stackoverflow.com/questions/7537419/how-to-filter-android-logcat-by-application
'IT story' 카테고리의 다른 글
3 개의 열 데이터 프레임을 행렬로 재구성 (“long”에서“wide”형식) (0) | 2020.07.16 |
---|---|
Markdown에서 머리글이없는 테이블 만들기 (0) | 2020.07.16 |
새로운 예외를 만들고 던지기 (0) | 2020.07.16 |
C ++에서 예외 지정자를 사용해야합니까? (0) | 2020.07.16 |
조건부 컴파일 및 프레임 워크 대상 (0) | 2020.07.16 |