So i am looking for a logging library, or code sni...
# random
n
So i am looking for a logging library, or code snippet that can automatically add linenumbers to logmessages, using reflection or so is fine too does anyone know how one can manage something like that with kotlin-logging or any other logging framework ?
a
You can use logback as
kotlin-logging
backend. Proceed with https://logback.qos.ch/manual/layouts.html#conversionWord to achieve desired output (i.e.
%L
is what you want I guess). To make it even better, you can add
\(%F:%L\)
somewhere in formatted line, then you'll be able to navigate to logged line from the console.
s
you can do this with with log4j loggingevent has a locationIformation property which has lineNumber. its worth spending a few hours to digest to logging hell of java. log4j support the SLF4J so it plugs into dependencies like Koin etc easily. I played with the idea of my own simply logging library but at some point you have to face the java devil and you'll end up implementing a slf4j adapter for your own logging library anyway so its non-escpable. there's not much boilerplate to log4j - beyond basic init and only thing I've done is create a JsonLayout for stackdriver