java - Automatic logging in Android -


i fan of debug logs (in debug builds), , want make improvements custom logger class. ideally, create base method logs calling class name, method name, , parameter values.

for example, have application "myapplication" class "mainactivity", , calling method "foo" parameter "bar". see in logcat:

d/myapplication mainactivity foo("bar")

is there way of getting information without having pass in of these values manually? i've seen articles referring java supported methods, such java.lang.invoke.methodhandles, haven't found referring android supported methods. expect parameters have passed in, automating class name , method name excellent.

calling thread.currentthread().getstacktrace() can stacktraceelement of current thread. can call getclassname(), getmethodname() , getlinenumber() print out class, method , line of code. in code.

stacktraceelement ste = thread.currentthread().getstacktrace()[0]; string msg = ste.getclassname() + "." + ste.getmethodname() + ":" + ste.getlinenumber(); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -