# Auto \_\_FILE\_\_, \_\_LINE\_\_ on printlns

**URL:** <https://discuss.kotlinlang.org/t/auto-file-line-on-printlns/8678>\
**Category:** Uncategorized\
**Created:** [July 21, 2018, 12:19pm UTC](https://discuss.kotlinlang.org/t/auto-file-line-on-printlns/8678 "2018-07-21T12:19:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikt](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@ikt](https://discuss.kotlinlang.org/u/ikt)\
**Post date:** [July 21, 2018, 12:19pm UTC](https://discuss.kotlinlang.org/t/auto-file-line-on-printlns/8678/1 "2018-07-21T12:19:38Z")

</div>

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:

```auto
EXCEPTION MSG
  ... 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” ?

---

<div class="post-metadata">

**Author:** ![ikt](https://avatars.discourse-cdn.com/v4/letter/i/46a35a/32.png) [@ikt](https://discuss.kotlinlang.org/u/ikt)\
**Post date:** [July 21, 2018, 12:23pm UTC](https://discuss.kotlinlang.org/t/auto-file-line-on-printlns/8678/2 "2018-07-21T12:23:14Z")

</div>

Is there something that provides `expensive_print` and `expensive_println`

where:

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”

---

<div class="post-metadata">

**Author:** ![mibac138](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mibac138](https://discuss.kotlinlang.org/u/mibac138)\
**Post date:** [July 21, 2018, 6:02pm UTC](https://discuss.kotlinlang.org/t/auto-file-line-on-printlns/8678/3 "2018-07-21T18:02:30Z")

</div>

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
