File and Line Number for IO.inspect

I’d like to extend IO.inspect to also emit the file and line number of the statement.

I had this in Ruby and found it to be super helpful.

Would there be any way in Elixir to write a function or macro that could introspect, maybe at compile time, to capture the file and line number?

2 Likes

In general this is accessible from the __ENV__ struct, there are fields for various things like file, line, current function, module, etc. Inside macros the __CALLER__ macro returns similar information for the place where the macro was called.

2 Likes

Many thanks for this tip!