如何在没有崩溃报告的情况下优雅地终止 gen_server

How to terminate gen_server gracefully without crash report

在我的 gen_server 中,我将这样终止它:

handle_info({'EXIT', _From, _Reason}, State) ->
    {stop, partner_fled, State};

但记录器仍然将其打印为错误

14:56:43.349 [error] gen_server <0.3290.0> terminated with reason: partner_fled
14:56:43.349 [error] CRASH REPORT Process <0.3290.0> with 0 neighbours exited with reason: partner_fled in gen_server:terminate/7 line 812

代码按预期运行,但我不希望记录器打印它作为正常终止。

顺便说一句,我正在使用啤酒,但我认为删除它只会改变日志记录的格式。

来自 the manual:

Notice that for any other reason than normal, shutdown, or {shutdown,Term}, the gen_server process is assumed to terminate because of an error and an error report is issued using error_logger:format/2.

因此,如果您不想打印任何错误报告,您可以将原因更改为 normalshutdown,或者如果您确实想要 return还有自定义术语,{shutdown, Term}.

handle_info({'EXIT', _From, _Reason}, State) ->
    {stop, {shutdown, partner_fled}, State};