Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,810,899 Members 38,050 Now Online
XDA Developers Android and Mobile Development Forum

[Tutorial] How To Logcat

Tip us?
 
paxChristos
Old
(Last edited by paxChristos; 2nd July 2012 at 08:09 PM.) Reason: Updated
#1  
paxChristos's Avatar
Retired Forum Moderator - OP
Thanks Meter 1,487
Posts: 2,036
Join Date: Aug 2011
Location: Milwaukee

 
DONATE TO ME
Default [Tutorial] How To Logcat

Here's how to use logcat:
There are two main ways to do a logcat, within android, and through adb.
Logcat within android can be done one of two ways, through a Logcat app:
Here are two good examples are either: aLogcat or Catlog
I prefer catlog, because in my opinion it has a little bit nicer UI. Both of these programs can dump their logs to a txt file, which is very useful for debugging. Or, you can do it in terminal emulator (same rules as running through adb(see below))

From Moscow Desire:
Quote:
Originally Posted by Moscow Desire View Post
Just a little more info when doing logcat.

Remember, Logcat will run till you end the session. And it won't always create the file till you do so. It's possible you may not see the logfile for a minute or so.

Edit: For phones/tablets with internal storage & external sd:
(note that the location naming convention may be different depending on device)

Open your terminal app;

Type: logcat > /sdcard/logcat.txt (this should create it in internal memory on the tablet)

To send to ext sd card: logcat > /mnt/external_sd/logcat.txt

I use a tablet for example Phones may have a different naming convention.

MD
On the other hand, using adb to run logcat, in my opinion is much more useful, because you can start using it when android boots (i.e. once the boot animation appears.)

The code for logcat to output to a file is
Code:
adb logcat > name of problem.txt
you can also do
Code:
adb logcat -f name of problem.txt
how I prefer to do it is this way:
Code:
adb logcat -v long > name of problem.txt
with the -v flag & the long argument, it changes output to long style, which means every line of logcat will be on its own line (makes it a little neater, imo)
Note: When outputting to a file, you will see a newline, but nothing printed, this is normal. To stop logcat from writting to a file, you need to press ctrl+c.

Here's where using logcat (via adb makes life really easy)
Lets say you find a problem you're having after looking at a logcat.

For example:
When I was trying to use a different ramdisk, wifi wouldn't work so I got a logcat that's almost 1300 lines long (a lot of stuff happens in the background)

So if you are searching for an error in the logcat file (it's always e/ for error, f/ for fatal. Those are the two main things that will break a system.)

Code:
D/dalvikvm(  871): GC_CONCURRENT freed 472K, 6% free 10224K/10823K, paused 1ms+6ms
V/AmazonAppstore.DiskInspectorServiceImpl(  871): Available blocks: 21981, Block size: 4096, Free: 90034176, Threshold: 5242880, withinThreshold? true
D/AmazonAppstore.UpdateService(  871): Received action: null from intent: Intent { cmp=com.amazon.venezia/com.amazon.mas.client.framework.UpdateService }
W/AmazonAppstore.UpdateService(  871): Confused about why I'm running with this intent action: null from intent: Intent { cmp=com.amazon.venezia/com.amazon.mas.client.framework.UpdateService }
D/dalvikvm(  890): GC_CONCURRENT freed 175K, 4% free 9375K/9671K, paused 2ms+3ms
V/AmazonAppstore.ReferenceCounter(  871): Reference (MASLoggerDB) count has gone to 0. Closing referenced object.
E/WifiStateMachine(  203): Failed to reload STA firmware java.lang.IllegalStateException: Error communicating to native daemon 
V/AmazonAppstore.UpdateService(  871): runUpdateCommand doInBackground started.
V/AmazonAppstore.UpdateService(  871): Running UpdateCommand: digitalLocker
V/AmazonAppstore.UpdateCommand(  871): Not updating key: digitalLocker from: 1334228488057
V/AmazonAppstore.UpdateService(  871): Finished UpdateCommand: digitalLocker
V/AmazonAppstore.UpdateService(  871): Running UpdateCommand: serviceConfig
V/AmazonAppstore.MASLoggerDB(  871): performLogMetric: Metric logged: ResponseTimeMetric [fullName=com.amazon.venezia.VeneziaApplication_onCreate, build=release-2.3, date=Wed Apr 11 13:10:55 CDT 2012, count=1, value=1601.0]
V/AmazonAppstore.MASLoggerDB(  871): onBackgroundTaskSucceeded: Metric logged: ResponseTimeMetric [fullName=com.amazon.venezia.VeneziaApplication_onCreate, build=release-2.3, date=Wed Apr 11 13:10:55 CDT 2012, count=1, value=1601.0]
W/CommandListener(  118): Failed to retrieve HW addr for eth0 (No such device)
D/CommandListener(  118): Setting iface cfg
D/NetworkManagementService(  203): rsp 
D/NetworkManagementService(  203): flags 
E/WifiStateMachine(  203): Unable to change interface settings: java.lang.IllegalStateException: Unable to communicate with native daemon to interface setcfg - com.android.server.NativeDaemonConnectorException: Cmd {interface setcfg eth0 0.0.0.0 0 [down]} failed with code 400 : {Failed to set address (No such device)}
W/PackageParser(  203): Unknown element under : supports-screen at /mnt/asec/com.android.aldiko-1/pkg.apk Binary XML file line #16
D/wpa_supplicant(  930): wpa_supplicant v0.8.x
D/wpa_supplicant(  930): random: Trying to read entropy from /dev/random
D/wpa_supplicant(  930): Initializing interface 'eth0' conf '/data/misc/wifi/wpa_supplicant.conf' driver 'wext' ctrl_interface 'N/A' bridge 'N/A'
D/wpa_supplicant(  930): Configuration file '/data/misc/wifi/wpa_supplicant.conf' -> '/data/misc/wifi/wpa_supplicant.conf'
D/wpa_supplicant(  930): Reading configuration file '/data/misc/wifi/wpa_supplicant.conf'
D/wpa_supplicant(  930): ctrl_interface='eth0'
D/wpa_supplicant(  930): update_config=1
D/wpa_supplicant(  930): Line: 4 - start of a new network block
D/wpa_supplicant(  930): key_mgmt: 0x4
(mind you, that's 29 lines out of 1300ish, just for example)

I then could do the following with logcat:
Code:
adb logcat WifiStateMachine:E *:S -v long > name of problem.txt
and this will only print out any errors associated with WifiStateMachine, and anything which is fatal, which makes it about a million times easier to figure out what's going on!

In WifiStateMachine:E, the :E = to look for Errors, the full list of options is as follows:
V — Verbose (lowest priority)
D — Debug
I — Info (default priority)
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)

You can replace the :E with any other letter from above to get more info.
In order to filter out anything other than what you are looking for (in this case, WifiStateMachine) you must put a *:S after your last command (i.e. WifiStateMachine:E ThemeChoose:V ... ... AndroidRuntime:E *:S)

Sources: http://developer.android.com/tools/help/logcat.html
http://developer.android.com/tools/help/adb.html

Update for windows users:
Thank go to FuzzyMeep Two, Here's what he's posted for windows

Quote:
Originally Posted by FuzzyMeep Two View Post
I have made a tool to simplify this for people. I will send you the .bat version, to see the validity of the file, and post the .exe for everyone else.

http://logcat-tool.googlecode.com/fi...gcatHELPER.exe

I made this in about a half hour, so if you fnd any issues let me know. I believe i worked out all functionality issues, and do plan on expanding functionality in the future.
(If you used his tool, here's his post, thank him for his work!)
Tips:
*Logcat or it never happened. *Search before posting *Go to User CP -> Edit Options -> switch "Number of Posts to Show Per Page" to 50. *Reporting Posts

Looks like I won't be doing anything android for a long time

Thanks for the lul'z

Pax
The Following 428 Users Say Thank You to paxChristos For This Useful Post: [ Click to Expand ]
 
Lloir
Old
#2  
Recognized Contributor / Recognized Developer
Thanks Meter 6,676
Posts: 5,195
Join Date: Mar 2009

 
DONATE TO ME
Very nicely done, now i have something i can refer people to
The Following 4 Users Say Thank You to Lloir For This Useful Post: [ Click to Expand ]
 
pRo_lama
Old
#3  
Senior Member
Thanks Meter 223
Posts: 1,019
Join Date: May 2008
Location: Ružomberok

 
DONATE TO ME
Perfect tutorial. Well done. ... I'll translate your tutorial into my language to share it other people.
fqf

# LG G3 (32GB): stock ROM (V10h-EUR-XX) - rooted
# Google Nexus 7 (2013): OmniROM 4.4.4 - unlocked bootloader - rooted
# Samsung Gear Fit (SM-R350): R350XXU0BNE5 - black/orange strap - GFM v1.67.0523
The Following User Says Thank You to pRo_lama For This Useful Post: [ Click to Expand ]
 
paxChristos
Old
#4  
paxChristos's Avatar
Retired Forum Moderator - OP
Thanks Meter 1,487
Posts: 2,036
Join Date: Aug 2011
Location: Milwaukee

 
DONATE TO ME
Quote:
Originally Posted by pRo_lama View Post
Perfect tutorial. Well done. ... I'll translate your tutorial into my language to share it other people.
Thank you! And thanks for taking your time to translate it!

If you need me to clarify anything shoot me a PM, and I'll help! (Same goes for anybody else interested in porting to their language)

Pax
Tips:
*Logcat or it never happened. *Search before posting *Go to User CP -> Edit Options -> switch "Number of Posts to Show Per Page" to 50. *Reporting Posts

Looks like I won't be doing anything android for a long time

Thanks for the lul'z

Pax
The Following 2 Users Say Thank You to paxChristos For This Useful Post: [ Click to Expand ]
 
Krain
Old
#5  
Junior Member
Thanks Meter 5
Posts: 11
Join Date: Nov 2010
Very nice, but I do have a question (and I started programming for Android recently): What do you do when the system reboots while debugging (in my case musb_hdrc.ko)? I tried catlog, but the logs are empty... Is there another way to do that?

Thank you in advance
The Following 2 Users Say Thank You to Krain For This Useful Post: [ Click to Expand ]
 
paxChristos
Old
(Last edited by paxChristos; 1st July 2012 at 12:43 PM.)
#6  
paxChristos's Avatar
Retired Forum Moderator - OP
Thanks Meter 1,487
Posts: 2,036
Join Date: Aug 2011
Location: Milwaukee

 
DONATE TO ME
Quote:
Originally Posted by Krain View Post
Very nice, but I do have a question (and I started programming for Android recently): What do you do when the system reboots while debugging (in my case musb_hdrc.ko)? I tried catlog, but the logs are empty... Is there another way to do that?

Thank you in advance
Use adb instead of an in-android method to capture the logs, you can start when the boot animation starts (note: Not when the kernel splash screen appears) and when it reboots, it'll automatically end. (i.e. run the following in command prompt:
Code:
 adb logcat *:E > oh_nos_it_crashed.txt
)

If you're not getting to the boot animation (keeps cycling on the Kernel splash screen) then you have kernel issues, and you need a kernel that has integrated last_kmsg (a whole different ball of wax that I'm still learning about) to figure out what's going on. (kmesg's are direct kernel output)

