Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Tutorial] How To Logcat

OP paxChristos

22nd June 2012, 08:20 PM   |  #1  
paxChristos's Avatar
OP Retired Forum Moderator
Flag Milwaukee
Thanks Meter: 1,507
 
2,036 posts
Join Date:Joined: Aug 2011
Donate to Me
More
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

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

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!)
Last edited by paxChristos; 2nd July 2012 at 09:09 PM. Reason: Updated
The Following 444 Users Say Thank You to paxChristos For This Useful Post: [ View ]
1st July 2012, 12:08 PM   |  #2  
Recognized Contributor / Recognized Developer
Flag Swansea
Thanks Meter: 7,142
 
5,545 posts
Join Date:Joined: Mar 2009
Donate to Me
More
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: [ View ]
1st July 2012, 12:57 PM   |  #3  
Senior Member
Flag Ružomberok
Thanks Meter: 258
 
1,105 posts
Join Date:Joined: May 2008
Donate to Me
More
Perfect tutorial. Well done. ... I'll translate your tutorial into my language to share it other people.
The Following User Says Thank You to pRo_lama For This Useful Post: [ View ]
1st July 2012, 01:14 PM   |  #4  
paxChristos's Avatar
OP Retired Forum Moderator
Flag Milwaukee
Thanks Meter: 1,507
 
2,036 posts
Join Date:Joined: Aug 2011
Donate to Me
More
Quote:
Originally Posted by pRo_lama

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
The Following 2 Users Say Thank You to paxChristos For This Useful Post: [ View ]
1st July 2012, 01:18 PM   |  #5  
Junior Member
Thanks Meter: 5
 
11 posts
Join Date:Joined: 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: [ View ]
1st July 2012, 01:33 PM   |  #6  
paxChristos's Avatar
OP Retired Forum Moderator
Flag Milwaukee
Thanks Meter: 1,507
 
2,036 posts
Join Date:Joined: Aug 2011
Donate to Me
More
Quote:
Originally Posted by Krain

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
Last edited by paxChristos; 1st July 2012 at 01:43 PM.
The Following 6 Users Say Thank You to paxChristos For This Useful Post: [ View ]
1st July 2012, 02:21 PM   |  #7  
tranceph0rmer's Avatar
Senior Member
Flag New Delhi
Thanks Meter: 68
 
614 posts
Join Date:Joined: Jun 2012
More
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: [ View ]
1st July 2012, 03:05 PM   |  #8  
Moscow Desire's Avatar
Senior Moderator - Resident Troll Killer
Flag Somewhere in a Deep Cave on the Troll Kings Throne
Thanks Meter: 6,233
 
7,467 posts
Join Date:Joined: Mar 2011
Donate to Me
More
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
Last edited by Moscow Desire; 1st July 2012 at 03:09 PM.
The Following 11 Users Say Thank You to Moscow Desire For This Useful Post: [ View ]
1st July 2012, 03:11 PM   |  #9  
paxChristos's Avatar
OP Retired Forum Moderator
Flag Milwaukee
Thanks Meter: 1,507
 
2,036 posts
Join Date:Joined: Aug 2011
Donate to Me
More
Quote:
Originally Posted by tranceph0rmer

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
The Following 4 Users Say Thank You to paxChristos For This Useful Post: [ View ]
1st July 2012, 03:21 PM   |  #10  
paxChristos's Avatar
OP Retired Forum Moderator
Flag Milwaukee
Thanks Meter: 1,507
 
2,036 posts
Join Date:Joined: Aug 2011
Donate to Me
More
Quote:
Originally Posted by Moscow Desire

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

The Following 3 Users Say Thank You to paxChristos For This Useful Post: [ View ]
Post Reply Subscribe to Thread

Tags
how to logcat, logcat, logcat guide, troubleshooting guide
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes