views:

69

answers:

2

Hi,

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

+1  A: 

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.
Kent
Did you read the question?
Zed
Some problems with this approach: a) There might not be a real exception, just a call to error() b) I cannot modify the `error()` function, since its part of the stdlib c) I'm in a different process, so I cannot call `get_stacktrace()`
ZeissS
Sorry. I misunderstood the question.
Kent
A: 

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.

No, it doesn't contain it. It believe, there is no way to get that info, too. Just asking to get sure. :(
ZeissS