Reputation: 1127
Currently I write my log statements like this:
Log.i(TAG, MyClass.class.getSimpleName() + "#methodName" + someThing);
Is there a way to reference a method name similar to a Class's
getSimpleName()
that doesn't involve a hard coded String
?
Upvotes: 2
Views: 479
Reputation: 25950
You can use Thread.currentThread().getStackTrace()[1].getMethodName();
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
Log.i(TAG, MyClass.class.getSimpleName() + methodName + someThing);
Upvotes: 3