qwerescape

qwerescape

How to get the call stack/stack trace at any point in code?

Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the code got to that point. It will be super helpful to learn how some of the frameworks/libraries work that way.

Marked As Solved

sasajuric

sasajuric

Author of Elixir In Action

Process.info(self(), :current_stacktrace)

33
Post #4

Also Liked

nardopessoa

nardopessoa

In my case, I do this:

defmodule Foo do
  require Logger

  defp log_this do
    stacktrace = Process.info(self(), :current_stacktrace) |> elem(1)
    Logger.warn "IMEDIATE CALLER: #{stacktrace |> Enum.at(2) |> Exception.format_stacktrace_entry}"
    Logger.warn "    NEXT CALLER: #{stacktrace |> Enum.at(3) |> Exception.format_stacktrace_entry}"
    "do something"
  end

  def do_something do
    log_this()
    "do something"
  end
  def execute_something do
    do_something()
    "execute_something"
  end
end
iex(1)> Foo.execute_something
10:24:16.528 [warn]  IMEDIATE CALLER: .iex.exs:12: Foo.do_something/0
10:24:16.529 [warn]      NEXT CALLER: .iex.exs:16: Foo.execute_something/0
"execute_something"
gon782

gon782

You could use :erlang.get_stacktrace/0.

Where Next?

Popular in Questions Top

tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement