0

I want to write a simple helper logging function in kotlin-js, like so:

inline fun log(block: () -> String){
    kotlin.js.console.log("[LOG] ${block()}")
}

But when using it like log{ "Processing..." }, the console still prints the line where the function log body is defined, not where it is called (which inlining should be doing).

Any ways to achieve the proper line output?

er453r
  • 211
  • 2
  • 11
  • just wonder why you need log as a callback? – shabunc Sep 10 '20 at 13:17
  • @shabunc that is how most kotlin loggers work (that allows not running logger logic when changing log levels) - but we can also assume it is a simple argument/function call - both ways produce the same problem – er453r Sep 10 '20 at 13:25
  • ok, I see, so next thing I want to ask is what version of compiler are you using and the rest of setup, like are you using source maps, what module kind is set for compilation etc. I've checked on my side and everything is inlined, as well as line numbers are preserved in console. – shabunc Sep 10 '20 at 13:29
  • @shabunc I'm using 1.4.0 with a browser webpack build with sourcemaps (to clarify - i want to see the correct Kotlin line number, not transpiled JS line number) - tired both old and the new IR compiler (but the IR currently does not support source maps) – er453r Sep 10 '20 at 13:39

0 Answers0