Skip to content

lemonboston/android-investigator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 

Repository files navigation

Android Investigator

Android Arsenal

A simple tool that can be used to quickly add informative debug logs to the code during investigation without typing much:

@Override
public void onResume() {
    Investigator.log(this);
    ...
}

log:

D/Investigator: [main] [email protected]()

Features

Easy or automatic logging of the followings at the place of the call:

  • the thread name
  • the !! object instance !! (its toString() value)
  • the method name
  • the stacktrace (for custom method depth)
  • variable values conveniently
  • the time elapsed since a start call
  • an extra comment

Motivation

Android Investigator is not intended as a production logging solution but as a handy productivity tool for helping bugfixing and investigation, kept available on the debug classpath (or even commented out in gradle).
Logging the object instance (not just the class) is the extra that it does compared to other logging libraries. I found it useful in many situations (e.g.: configuration changes, fragment transactions, checking DI scopes, checking activity launchmodes).
It is also simple and convenient to use:

More sample usage

D/Tag: [main] [email protected]()								<- Investigator.log(this)

D/Tag: [thread-5] [email protected]() | comment				    	<- Investigator.log(this, "comment")

D/Tag: [main] [email protected]() | age = 32					<- Investigator.log(this, "age", age)

D/Tag: [main] [email protected]()						<- Investigator.log(this, 3);
				at sample.MyAsyncTask.onPostExecute(MyAsyncTask.java:10)
				at android.os.AsyncTask.finish(AsyncTask.java:651)
				at android.os.AsyncTask.-wrap1(AsyncTask.java)

D/Tag: [main] [email protected]() | 0 ms (STOPWATCH STARTED)	<- Investigator.startStopWatch(this);
D/Tag: [main] [email protected]() | 344 ms					<- Investigator.log(this);

Tag, default stacktrace method depth, thread name, and log level are customizable through the fields of the class. (Check out the class itself or the javadoc.)

When is it useful?

It can be most useful when debugging is not effective any more because there are too many checkpoints to step through or there is asynchronicity. Adding a few simple Investigator log calls to checkpoints can provide an overview about the order of the events, the object instances in play, variable values, where the watched method is called from, and on which thread. (I also found myself using it instead of simple debugging, too.)

Note: The log calls complete fast (usually under 1 ms) so they don't distort the normal program flow.

Download

Android Investigator is available in Maven Central.

Get with gradle:

dependencies {
    debugCompile 'com.github.lemonboston:android-investigator:1.0.0'
}

Or, since it is a single java class, it can be grabbed from here and added to the project (possibly under src/debug/java).

License

MIT License - Copyright (c) 2016 Gabor Keszthelyi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages