Not quite clear what logcat can and cann't. Suppose my phone is connected to my local computer. Do:
c:> adb shell logcat > /data/tmp/logs/log.txt
log.txt file will be created on the android devie. After some time, phone crashes. How can I got the log.txt back from the device? Is there a way to directly output all the events (even kernel message such as dmesg does) on the device to my computer, instead of generating a log file on the device first, then pull it to the computer?
You Should use android-logging-log4j.jar
You can store all the log in .txt or .xml
For More details go through
https://code.google.com/p/android-logging-log4j/
You need to give path where you want to save your log. So can navigate to that path and can get the log file
Hope this help.
Related
What log source is used by logcat (with default settings: adb shell logcat). Are dmesg logs included in logcat's output? If not, what's the difference between dmesg logs and logcat logs?
According to the source code https://github.com/android/platform_system_core/blob/master/liblog/logd_write.c Log.d(String tag, String message) writes directly to /dev/log/main.
You can write there like this adb shell echo "Hello world" >> /dev/log/main
But dmesg prints the contents of the kernel's ring buffer. So dmesg will print only what system writes to kernel log, logcat will output only android app's logs.
LOGCAT-- This is used in Android , to see the different messages written by the activity managers inside the Android , u see android also uses the linux kernel , but what it does is, once the kernel boots ( the hardware initialization /probing has been taken care of) , the android starts a process called init which parses the init.rc file which contains all the android system activities , i mean the basic processes for android to boot , in this init.rc file there's a process called zygote which starts the Dalvik Virtual Machine , and after that all the other activity managers , which will be used by the application to interact with the hardware . so its basically messages from the VM , for the application programmers to debug it .
logcat example
http://pastebin.com/bV1Vd6EQ
Dmesg- it is messages from the kernel , suppose u write a driver , it can be used as a tool for debugging drivers and other kernel code, most of them are driver messages its a good way of debugging , the kernel , driver etc..
dmesg example
http://pastebin.com/P4ja9PFi
Logcat is only for android and its not available in any other OS , both Logcat and dmesg is available on Android but not the vice versa for any linux distros .
regards,
zubraj
I already posted similar question, but still could not get my job done, so this a a second attempt, where
I would like to more clearly state my stumbling block.
So basically I am in Android phone's adb shell, communicating with the GPRS modem by sending AT commands.
I am able to do it by redirecting at command to the device file representing the modem; and I can read back
the response using cat utility running on the background (started earlier). I implemented it in a script
which can send a single AT command and read back the response. For example, here is the script to
send at+cops? to get the name of the operator the mobile is camping on:
#SendATCommand script
cat /dev/pts/7 &
echo -e at+cops?\\r > /dev/pts/7
The output looks as follows:
# ./sendATCommand
./sendATCommand
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
Now here are two problems which I cannot resolve:
I still need to manually press ENTER button to get back adb shell prompt "#". Is there a way to return
to "#" prompt programmatically? Again, I am in adb shell.
The displayed response cannot be captured, neither in a variable, nor in file, (such as(#./sendATCommand > output.txt) Output.txt file will be empty. I tried various redirections, but still did not get it to work.
Can anyone please help me resolve those two problems (if ever possible)? Ultimately I want this little script to be
called from a "super" script (e.g. Perl or Powershell) running on PC to which my Android device is
connected, but there is no way to do it until those two problems resolved. Thanks a lot in advance!
I suggest that you try out my atinout program which should be exactly what you are asking for: a program to send AT commands from the command line and capture the output.
In your case the result should be like
$ echo 'at+cops?' | atinout - /dev/pts/7 -
+COPS: 0,0,"AT&T",6
OK
$
and to capture the output just put a file name instead of the last -.
I had similar problems with redirecting output to file. I resolved my problem by adding CMD /c in front of the echo command. I.e. if I understand correctly you need to tell the system that it needs to wait until command finishes executing and only then redirect output to a file. I was doing it in DOS.
Since you are running on ANDROID try adding sh -c in front of your command. Hope it helps.
How can I see timestamp in Logcat? Is there any application which shows me the log along with the timestamp? Also, how can I increase the size of the Log in andriod phone?
To get timestamps: logcat -v time
To run logcat on the device at a shell prompt: logcat
There are several free logcat viewers for Android. I've heard that aLogCat is pretty good.
EDIT
You can set your preferences in aLogCat to see the time.
Regarding your second question, I found an answer here:
The logs are held by a kernel device; the entries are in /dev/log.
The buffer is currently 64KB, and there is no way to change the size
on a production device.
The easiest way to keep more of the log is to run "logcat" and send
the output to a file. logcat runs on the device, so you could run it
there and redirect it to (say) /sdcard/log.txt.
I want to dump all logs out to test a long usage of my app, maybe 2-3 days, but the logs seem to be cleared out while running after a long time.
How can I keep the logs?
I do not want to connect my device with eclipse all the day, I want the log just keep for me, like store it in the sd card for further check.
I had same requirement for my application. By default there is logcat process that tracks logs up to around 64kb (depends on device).
You can start your own logcat process using adb shell with some custom arguments. For example:
adb shell logcat -f /mnt/sdcard/large.log -r 100 -n 10
This will save up to 1mb of logs evenly distributed among 10 files (large.log, large.log.0, larget.log.1, etc.);
The next step is to launch logcat from your application:
String [] args = new String[] { Logcat, "-v", "threadtime",
"-f", logFile.getAbsolutePath(),
"-r", Integer.toString(sizePerFile),
"-n", Integer.toString(rotationCount),
"*:"+filter};
Runtime.getRuntime().exec(args);
So now your app may start saving logs. But you should be careful not to enable this in your production versions of application (or at least make this opt-in feature).
Instead of using the eclipse log use the apps like 'log viewer'. I think that app can solve your issue. I think the log will remain until you clear the log manually in 'log viewer'. I just downloaded it today morning and still has the logs of actions I performed just after I switched on the device.
Did you try dumping the log to a file?
adb logcat > log.txt
Sometimes we see the device restarts automatically, while few other times I had found it switching off after long time, even battery was not low.
So if we want to trace back of what actually has caused this, does we have any log file in device memory which has the cause of shutdown or restart ?
Like we get the dump for the other O.S. for any errors occured causing it to restart/shutdown in specific error log file. Similarly does android has such ?
It may be anywhere , even in internal memory, so with root privileges I can go into looking for it.
Any thoughts ? Thanks.
If you have installed Terminal on your phone just tupe in
su
logcat
If not enable DebbugingMode on your phone, connect it with your PC/Mac, open Eclipse and go to Debug.
There it will show the log of the phone.
I hope this helps.