Home Tutorials Hands on Android logging
Android logging
Tutorials - Hands on
Thursday, 16 October 2008 20:17
Article Index
Android logging
Can't see the wood for the trees
Filtering
All Pages
LoggingWhen your application is running, how can you tell exactly what it's doing at any time? After it has finished, how can you tell what it did during the run? If you are hunting down elusive bugs, you need all the tools you can get, and right up there with the interactive debugger is the logger. Google realise its importance and have done the one in the Android Eclipse plug-in sufficient justice. We will show how to set up our application for logging, perform some test runs and further refine our logging system to cut out the noise and focus on only the areas of our application we are interested in.
Tutorial: Android logging | Skill: Beginner | Download apk | Download source

To keep things simple, we'll use our trusty Wash your hands! application - you might want to download its files before continuing. We'll also be using the popular Eclipse and Android Eclipse plugin for this work, so if this is new to you it would be useful to go through our setup guide.

First, a little background regarding logging. Every computer language has had a way of sending output somewhere, and developers have taken advantage of this for decades. A great example is the C language with its print() statement. The developers could place these tracing statements at the appropriate point in their code to show items of interest, such as code paths and variable values. When the software was to be shipped, these trace statements were removed or suppressed. As UI systems further evolved in complexity, these base console systems were retained, so for example you could send them to a terminal or text file whilst the rich UI of your application ran normally. Sound familiar? That's exactly our scenario.

Java has had comprehensive logging support from early on, and it became apparent that with more complex systems, especially multi-user ones with no UI such as servers, the logging support was a crucial element in the development arsenal. A popular system was released by the Apache Foundation called log4j. This was widely used because it offered tremendous power and flexibility with the minimum setup and disruption to the running code. And it's here where we move onto the Android Eclipse plugin logger, because it bears more than a passing resemblance to this excellent battle-hardened system.

So - let's load up our fingerprint application and set it up for logging. The first thing we need to do is ensure we can see the place the logging will go to. This is either the Debug perspective or the DDMS perspective. They are available from the top right hand perspective button in Eclipse. We'll choose the Debug perspective:

 

 

You can see the LogCat window with some entries present before we even run anything.



 

Add comment


Security code
Refresh

Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 30 guests online