How to get logcat crashes - android

A newbie logcat question here, I am sure this is well known but could not find the answer. Sorry.
I want to use logcat for the users of my app MyApp to email me crash reports that obviously I don't know where they will appear. I want to print Warning and above only for my app.
I read the the documentation, and understood that, to print logcat only for a package I should do something like:
logcat -d -v time MyApp:W *:S
However that does not work: that is just for tags, not for app names.
I read people suggesting something like
logcat -d -v time *:W | grep MyApp
but that does not work either: the error messages, exactly what I am interested in, do not print MyApp name in all the lines.
I also tried
logcat -d -v time --pid=$(pidof -s MyApp) *:W
but that does not work either since the app crashed already, so it is not running, and it will send me the log of the still running MyApp PID.
What I ended up doing was to print only the last 20 minutes of everything with:
long timesinceepoch = System.currentTimeMillis()/1000 - 1200;
Process process = Runtime.getRuntime().exec("logcat -d -v time -t "+timesinceepoch+".0 *:W");
but I still get lots of trash and big files, of course.
So how do I add a MyApp tag to ALL the logcat logs of MyApp?
EDIT: Actually, in Android Studio the MyApp appears in the logcat, and there is an option to show logcat for a single app. Isn't Android Studio logcat and adb logcat the same??

This is totally unnecessary since when an app calls logcat it only logs the calling app logs. See this (thanks #jake-lee !).

Related

Whitelist my App in logcat / chatty identical 1 line

Logcat is filtering my logs, so I get only:
1234-1234/com.example.test I/chatty: uid=45678(com.example.test) identical 1 line
This is a serious issue for me, I tried applying the solutions suggested in other threads like
adb logcat -P ""
I also read the documentation (logcat --help and the "-P" option at official documentation like adb logcat -P 45678), but this also didn't help.
adb logcat -p shows that I whitelisted my app:
adb logcat -p
45678 (the UID of my app)
Still the logs are getting filtered. How can I fix that? I simply want no log filtering on my app during development.
My fault. I checked in Android Studio where I had the log leve filter set to "Info". The chatty message is "info" level, my log messages were "verbose" level. Actually I am getting both, my app log messages and the chatty messages...
Make sure to test without Android Studio using logcat: adb logcat and see if you see your log message. If that works, something is selected wrong in Android Studio like it was for me and by me.

ADB logcat fails to clear the main log

When I connect to a device or an emulator using adb, I can clear logcat using adb logcat -c. The issue I am facing is that I often get the following message:
failed to clear the 'main' log
AFAIK, 'main' is a non-rooted buffer which means that I should be able to clear it without root. What can then be the reason for this message?
You might have your Android Studio opened, please close it and run again , it should able to clear the logs.
use
adb logcat -b all -c
it will clear all buffers. sometime adb logcat -c will not work because of many process using it like android studio.
Logcat messages are stored in buffer, you can try,
adb logcat -c
Clear (flush) the selected buffers and exit. The default buffer set is main, system and crash. To clear all of the buffers, use -b all -c.
source: logcat doc
For more logcat usage, check How do I get the logfile from an Android device?

Finding logs relevant to a specific app in adb logcat [duplicate]

This question already has answers here:
Filter LogCat to get only the messages from My Application in Android?
(37 answers)
Closed 5 years ago.
I am not using Android Studio, so when coding or debugging an application, I send the .apk with:
adb install -r test.apk
and run it. Recently, since using Thread, I get a Unfortunately, app has stopped crash. I tried to use:
adb logcat
but it is totally impossible to see anything in it, because I see hundreds of lines per second, and it never stops.
How to display only messages associated to a specific .apk with adb logcat?
On Linux, a grep could probably work, but I doubt it would work with adb on Windows (that I am using).
Add filters:
adb logcat -v time Foo:V Bar:E *:S
This would allow all verbose (and more severe) logs for the tag Foo, error logs for Bar, and silence everything else.
Regarding grep: if you install something like Git For Windows you'll be able to add grep as a command that can be used from a normal Windows commandline window as well.

Android AIDE, logcat scrolling on runtime error

On every runtime error in AIDE (when the application crashes) the logcat window is displaying all messages again (even from the last days) which needs long time to scroll to the end to find out what's wrong. I don't want always clear the logcat list before i compile the project, but i did not find any setting to avoid this behavior. Does anyone have a solution for this?
Actually you can have command line,use
Terminal IDE if your device is running on android 4.x
or lower,
Termux if Lollipop+,
launch your app within one of these Terminal Emulators with am command:
am start -a android.intent.action.Main -n com.your.package/.Ur_Main_Activity
And then use the logcat command to observe log, it will be a bit cumbersome though, use filters as you see fit. Enter ctrl+C to end Logcat dump. Hope this helps,

Logcat displays nothing when used from Runtime.exec

I'm running the command
logcat -d AndroidRuntime:E *:S
When ran from adb on my computer, it displays all the things it should. When I try to run it from an Android application with
Runtime.getRuntime().exec("logcat -d AndroidRuntime:E *:S");
and print the output, it won't display anything except the headers.
How can I fix this?
First, this has never been supported.
Second, if you are running on Android 4.1 and later, you will only get any log messages that your own app logs, not messages from other apps, as you can no longer hold the READ_LOGS permission in an ordinary SDK app.

Categories

Resources