I'm writing an application in Kotlin and would love for me to be able to log every function call without having to pass the name of the function to a log call as a string.
fun myFunction() {
log() // Would love to be able to do just this without any args
// Content of myFunction here
}
The desired behaviour is that the function log() would do something like look at the stack-trace and fetch the name of the class and/or function that it was called from. If this isn't possible then I wouldn't mind passing in some information to the log() function like this;
log(this::function) // Not possible in kotlin AFAIK
Anything more than this and it would be defeating the point (which is to minimise boilerplate code at the start of myFunction's).
If anyone could help me construct "log()" to achieve this or point me in the right direction that would be extremely helpful.
Aucun commentaire:
Enregistrer un commentaire