About Android Logcat in real device - android

I have some question related to the Android Logcat, I am refering these questions to be in REAL DEVICE not the emulator:
I have a program which has a lot of Log.d (or other similar log functions), I did some google search and found that those logs will be output to a circular 64K buffer. My question is, where are those 64K buffer located? Is it located in RAM or file system? Will it be removed after my app exits?
I google and found that, the log will be output to a file called /dev/event (not sure), but I couldn't see any application-related logging inside, why? Only system-related log entries can be seen.
Does every app output its log to a different log file? Or are they all dumped into the same log file? In this case, how can we seperate the log?
If the logging buffer is 64K, how can we increase it? If we want to re-direct the log to a file which is on a sd card, how can we limit the file size (of course make it circular too)?

Going point by point:
(1) The log buffers are in RAM, in the kernel. Logging is handled by a kernel driver. On recent devices, the log buffer is much larger than 64KB. They are not lost when an application exits, but will not survive a device reboot.
(2) The device entries are in /dev/log, e.g. /dev/log/main for the main log, /dev/log/radio for the radio log, and /dev/log/events for the event log. The logs are stored in a format that is generally more compact than what you see in logcat, so reading them directly with something like cat may be confusing.
(3) All apps write to the same log devices. Each log message is tagged with the process ID and thread ID of the log writer, so you can separate them out that way. (logcat -v threadtime will show you the pid, tid, timestamp, and tag.)
(4) You would need to change a value in the driver to alter the size of the log. Again, recent devices have much larger log buffers, so this is probably not so useful. You can send the output to a file with logcat; if you want to do some sort of circular buffer you will need to capture the output of logcat and handle it yourself. (You could also read the log device directly, but I don't think the API is public. See the AOSP logcat sources.)
Recent versions of Android do not allow apps to read all entries in the log. Instead, apps may only read the entries that they themselves generated. This was done to allow bug reporting systems to capture the logs, while preventing wayward apps from "spying" on other apps. When you run logcat from adb shell, it runs as the shell user, which has permission to read all logs.

Related

Difference between logs in logcat view in ddms & those obtained using adb logcat on console

There are two ways to obtain logs for android:
Use the logcat-view in DDMS prespective in eclipse. Pros - various
filters can be applied on the logs.
Print logs to a file using adb logcat command on console.
I was wondering if the logs obtained using both the methods are same?
If not, what is the difference (apart from filtering ease on ddms).
I mean, which logs should be used and when?
(I did not find both the ways giving the same logs)

What is the difference between logcat vs. dmesg?

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

Can I execute logcat on the mobile phone itself by issung a command in the shell?

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.

How to keep android device log from not being cleared?

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

Android: Retrieve logcat before crash (reboot) on a real device

I am developing an application and during my testing on a real device I have found that it will crash and cause the phone to reboot (worrying I know...)
Is there any way I retrieve the logcat from before the phone rebooted as the logcat seems to reset when the phone boots up.
Thanks in advance.
Use http://code.google.com/p/acra/, which is a great lib to send crash reports to a google form incl. stack trace. I use it in my app and works nicely. Let me know if you have any difficulties implementing it.
Read the http://code.google.com/p/acra/wiki/ACRAHowTo, it's easy to setup.
From slashfoo's blog, (check the logcat page for exact syntax)
hook up your computer to start off the logcat process in the background.
adb shell nohup logcat -f /dev/[your sdcard] -n60 -r3600
Although it means logcat will be saved to the sdcard but every time you reboot, you must perform the procedure again.
Easiest way:
Get aLogrec from Market for free.
This app saves the logs to sdcard.
Use the alogrec program. It writes the log to the SD card, and will automatically resume after rebooting.
Updating for 2019, Fabric, which was purchased by Google, does an excellent job of remote logging app crashes. Integration into the app was simple, and it is free (at least at whatever level I'm using it).
It has been extremely valuable to finding defects in my apps.
https://www.fabric.io
Try to open a terminal/command prompt and issue this in it :
adb -d logcat
This should dump you a live version of the logcat you could read to find the problem

Categories

Resources