Android log file has missing lines - android

i use some batch script for android device , it should clear The device log , start and close an apk and then take the log out of it.
thats my code i use:
adb -s %DeviceId% logcat -c
adb -s %DeviceId% shell am start -n com.mv4d.sdktutorialbasicchangeframesize/com.mv4d.sdktutorialbasicchangeframesize.MainActivity
SLEEP 80
adb -s %DeviceId% shell am force-stop com.mv4d.sdktutorialbasicchangeframesize
adb -s %DeviceId% logcat -d -v time > D:\Roey\Jen2\ChangeFrameSize\Results\Logcat\AndroidLog.txt
the created log is missing lot of first and last lines. (that appears if you start the app and check the live log via android studio for example...) any ideas ?

adb logcat -d [file] will only dump the logs currently in memory, not all logs since the device boot.
The logs stored by LogCat are circular, which means that when the allocated space for logs starts to run out, LogCat with delete older logs to make space for newer logs. That means you can only have a certain number log lines in memory at any given time (usually set to something like 16kb).
To be able to get all logs you will have to make LogCat write logs out to a specific file, instead of just keeping them in memory.
You can do this with the following command:adb logcat -f [file].
This will make LogCat write out any log in memory and any future log to the specified file.
NOTE: The specified file must be on the device itself and can be pulled from the device.(adb pull [device file] [destination file])

Related

ADB Shell is not displaying logs continously

I am trying to debug a Yocto project. I have flashed cpp binaries on some device.
Now I my trying to display logs using below adb command
adb shell tail -f /var/log/acs_main.log
The problem i'm facing is that logs are not displayed continuously.I have to cancel and again start to print further log statements.
Anyone can help me in this ?

Getting adb logs on PC using a batch file while the Android app is running

I have a created a windows batch file(log.bat) like this below :
adb logcat -c
adb logcat -d > log.txt
But it soon exits whenever I press log.bat command.
I want it to keep recording the logs unless I press ctrl+C.
From doc
-c : Clears (flushes) the entire log and exits.
-d : Dumps the log to the screen and exits.
So, in both cases, the execution stops once you run the logcat command with these options. Try this,
adb logcat -c && adb logcat > log.txt
This won't let the shell execution to be released once it executes logcat -c and will start the next command right after it which is adb logcat > log.txt that is going to write the logcat's log till you hit the Ctrl + c.
It looks problem is using option -d with logcat. Please check usage :
-d Dump the log and then exit (don't block)
Removing it will solve your problem.
I need to create a batch file that can copy a log file to a PC. The batch file I created doesn't work. When I run all the commands manually it works however when putting into a script it hangs. Here are the individual commands:
Try this single line command:
$adb shell run-as com.example.name cat /data/data/com.example.name/files/logfile.log > c:\logs\logfile.log

uiautomator dump in Runtime.getRuntime().exec() not working

When I put this line in my test app,
Runtime.getRuntime().exec("uiautomator dump"), no .xml file was dumped. I am pretty sure I checked the correct location.
I tried to debug my app by putting a break point. When it reaches the break point, I adb shell on terminal to get into the device, and then manually run uiautomator dump from terminal, then it says killed, no .xml file was produced either.
adb shell uiautomator dump only produces .xml file when I killed my app, and run this command from terminal.
Is this a sort of permission or accessibility problem?
You can't use adb shell uiautomator dump while a test is running.
You can call UiDevice.dumpWindowHierarchy(..) from inside your test instead.

adb logcat cannot write to file using -f option (under windows XP)

I want to write log from my android device to the file under Windows XP.
I'm trying to use command:
adb logcat -f test
But it returns:
log file locked.couldn't open output file: Bad file number
If I use
adb logcat >test
then it works OK, but it doesn't show anything to the console.
I thought that using "-f" option would show data in console and simultaneously write to the file.
How to do it?
Just sharing in case someone fall here.
The -f options expects a path from phone folder (and not from your PC). For example:
adb logcat -f /sdcard/test.txt
Then, after stopping the log, you must pull that file from phone:
adb pull /sdcard/test.txt

how to get Logs and write them in files

I want to write all logs displayed in logcat into a file when my application crashes (forced close) or else also.Is there ane way to get Logs programatically ? or is there ane way to know when my application crashed?
I dont want to use "adb logcat " command. Plz help me out
Have a look at this microlog4android
and also go through this question too How do you save an Android application log to a file on a physical device?
Copied "Lars Blumberg" answer for your quick reference:
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
Refer for more info: Viewing stdout and stderr
If you want write your own Log function, see this answer Android Writing Logs to text File

Categories

Resources