[erlang-questions] getting the error (after the fact) in an Erlang process?

Vans S vans_163@REDACTED
Thu Mar 2 15:43:48 CET 2017


> I did not know that the process exit message also lands there,
> a bit surprised actually. 

Apparently so, and I was surprised going into the other direction, that an OTP app 
sends the message to error_logger instead of standard output.  So far I found
a temporary hacky solution to call erlang:get_stacktrace() when I get an EXIT signal
or end up in terminate, then I print that to stdout of the process.

I don't get the nice gen_* OTP error message but at least I get the error + stacktrace.


> In production you often run the node via run_erl, which puts the system
> logs in rotating log files.  Is this what you are aiming for?
I am aiming to have the gen* OTP error messages go to the stdout of the process that
produced them, I wonder if this is at all possible?



On Thursday, March 2, 2017 3:54 AM, Raimo Niskanen <raimo+erlang-questions@REDACTED> wrote:
On Wed, Mar 01, 2017 at 09:06:47PM +0000, Vans S wrote:
> Before I was doing something like:
> 
> spawn_monitor(fun() -> {ok, F} = file:open("/hi", [write]), group_leader(F, self()) end).
> 
> Now this processes error messages after a crash out go to the hi file.
> 

That redirects all process standard output to the file e.g io:format
printouts.  I did not know that the process exit message also lands there,
a bit surprised actually.  I would have guessed such messages were printed
with error_logger, see below.


> 
> Now what I have is a [1] supervisor -> [1] gen_server, trap_exit, start_link -> [many] gen_statem
> 
> When the gen_statem changes group_leader like that to a file, the errors do not go to the file.
> 
> Is this because of how gen_*,trap_exit, and start_link work and whatnot?
> 
> Does anyone know a way to keep this relationship but also have the error+stacktrace forwarded to the
> group leader?

gen_* like like all processes adhering to OTP design principals print their
events through error_logger: http://erlang.org/doc/man/error_logger.html

This is to collect all system logs in one place.

In production you often run the node via run_erl, which puts the system
logs in rotating log files.  Is this what you are aiming for?

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list