Auto __FILE__, __LINE__ on printlns

  1. I realize what I am asking is probably impossible. Thus, feel free to rephrase the question as “what is the closest we can get to this.”

  2. I am using IntelliJ IDEA. Thus question assumes the developer is using IntelliJ IDEA.

  3. Any time we throw an exception in Kotlin/IDEA, the console has a nice display of:

  ... some class info .... (file_name: line_number)
  ... some class info .... (file_name: line_number)
  ... some class info .... (file_name: line_number)
  ... some class info .... (file_name: line_number)

then, if I click on any of the (file_name: line_number), IDEA jumps to the right file_name / line_number.

  1. What I want / my actual question:

I want the above for regular console output (i.e. via println/prin).

I want to scroll in the IDEA console, right click on a piece of console output, and have the option of “jump to the file name / line number that generated this output.”

I realize there is an extra overhead here – where, for each char of output, we have to store a (file name / line number) pair – but I am willing to pay that price.

Question: What is the closest we can get to the above? To be able to click on a piece of output and ask “where was this generated” ?

Is there something that provides expensive_print and expensive_println


  1. it outputs the corresponding string like print/println
  2. it also attaches the ENTIRE STACK FRAMES , thus the name “expensive”

This would be helpful, as I often end up asking “what is generating this / why is this being generated”

You could just create a exception yourself and check it like so val trace = Exception().stackTrace[0] where 0 is the frame distance from current frame (i.e. 0 means this function, 1 means the function that called this function, and so on). Then you could just print that like this println(trace). I did not test it but it should work