[Reference] How to get useful logs

Search This thread

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
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):


 
Last edited:

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
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
 
Last edited:

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
Choose 1 or 2:

1:
What developers like:
Logcat.jpg


What developers don't like:
SPOON-FEEDING-re%2520%25281%2529.gif

2:
3645qt.jpg
 
Last edited:

CVonV

Senior Member
Mar 7, 2010
433
46
Sydney
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
 

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
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.
 

oneearleft

Senior Member
Jan 16, 2013
203
102
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
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...
 

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
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).
 
  • Like
Reactions: oneearleft

dargon91

Senior Member
Jan 8, 2012
51
4
tonyp I am having RAPID restarts with your PA ROM.. everything is fine, battery life , smoothness, performance but this restarts are so annoying .. I am talking and oooopsss big X in the screen... then NO network... i am going to Lumberjack last kmsp and nothing file is empty, go to logsys there is no check on karnel log.. :( ;( :( I am so depressed i am having restarts even when i am using Chat clients like "Whats app" or "Viber" ... When network is busy phone is restarting.. :/ I dont like moving to another ROM but i cant see other escape. Please tell me how to get those stupid logs ;( ;( i tried everything :/ I made 3-4 full wipes but nothing happends .. everything is like usual ... restart restart no network restart.. :/ ;( ;( :( :( :(

Here is what i got from Logsys just a minute ago (after another restart and removing battery) but there is no last kmsg log again :/
http://speedy.sh/GjmDH/2013-04-05-16.12.zip
 
Last edited:

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
tonyp I am having RAPID restarts with your PA ROM.. everything is fine, battery life , smoothness, performance but this restarts are so annoying .. I am talking and oooopsss big X in the screen... then NO network... i am going to Lumberjack last kmsp and nothing file is empty, go to logsys there is no check on karnel log.. :( ;( :( I am so depressed i am having restarts even when i am using Chat clients like "Whats app" or "Viber" ... When network is busy phone is restarting.. :/ I dont like moving to another ROM but i cant see other escape. Please tell me how to get those stupid logs ;( ;( i tried everything :/ I made 3-4 full wipes but nothing happends .. everything is like usual ... restart restart no network restart.. :/ ;( ;( :( :( :(

Here is what i got from Logsys just a minute ago (after another restart and removing battery) but there is no last kmsg log again :/
http://speedy.sh/GjmDH/2013-04-05-16.12.zip

Well you aren't doing anything wrong, it seems like the logs just aren't there.
As you're the only one with these issues and can't produce logcats you have to figure this out yourself, I'm afraid.
I'd suggest to use NVFlash / AIOToolkit and start fresh. Do NOT restore data with TitaniumBackup or similiar apps.
I have no idea what's up with your phone, maybe it's the hardware. If it only affects my ROM then move to another one.
And please remember that this is not the PA thread.
 
Last edited:

dargon91

Senior Member
Jan 8, 2012
51
4
I know sorry for offtopic but i am so depressed i want get those logs cuz my phone is messed up .. :/ and i cant well i will think of formating everything it would be the last choise :/
 

Custom40

Senior Member
Aug 5, 2010
880
908
Consider adding a link to this tool right here: AIOlog
Don't mind the screenshot in that thread, it will detect & write Device Model: LG P990 automatically when it is connected.
That tool makes the simple things even more simple ;)
 

Vippo321

Senior Member
Jan 25, 2010
141
9
Nové Zámky
Great

Thank you for this little tutorial, you helped a lot. ;) But I am thinking about if its not possible to watch phone logs live on you pc, while your phone is connected via USB. :D
 

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
Thank you for this little tutorial, you helped a lot. ;) But I am thinking about if its not possible to watch phone logs live on you pc, while your phone is connected via USB. :D

Just type adb logcat (without the "arrow" to save the logs and the -d parameter), then you'll see it in the console.

Or if you got the android developer kit installed use the included ddms.bat or eclipse to have a nice logcat viewer.


Sent from my LG-P990 using xda app-developers app
 

natalya

Senior Member
Jul 24, 2012
988
800
Tony/pengus/anyone else, do you use Android SDK to adb logcat or normal command prompt on Windows? because lets say my phone is stuck on the LG logo, am I wrong to think that the PC won't detect the phone? I have been trying with Android SDK but I just haven't been able to adb logcat when it is stuck on LG logo or even bootamination. Actually, I did get to adb logcat when it was stuck on bootamination once, but I have no idea what I did lol.
Seriously need help, especially when its stuck on LG logo, got no idea how to logcat in such case.
Note: I am on Windows 7.
Thanks a lot!
 

tonyp

Inactive Recognized Developer
Feb 3, 2011
5,019
34,902
Tony/pengus/anyone else, do you use Android SDK to adb logcat or normal command prompt on Windows? because lets say my phone is stuck on the LG logo, am I wrong to think that the PC won't detect the phone? I have been trying with Android SDK but I just haven't been able to adb logcat when it is stuck on LG logo or even bootamination. Actually, I did get to adb logcat when it was stuck on bootamination once, but I have no idea what I did lol.
Seriously need help, especially when its stuck on LG logo, got no idea how to logcat in such case.
Note: I am on Windows 7.
Thanks a lot!

Okay, here's the deal.
You probably didn't do anything wrong. There are different kind of bootloops - sometimes the phone initializes correctly and manages to bring up the adb interface before it loops - but sometimes the error happens before that, then there's nothing you can do.

Just check if the device is online with "adb devices" - if there's no serial number you don't have adb access to the phone.
 

maqninou

Senior Member
Jun 9, 2012
169
19
Algiers
I'm trying to generate a logcat through Terminal Emulator but keep getting an error msg : -c not found. Any idea please?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 143
    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):


    53
    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
    30
    Choose 1 or 2:

    1:
    What developers like:
    Logcat.jpg


    What developers don't like:
    SPOON-FEEDING-re%2520%25281%2529.gif

    2:
    3645qt.jpg
    3
    Such a great and useful post, should be stickied ...

    It is stickied :D
    2
    Thank you for this little tutorial, you helped a lot. ;) But I am thinking about if its not possible to watch phone logs live on you pc, while your phone is connected via USB. :D

    Just type adb logcat (without the "arrow" to save the logs and the -d parameter), then you'll see it in the console.

    Or if you got the android developer kit installed use the included ddms.bat or eclipse to have a nice logcat viewer.


    Sent from my LG-P990 using xda app-developers app