Peter Saxton
Peter Saxton

Reputation: 4676

Printing the current line in elixir source code

In elixir we have the Pseudo-variables __MODULE__, __DIR__ et al. In erlang there is also the functionality to get the current line, using an erlang macro.

How do I get the current file line in elixir.

Something like

IO.puts __LINE__

Upvotes: 4

Views: 1523

Answers (1)

Patrick Oscity
Patrick Oscity

Reputation: 54714

It's all inside __ENV__:

IO.puts __ENV__.file
IO.puts __ENV__.line

Also see https://hexdocs.pm/elixir/Macro.Env.html

Upvotes: 6

Related Questions