forked from androidannotations/androidannotations
-
Notifications
You must be signed in to change notification settings - Fork 0
Trace Method Execution
pyricau edited this page Jan 12, 2012
·
4 revisions
Since AndroidAnnotations 2.2
The @Trace annotation allows you to trace the execution of a method by writing log entries.
The method must not be private.
Usage examples:
@Trace
void doWork() {
// ... Do Work ...
}Will generate those log entries:
I/TracedMethodActivity( 302): Entering [void doWork() ]
I/TracedMethodActivity( 302): Exiting [void doWork() ], duration in ms: 1002
Equivalent boilerplate code :
public void doWork() {
if (Log.isLoggable("TracedMethodActivity", Log.INFO)) {
long start = System.currentTimeMillis();
Log.i("TracedMethodActivity", "Entering [void doWork() ]");
}
try {
// ... Do Work ...
} finally {
if (Log.isLoggable("TracedMethodActivity", Log.INFO)) {
long duration = (System.currentTimeMillis()-start);
Log.i("TracedMethodActivity", ("Exiting [void doWork() ], duration in ms: "+ duration));
}
}
}You can also specify the tag and the level of the log message:
@Trace(tag="CustomTag", level=Log.WARN)
void doWork() {
// ... Do Work ...
}W/CustomTag( 533): Entering [void doWork() ]
W/CustomTag( 533): Exiting [void doWork() ], duration in ms: 1001
14/06/2012 The 2.6 release is out
- Get started!
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow