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

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Mar 2 09:53:45 CET 2017


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



More information about the erlang-questions mailing list