Hello, sometime recently i believe i came across a...
# android
t
Hello, sometime recently i believe i came across a library which had a logging feature where instead of using
Log.d(TAG, "something")
, you could just do
d { "something" }
and the logger would automatically figure out what class and method its in. Does anyone either happen to know this library or know how i could implement that myself?
c
Not sure on the library, but you could implement yourself with something like...
Copy code
fun d(logBlock: () -> Unit) { logBlock() }
🤔 actually probably more like this
Copy code
fun d(logBlock: () -> String) { 
    val logStatement = logBlock()
    Log.d(..., logStatement)
}
t
thats awesome! thank you, that is definitely better than what i have. ill try to find a way to reliably get at least the class name
do i call
toString()
on the
logStatement
?
j
You can take a look to my library to get some ideas: https://github.com/JavierSegoviaCordoba/KotlinLogger
it is working fine in intellij, I have to create the android version, but at least it does what you are searching
image.png
t
@Javier awesome thank you :))
c
@Tim -- since the output of the function being passed in is a string you just need to invoke it. @Javier -- this looks nice, I've been looking for a logger for a ktor project I've been working on and I think I may have just found it 🙂
j
@Cody Engel I have to add support to native, now only JVM, I don't know if you need native too
c
I'm using ktor for a backend project so native doesn't matter, i spend a lot of time looking at logs though so having them look nicer would be a big win
👍 1
d
Please remember to add “inline” modifier . As {} will be translated into Function0 ,which will delay your app.