[Reference] How to get useful logs

Search This thread

Adam77Root

Inactive Recognized Developer
Jul 3, 2012
2,521
11,117
Nice guide you put together here. This should be in general Android forums. I especially like the third post. :D
 

XDA-00

Senior Member
Sep 6, 2015
348
50
New Delhi
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):


Please tell me what type of log to use for checking wifi.
 

thechosenone43

Senior Member
Feb 3, 2015
671
145
Xiaomi Poco F1
What are you even asking?

"make a logcat while in TWRP?"... "setup a custom ROM please"

... What?

Try explaining what you're trying to accomplish in detail.

Ok. Im aware to make a Logcat with a Terminal Emulator on my device.

But I want to make a Log when flashing a new Custom ROM (Omni Rom) because I get FC and Pop ups even in clean install ROM and Gapps. So I think it works with PC and ADB or so... But that I'm asking for here in this thread.

Idk can you understand that question now? Thanks
 

Paschfire

Senior Member
May 16, 2014
932
812
46
Ottawa
Samsung Galaxy A20
Ok. Im aware to make a Logcat with a Terminal Emulator on my device.

But I want to make a Log when flashing a new Custom ROM (Omni Rom) because I get FC and Pop ups even in clean install ROM and Gapps. So I think it works with PC and ADB or so... But that I'm asking for here in this thread.

Idk can you understand that question now? Thanks

Use the XDA search box to find a guide on how to install, setup and use ADB/Fastboot on your PC. Then you can record logs via terminal prompt.

There are many tutorials available on how to setup and use ADB/Fastboot on a PC(Windows, Mac, Linux...etc). A simple Google search should also be helpful in finding guidance.

Sent from my OnePlus 3T using XDA Labs
 
Last edited:

Zwani

New member
Jun 22, 2020
1
0
My device is struck on boot screen. Please give detailed adb commands. When I write kernal commonds in adb it shows access denied.
 

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