Maybe if someone like AdamOutler (or any other Dev who has a much better handle on them than myself) were to explain them, it'd help

Pax
Tips:
*Logcat or it never happened. *Search before posting *Go to User CP -> Edit Options -> switch "Number of Posts to Show Per Page" to 50. *Reporting Posts

Looks like I won't be doing anything android for a long time

Thanks for the lul'z

Pax
The Following 6 Users Say Thank You to paxChristos For This Useful Post: [ Click to Expand ]
 
tranceph0rmer
Old
#7  
tranceph0rmer's Avatar
Senior Member
Thanks Meter 68
Posts: 614
Join Date: Jun 2012
Location: New Delhi
Hey man regarding your guide .
I was testing a built of cm9 from my htc one v and it wasnt booting so the dev told me to do a logcat for it .
Just wondering what the process and commands would be?
Thanks.
The Following User Says Thank You to tranceph0rmer For This Useful Post: [ Click to Expand ]
 
Moscow Desire
Old
(Last edited by Moscow Desire; 1st July 2012 at 02:09 PM.)
#8  
Moscow Desire's Avatar
Senior Moderator - Resident Troll Killer
Thanks Meter 6,012
Posts: 7,262
Join Date: Mar 2011
Location: Somewhere in a Deep Cave on the Troll Kings Throne

 
DONATE TO ME
Just a little more info when doing logcat.

