Android ADB LogCat: ANDROID_PRINTF_LOG environment variable not working - android

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.

Related

Can we override adb environment variables from terminal?

ADB has following environment variables in their docs.
What is the purpose of providing them in docs. Can we override their default values from terminal ? If so how?
environment variables:
$ADB_TRACE
comma-separated list of debug info to log:
all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
$ADB_VENDOR_KEYS colon-separated list of keys (files or directories)
$ANDROID_SERIAL serial number to connect to (see -s)
$ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
$ADB_LOCAL_TRANSPORT_MAX_PORT max emulator scan port (default 5585, 16 emus)
$ADB_MDNS_AUTO_CONNECT comma-separated list of mdns services to allow auto-connect (default adb-tls-connect)
I am trying to set as shown in docs
I have tried the same on windows PowerShell and macOS terminal without any effect.
for widows powershell I tried
set ANDROID_VERBOSE=radio;adb logcat
for macos terminal I tried
export ANDROID_VERBOSE=radio;adb logcat
But I don't find any difference in output
The purpose of listing them in the documentation is simply to tell people who need to use them that they exist. I don't know Powershell, but the correct macOS syntax is:
export ANDROID_VERBOSE=radio
adb logcat
or:
ANDROID_VERBOSE=radio adb logcat
You can use either, according to your taste.

adb devices is not recognised as a known command

I am trying to set-up a command in Android studio that would allow me to see the current active devices like in this tutorial (1:39:41):
I have opened the environment settings and created the variable adb devices like it was explained in the tutorial
However, when I run it in Android Studio Terminal, the command is not recognised:
What did I do wrong?
The problem is with your naming. Try remove the white space and it will work.
Cause you type adb with argument devices.
Try change your variable to adb
then type
$ adb devices
and it will work

Set the default adb logcat output format

I'm developing in a linux system (Ubuntu 12.04).
My favorite output format is -v time, but it is annoying to have to type $ adb logcat -v timeevery time I want to see a log message.
So, my question is: is there a way to configure adb to output time format as default?
I've looking over internet for an environmental variable to set the preferred format, but so far I've no success.
use an alias.
alias myalias='adb logcat -v time'
(use whatever you prefer instead of myalias. First letters, for instance alvt)
And put it in your .bashrc

Sending AT Commands Via ADB Android

I have a task at work to investigate if it is possible to send AT commands to an android device via ADB shell. So far,I have tried to echo out the AT commands but it passes them as normal strings.
Any help please anyone.
Please try this:
echo -e "AT+CFUN=?\r\n" > /dev/ttyUSB0
On your phone, the serial line must not necessarily be called ttyUSB0. If this is not working or not available, check out the other entries of the /dev/ directory.
So it could also be /dev/ttyGS0 or /dev/SMD0 (as found out by #Sani).
For further information, please check out this Guide
NOTE:
There might also be phones, that do not respond to AT commands on any of their serial (tty) devices.
I just tried my own procedure on a Samsung Galaxy S4 and did not have any success.
Echo them where? In Android you talk to the rild (Radio Interface Layer) daemon, which in turns talks to a proprietary library, which sends commands to the actual hardware. Check rild source code for details. You could probably write a command line program that talks to the rild and execute it via adb shell, if that fits your needs.
In order to find out which port to use :
You can check
# cat /proc/tty/drivers
Use logcat -b radio | grep dev to see wich tty the radio is using.
Yes you can run AT commands from adb shell too...
prerequsite :-
1. rooted android phone
2. you are aware of the port that RIL use for i/o operation.
3. to check which port is being used by RIl use `getprop rild.libargs`
To run AT command from ADB use:
echo -c "AT\r\n" > /dev/smd11
PS: smd11 is port used by RIL.This varies from device to device.
ALso to run AT commands from android application check this tutorial
http://tech-papers.org/executing-at-commands-android-application/
Kind of a combination of the above. We got it working with 2 terminals on a Pixel 4 XL.
On one we did:
cat /dev/smd7
in the other:
echo "AT\r" > /dev/smd7
The output shows up in the first terminal
Notes:
Have to be root!
None of the discovery mechanisms worked for us, so we blindly called into smdX until we got a response from "AT\r".
echo automatically adds a \n, so adding it is redundant.

Where does Android store shutdown logs?

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.

Categories

Resources