erlang error_logger handler disappeared unexpectly

237 Views Asked by At

I have a mochiweb based application. I specified -kernel error_logger '{file, "mylog.log"}' while starting the application, after running for a while, error_logger won't output anything. When the application started,

sys:get_status(EPID).
{status,<0.5.0>,
        {module,gen_event},
        [[{'$ancestors',[<0.2.0>]},
          {'$initial_call',{gen_event,init_it,6}}],
         running,<0.2.0>,[],
         [{header,"Status for event handler error_logger"},
          {data,[{"Status",running},{"Parent",<0.2.0>}]},
          {items,{"Installed handlers",
                  [{handler,sasl_report_tty_h,false,all,false},
                   {handler,error_logger,false,[],false},
                   {handler,error_logger_file_h,false,
                            {<0.35.0>,"mylog.log",error_logger},
                            false}]}}]]}

And after some time,

sys:get_status(EPID).
{status,<0.5.0>,
        {module,gen_event},
        [[{'$ancestors',[<0.2.0>]},
          {'$initial_call',{gen_event,init_it,6}}],
         running,<0.2.0>,[],
         [{header,"Status for event handler error_logger"},
          {data,[{"Status",running},{"Parent",<0.2.0>}]},
          {items,{"Installed handlers",
                  [{handler,sasl_report_tty_h,false,all,false},
                   {handler,error_logger,false,[],false}]}}]]}

The error_logger_file_h is missing. Why?

1

There are 1 best solutions below

0
On

The thing to watch out for with anything based on gen_event, such as error_logger, is that if any of the callbacks causes an exception the event_handler is silently removed. One can ensure that one is notified by providing using the terminate callback or adding a supervised event_handler. None of these solutions are however available in error_logger. So using some other logging framework or rolling your own is probably the best solution if you have to rely on the handler being present.