Remember, Logcat will run till you end the session. And it won't always create the file till you do so. It's possible you may not see the logfile for a minute or so.

But what if you can't connect ADB to your device? You can do this

(note that the location naming convention may be different depending on device)

Open your terminal app;

Type: logcat > /sdcard/logcat.txt (this should create it in internal memory on the tablet)

To send to ext sd card: logcat > /mnt/external_sd/logcat.txt

I use a tablet for example Phones may have a different naming convention.

Nice definition of the display terminology

MD

Want to avoid a vacation to the Frostlands? Then Follow the XDA Rules Here

 
Though I walk among the trolls, I fear them not, for I am the Troll King
Killen dem Trolls since 2011
Acer Iconia A701***A501***ExPlay X-Tremer***HTC Desire***Desire S
The Following 11 Users Say Thank You to Moscow Desire For This Useful Post: [ Click to Expand ]
 
paxChristos
Old
#9  
paxChristos's Avatar
Retired Forum Moderator - OP
Thanks Meter 1,487
Posts: 2,036
Join Date: Aug 2011
Location: Milwaukee

 
DONATE TO ME
Quote:
Originally Posted by tranceph0rmer View Post
Hey man regarding your guide .
I was testing a built of cm9 from my htc one v and it wasnt booting so the dev told me to do a logcat for it .
Just wondering what the process and commands would be?
Thanks.
What you'll wanna do is run the following,
Code:
 adb logcat *:E > crash.txt
And look at the output file specifically for lines that say 0x0deadbaad (if you see that, that means there's a problem with the Java libraries it references above it) otherwise look for other F/ lines, that'll point you in the right direction.

If you're having issues where and is not accessible for to buy having USB debugging turned off because of doing a /data wipe (factory data reset) first install a similar Rom (in your case, a prior, stable CM9, boot into it, turn on usb debugging, reboot into recovery & only write /cache & dalvik cache before installing the offending Rom & getting your logcat (sorry if I rambled, just got done working a double )

Pax

Sent from my R800x using Tapatalk 2
Tips:
*Logcat or it never happened. *Search before posting *Go to User CP -> Edit Options -> switch "Number of Posts to Show Per Page" to 50. *Reporting Posts

Looks like I won't be doing anything android for a long time

Thanks for the lul'z

Pax
The Following 3 Users Say Thank You to paxChristos For This Useful Post: [ Click to Expand ]
 
paxChristos
Old
#10  
paxChristos's Avatar
Retired Forum Moderator - OP
Thanks Meter 1,487
Posts: 2,036
Join Date: Aug 2011
Location: Milwaukee

 
DONATE TO ME
Quote:
Originally Posted by Moscow Desire View Post
Just a little more info when doing logcat.

Remember, Logcat will run till you end the session. And it won't always create the file till you do so. It's possible you may not see the logfile for a minute or so.

But what if you can't connect ADB to your device? You can do this

(note that the location naming convention may be different depending on device)

Open your terminal app;

Type: logcat > /sdcard/logcat.txt (this should create it in internal memory on the tablet)

To send to ext sd card: logcat > /mnt/external_sd/logcat.txt

I use a tablet for example Phones may have a different naming convention.

Nice definition of the display terminology

MD
Thanks, MD!

The problem is when you can't access terminal (bootloops, fc'ing like it's going out of style, etc.) that adb is really useful. Sometimes to trick the system into working, you can (esp with AOSP based roms) install a same version of android (I.e. 4.0.4) & not wipe /data (after turning on usb debugging) & still have an access :P (I learned this after spending about 2-3 months crack flashing my own builds & getting tired of titanium restoring all my apps)

Pax

Sent from my R800x using Tapatalk 2
Tips:
*Logcat or it never happened. *Search before posting *Go to User CP -> Edit Options -> switch "Number of Posts to Show Per Page" to 50. *Reporting Posts

Looks like I won't be doing anything android for a long time

Thanks for the lul'z

Pax

The Following 2 Users Say Thank You to paxChristos For This Useful Post: [ Click to Expand ]
Tags
how to logcat, logcat, logcat guide, troubleshooting guide
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes