Reputation: 12135
im currently writing an error_logger handler and would like to get the stacktrace where the error happend (more precisely: at the place, where error_logger:error*
was called). But I cannot use the erlang:get_stacktrace()
method, since i'm in a different process.
Does anyone know a way to get a stacktrace here?
Thanks
Upvotes: 3
Views: 1113
Reputation: 1616
I have not fully debugged it, but I suppose that the error functions simply send a message (fire and forget) to the error logger process, so at the time your handler is called after the message has been received, the sender might be doing something completely different. The message sent might contain the backtrace, but I highly doubt it.
Upvotes: 2
Reputation: 474
get_stacktrace() returns "stack back-trace of the last exception". Throw and catch an exception inside error_logger:error() and then you can get the stacktrace.
error() ->
try throw(a) of
_ -> a
catch
_:_ -> io:format("track is ~p~n", erlang:get_stacktrace())
end.
Upvotes: 3