logging - Encapsulating getting the method's name in a helper method -


for debugging purposes there's part of code in want log name of method, this:

val log = logmanager.getlogger(someclass::class.java.name) //... fun somemethod() {    log.debug(thread.currentthread().getstacktrace()[1].getmethodname()) 

how can have minimal legible expression? like:

log.debug(getmethodname()) 

by way, tried using aspectj i'm using eclipse , kotlin plugin works 1.1.1. aspectj require kapt (as far know) doesn't work maven (which i'm using) 1.1.1.

you define extension function on thread gives first method on stack:

fun thread.firststackmethod() = stacktrace[1].methodname 

call then:

log.debug(thread.currentthread().firststackmethod()) 

maybe it's alternative extend logger directly:

fun logger.debugmethodname(t: thread) = debug(t.stacktrace[1].methodname) //use log.debugmethodname(thread.currentthread()) 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -