How to always log/show the error reason when a supervisor child returns error from start_link?

StackOverflow https://stackoverflow.com/questions/4748257

Pergunta

When starting gen_server's from a supervisor (which itself is started by a application) I have the problem that when the start_link of the gen_server doesn't return {ok, ...} but {error, Reason} the only error message I see is:

=INFO REPORT==== 20-Jan-2011::13:14:43 ===
    application: foo
    exited: {shutdown,{foo_app,start,[normal,[]]}}
    type: temporary

The Reason that for terminating is not shown/logged.

Is there a way to see/log these error returns to the supervisor?

The childspec I'm using is e.g.:

{ok, {{one_for_one, 3, 10},  ... 
    {usb_mux_1, 
    {usb_mux, start_link, 
    [Some_Params]},
    permanent, 
    10000, 
    worker, 
    [usb_mux]}, ...

Edit: Clarification

I know about error_logger and using it already. The question is not how to get something logged but how to get supervisor to log the reason for it terminating, e.g. log who terminated with an error return and what did it return.

And just to get this also out of the way, yes I start erlang with sasl on:

 -boot start_sasl
Foi útil?

Solução

Just discovered the answer myself:

The supervisor is really logging the error exit as crash report.

The problem is the shell doesn't show these crash reports. Just to confuse me it shows info/warning and error reports but no progess reports and crash reports from the supervisor.

If I look in the on disk log there is a detailed crash report there:

10> rb:show(4).

CRASH REPORT  <0.53.0>                                      2011-01-20 17:33:52
===============================================================================
Crashing process                                                               
   initial_call                                  {usb_mux,init,['Argument__1']}
   pid                                                                 <0.53.0>
   registered_name                                                           []
   error_info
         {exit,{undef,[{usb_port,get_gw_hw_spec,[<0.59.0>]},
...

The reason the SASL events were not shown on the screen was a ommission in the -config file, which looked like this:

[{sasl, [
     {sasl_error_logger, false},    %% no SASL error logger installed
     {error_logger_mf_dir,"./log"}, 
     {error_logger_mf_maxbytes,10485760}, % 10 MB
     {error_logger_mf_maxfiles, 10}
     ]}].

Meaning there was a multi-file erroro logger installen (all the error_logger_mf_* entries) but no on screen logger for SASL events.

Changing the entry like this fixed it:

     {sasl_error_logger, tty},  %% SASL reports to tty

From the sasl manpage:

sasl_report_tty_h:

Formats and writes supervisor reports, crash reports and progress reports to stdio .

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top