ZeissS
ZeissS

Reputation: 12135

Is it possible to get the stacktrace of an error in the error_logger handler?

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

Answers (2)

andi5
andi5

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

Kent
Kent

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

Related Questions