FORUMS
Remove All Ads from XDA

[Reference] How to get useful logs

5,022 posts
Thanks Meter: 34,984
 
By tonyp, Inactive Recognized Developer on 11th March 2013, 03:31 PM
Post Reply Email Thread
We're on a development site - at least in theory.
To help out development without actually having some knowledge it's really important to know how and when to get logs.
Lately more and more people in this section do grab appropriate logs, which is a good thing and has already helped in fixing a bunch of bugs.
To stop (especially new) people from constantly asking how to get logcats I decided to hand out a quick reference on how to grab logs efficiently via adb / terminal / app.

There is an app which can export apps (see the end of this post), but you should learn how to get logs via adb anyways, as a dmesg is often crucial in case of debugging bsods.
I won't post instructions in how to get adb working - you can use Google or take this CM wiki entry as a starting point.


The three most important log types are:
  • logcat: the logoutput of the Android system
  • radio logcat: the log outpur ot your System / BB / RIL communication
  • kernel log (kmsg / dmesg): the kernel messages
    Additionally there's the last_kmsg which is a dump of the kernel log until the last shutdown.



Normal Logcat:
Code:
adb logcat -v time -d > logcat.log
Radio Logcat:
Code:
adb logcat -b radio -v time -d > logcat_radio.log

Note: Cyanogenmod (based) ROMs require the following setting to export kernel logs via adb:
Settings - Developer Options - Root access - choose: "Apps and ADB"


Kernel Log:
Code:
adb shell su -c dmesg > dmesg.log
Last_kmsg:
Code:
adb shell su -c "cat /proc/last_kmsg" > last_kmsg.log
For getting the logs via the Terminal Emulator app the commands differ a little:
Get logs via Terminal Emulator:
Normal Logcat:
Code:
logcat -v time -d > /sdcard/logcat.log
Radio Logcat:
Code:
logcat -b radio -v time -d > /sdcard/logcat_radio.log
Kernel Log:
Code:
su -c dmesg > /sdcard/dmesg.log
Last_kmsg:
Code:
su -c "cat /proc/last_kmsg" > /sdcard/last_kmsg.log

Notes:
  • -v time will include timestamps in the logcats
  • -d will export the complete log.
    If you want to save a continuous log you can remove the -d parameter - then you need to cancel the logging process via CTRL+C.
    To export a continuous kernel log use adb shell su -c "cat /proc/kmsg" > dmesg.log (and cancel it via CTRL+C again).

Exporting logs with an app:

I used to recommend Lumberjack for grabbing logs, but it doesn't work with Jellybean properly anymore and fails to export the dmesg.
I googled for a while and found a great (and fully open sourced) alternative to export logs: SysLog
With this great app there are no more excuses - at least open the app, export all 4 log types and attach the zip file from /sdcard/SysLog to your bug report.
Before anyone asks (duh!), Kernel log = dmesg, Last kernel log= last_kmsg, main log = logcat, modem log = radio log.
Lumberjack still is great to have a look at logs on the phone, but for exporting you probably should use SysLog as it does it quickly and reliable

SysLog (source):


The Following 143 Users Say Thank You to tonyp For This Useful Post: [ View ] Gift tonyp Ad-Free
 
 
11th March 2013, 03:31 PM |#2  
tonyp's Avatar
OP Inactive Recognized Developer
Thanks Meter: 34,984
 
Donate to Me
More
When to post which kind of logs:
  • If you got any kind of ROM problems - especially problems with Apps like force closes, attach a logcat.
  • If there are problems while calling or with your signal attach a radio logcat to the normal logcat.
  • In kernel threads or on issues which might be kernel related (from A as auto brightness to Z as ZRAM) you need a kernel log
  • If you had a sudden reboot attach a last_kmsg, then we can check if it's been kernel related

As our phone has always been on the edge of bsod's and freezes, some special notes about them as well:
  • If you had a bsod and/or freeze a logcat dmesg after rebooting is useless, as it doesn't show anything from before the reboot
  • There are two things you can do:
    1. While the phone's screen is black connect the cable to your computer and check if the device is accessable via adb (check e.g. with "adb devices").
      If it is export the dmesg like explained above. If not go on to step 2:
      Note that two of the bsod problems of the ICS/CM kernel have been fixed by pengus by the logs I managed to get while the phone has been in a bsod - which means this is crucial!
    2. Pull the battery and insert it again as quickly as possible. Why? The phone does hold a so called last_kmsg in RAM.
      It's non-permanent memory, which means it doesn't survive a loss of power - sometimes we're in luck by a quick pull though.
      If we're not in luck the file will be empty or contain scrambled characters.


Last but not least some general remarks:
  • If you don't provide useful logs we can not help you in 95% of the cases in case we can't reproduce it.
    Buf even if we could reproduce it - let's assume one of YOUR apps is force closing. Why should we install the app to reproduce the problem and get the logs ourselves.
    YOU want help, so YOU should provide the log.

  • Every real dev with some coding knowledge will need logs to fix the bugs.

  • This site is called xda-developers - which means that the initial intention of this forum is the actual development itself - and not "making your phone cool".
    The least you can (and must) do is to provide useful help with a clear problem description and attached logs when you run into some issues
The Following 53 Users Say Thank You to tonyp For This Useful Post: [ View ] Gift tonyp Ad-Free
11th March 2013, 03:32 PM |#3  
tonyp's Avatar
OP Inactive Recognized Developer
Thanks Meter: 34,984
 
Donate to Me
More
Choose 1 or 2:

1:
What developers like:


What developers don't like:

2:
The Following 31 Users Say Thank You to tonyp For This Useful Post: [ View ] Gift tonyp Ad-Free
11th March 2013, 03:50 PM |#4  
Senior Member
Flag Near Versailles - France
Thanks Meter: 22
 
More
Great, an other useful thread from you
11th March 2013, 04:27 PM |#5  
besho2222's Avatar
Senior Member
Thanks Meter: 31
 
More
Such a great and useful post, should be stickied ...
11th March 2013, 04:47 PM |#6  
Senior Member
Flag Sydney
Thanks Meter: 41
 
More
thank you so much for this tonyp.. i've been trying with lumberjack for a while and couldn't ever get any last_kmsg even with a quick battery pull.. i will try the syslog export
11th March 2013, 05:13 PM |#7  
tonyp's Avatar
OP Inactive Recognized Developer
Thanks Meter: 34,984
 
Donate to Me
More
Quote:
Originally Posted by besho2222

Such a great and useful post, should be stickied ...

It is stickied
The Following 3 Users Say Thank You to tonyp For This Useful Post: [ View ] Gift tonyp Ad-Free
11th March 2013, 05:39 PM |#8  
Senior Member
Flag On The Run
Thanks Meter: 554
 
More
Awesome, thank you.
11th March 2013, 08:10 PM |#9  
tonyp's Avatar
OP Inactive Recognized Developer
Thanks Meter: 34,984
 
Donate to Me
More
Just a small update, I added "su" requests to the kernel log commands in post 1.
This ensures you won't run into permission denied problems.

My ParanoidAndroid ROM is a eng-build so you won't need that there, but on most other CM10 / CM10.1 ROMs you'll probably need to ask about superuser rights.
Root shouldn't be disabled at Settings - Developer Options - Root access of course.
3rd April 2013, 11:37 PM |#10  
oneearleft's Avatar
Senior Member
Thanks Meter: 102
 
More
Question How to get the last kernel log?
I have tried several times now; I can't find the last kernel log:
in SysLog last kernel log option is greyed out, and
with adb as described above response is
Quote:

sh: cat: /proc/last_kmsg: No such file or directory

What I am doing wrong? Do I have to put some check mark?
I have checked root access for apps and adb...
3rd April 2013, 11:59 PM |#11  
tonyp's Avatar
OP Inactive Recognized Developer
Thanks Meter: 34,984
 
Donate to Me
More
Quote:
Originally Posted by oneearleft

I have tried several times now; I can't find the last kernel log:
in SysLog last kernel log option is greyed out, and
with adb as described above response is

What I am doing wrong? Do I have to put some check mark?
I have checked root access for apps and adb...

Do a reboot, is the file there then? It won't be there every time, just if the kernel manages to save it properly (reboot, usually oops and panic).
The Following User Says Thank You to tonyp For This Useful Post: [ View ] Gift tonyp Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes