Anybody out there know how to copy/export just the "Message" portion of the logcat output either from Eclipse or attached via the command line? I often need to just export the logging statements without all the timestamp, pid, and tag information as well. For example:
02-25 12:35:13.083: INFO/System.out(2272): URL Requested: http://...
I don't need or want the 02-25 12:35:13.083: INFO/System.out(2272): portion. Seems like I shouldn't have to write a script to post-process the output, either.
Been driving me nuts for awhile now, thanks!
Run logcat from a decent shell environment (linux, osx, cygwin or msys or in a pinch use the adb shell on the device itself), and pipe it into awk or sed, probably after grepping for the category of message and PID you care about.
Related
Android Studio's logcat is unusable; it goes in and out and rarely shows messages on restart, so I've started using adb logcat on my terminal. Reading http://developer.android.com/tools/debugging/debugging-log.html gives examples of filtering with a tag. What if I don't know the tag, but want to show all error with an error substring I know?
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'
You can try pidcat (by Jake Wharton).
It's a "colored logcat script which only shows log entries for a specific application package", as the author says.
If you're on windows, you can clic on left upper corner > Edit > Search and then introduce the substring you know.
Most probably the terminal for Linux has the same feature, but I don't know how to access to it.
When I execute adb logcat --help, the Logcat usage details are printed. Near the bottom, it describes two environment variables:
"If not specified on the commandline, filterspec is set from
ANDROID_LOG_TAGS. If no filterspec is found, filter defaults to '*:I'
If not specified with -v, format is set from ANDROID_PRINTF_LOG or
defaults to 'brief'"
On my Windows 7 machine, when I add ANDROID_LOG_TAGS to my environment variables with a value of "Foo:* *:S", for example, then it works! Calling adb logcat without tag filters will default to my custom values. Great!
However, when I add ANDROID_PRINTF_LOG, with any valid setting (I prefer "time"), this will NOT have an affect on the logcat output. adb logcat still outputs in "brief" format.
Is there some mistake I am making, or something I can do to get to work??
I would really like to get this working because I use "-v time" a lot.
My ADB version is 1.0.31.
Thanks in advance.
Android pages themselves didn't mention this variable:
http://developer.android.com/tools/help/logcat.html
http://developer.android.com/tools/debugging/debugging-log.html#outputFormat
ANDROID_PRINTF_LOG and ANDROID_LOG_TAGS are processed by the logcat binary running on the device side. It means that in order to affect the output format the variables need to be set inside of the device's shell environment. And you are setting them in your PC's shell environment. The reason why ANDROID_LOG_TAGS still works when set on the PC side is the following:
When you run the adb logcat the actual command being executed is this:
adb shell export ANDROID_LOG_TAGS=\"%ANDROID_LOG_TAGS%\"; exec logcat
i.e. your local ANDROID_LOG_TAGS value is being copied into the device's environment before every logcat call. Not sure if not copying the ANDROID_PRINTF_LOG as well qualifies as a bug though. adb -h lists all the variables supported on the PC side and ANDROID_PRINTF_LOG is not among them.
I am testing an app with 2 devices communicating using sockets and monitoring the timestamp values. I select the required device name from the DDMS perspective. But some initial logs are missing(as I have many Log.d statements in the code). I want to store the whole log file after I stop apps in both the phones. Can someone tell me how this can be done in command line using adb? I couldn't find any example for 2 devices.
Thanks
You can try with two console and get logcat separately for two devices
Get serial no for each devices using adb devices
and save logcat as text files
console 1: adb -s <device1serialNO> logcat -d > logcat1.txt
console 2: adb -s <device2serialNO> logcat -d > logcat2.txt
You can filter result for your given tag if needed
Before launching your application you can start the following command in your terminal:
adb logcat <your_application_log_tag>:V *:S > file.txt
<your_application_log_tag> is a log tag that you use in your application. *:S means that you suppress all log outputs from other components. > file.txt redirects the output of the command to file.txt.
The cause of the problem is that for logging Android has a buffer in RAM and if it becomes full it rewrites the most old entries (FIFO). The command I've provided will store the log on your computer.
I've never used python before, but I have to in order to enable push notifications on my android app. When I type
python D:\Project\UAirship\clientauth.py
I get a syntax error with an error pointing to the drive letter. I've read support articles on urban airships website, and this is the way they execute this script so I'm not sure what I'm doing wrong. Thanks for your help.
You're supposed to type that in your shell/command interpreter, not the Python REPL.
Check to make sure you've added Python to your path. At the C:> prompt type
python
and see what happens. If you get the Python shell, great. Else do what the faq says.
edit: just fired up a windows box to check, and the D: shouldn't be a problem, never mind the thought that was previously occupying this space.
It seems likely that ignacio is right in his answer: you're typing a command-prompt command into the python shell. Your cursor should be flashing after something that looks like this
C:\>
if it looks like this
>>>
type exit() to get out of the python shell and try again.
I know that the boot up log can be obtained by pulling out contents of kmsg or dmesg through ADB.
But I'm not aware of how to retrieve the shutdown logs in Android as there's no /var folder in Android (place where most desktop linux distros generally store their shutdown logs).
So how can I obtain the shutdown logs in Android?
Look in some locations such as these:
/proc/last_kmsg
/data/tombstones/
/data/dontpanic/
/data/system/dropbox/
(This list isn't strictly kernel logs, including framework and application logs too, which are also sometimes of interest)
One work around I found for collecting shutdown logs in Android is to run adb pull /proc/kmsg C:\Logs.txt on the host PC and then switch off the device. You will get the logs till the USB communication between the host and the device snaps! I know this is only one case out of the numerous shutdown scenarios but I haven't found satisfactory answers for other cases!
TL;DR:
Run command through adb that copies logcat and proc/kmsg to a file and keep it running even when adb disconnects with nohup, disown or setsid. Probably needs busybox, needs root and adb root, too.
setsid cat proc/kmsg > /sdcard/kmsg.txt &
and
logcat -v long -f /sdcard/logcat.txt (somehow only works without setsid)
Or add normal copy commands to some startup script.
/TL;DR
You can constantly copy proc/kmsg and logcat to a file on your android device or a microSD card to get the logs even after adb disconnects.
You need root access and adb root access for this to work. For the latter, use the setting in the developer options if you have a custom rom or the adbd insecure app.
After using adb shell to get your android shell, type su to get superuser access.
Then you not only need to put an ampersand (&) after the command but also make sure that the command keeps running after adb disconnects. That is done by nohup, disown or setsid (see here for usage).
If it doesn't work because you don't have these commands, you need to install busybox.
See my question here.
See here for how to get logcat and kernel logs and print it to some file or merge it.
See developer.android.com/tools/help/logcat.html for parameters for the logcat command.
In the end you could have a command like setsid cat proc/kmsg > /sdcard/kmsg.txt & for the kernel messages.
For logcat you could have one of the following commands: logcat -v long -f /sdcard/logcat.txt or logcat -v long > /sdcard/logcat.txt
I don't know why, but sometimes it didn't work with setsid and just didn't copy continuously but stopped shortly after executing the command. In these situations, it also showed up when entering jobs, which it didn't otherwise. Then it just worked without setsid, it stayed alive after disconnecting and reconnecting. I guess you must just try when the file does keep getting larger. If someone figured out why it is behaving like it is... let me know and I'll edit the answer.
Probably adding the commands to a startup script could be a solution for some, too.
Hope this helps.
fightcookie
Newer phones do NOT use any of these locations so if you're reading this article then as of now
The kernel crash logs are now in /sys/fs/pstore instead of /proc/last_kmsg
I was looking for the same thing, and finally, I found the answer!
In android 8 all logs are located in \data\log\android_logs\... including apps and kernel logs. Kernel logs are called kmsgcat-log_timestamp_.gz
edit: Although this is a very old thread, I think the answer might be helpful.