fix(logger): fix REPORT_CB/2 CRASH logs
This commit is contained in:
parent
3587c4c04a
commit
4653ca65f7
|
@ -23,7 +23,14 @@
|
||||||
check_config(X) -> logger_formatter:check_config(X).
|
check_config(X) -> logger_formatter:check_config(X).
|
||||||
|
|
||||||
format(#{msg := {report, ReportMap}, meta := Meta} = Event, Config) when is_map(ReportMap) ->
|
format(#{msg := {report, ReportMap}, meta := Meta} = Event, Config) when is_map(ReportMap) ->
|
||||||
Report = enrich_report(ReportMap, Meta),
|
ReportList = enrich_report(ReportMap, Meta),
|
||||||
|
Report =
|
||||||
|
case is_list_report_acceptable(Meta) of
|
||||||
|
true ->
|
||||||
|
ReportList;
|
||||||
|
false ->
|
||||||
|
maps:from_list(ReportList)
|
||||||
|
end,
|
||||||
logger_formatter:format(Event#{msg := {report, Report}}, Config);
|
logger_formatter:format(Event#{msg := {report, Report}}, Config);
|
||||||
format(#{msg := {string, String}} = Event, Config) ->
|
format(#{msg := {string, String}} = Event, Config) ->
|
||||||
format(Event#{msg => {"~ts ", [String]}}, Config);
|
format(Event#{msg => {"~ts ", [String]}}, Config);
|
||||||
|
@ -34,6 +41,11 @@ format(#{msg := Msg0, meta := Meta} = Event, Config) ->
|
||||||
Msg3 = enrich_topic(Msg2, Meta),
|
Msg3 = enrich_topic(Msg2, Meta),
|
||||||
logger_formatter:format(Event#{msg := Msg3}, Config).
|
logger_formatter:format(Event#{msg := Msg3}, Config).
|
||||||
|
|
||||||
|
is_list_report_acceptable(#{report_cb := Cb}) ->
|
||||||
|
Cb =:= fun logger:format_otp_report/1 orelse Cb =:= fun logger:format_report/1;
|
||||||
|
is_list_report_acceptable(_) ->
|
||||||
|
false.
|
||||||
|
|
||||||
enrich_report(ReportRaw, Meta) ->
|
enrich_report(ReportRaw, Meta) ->
|
||||||
%% clientid and peername always in emqx_conn's process metadata.
|
%% clientid and peername always in emqx_conn's process metadata.
|
||||||
%% topic can be put in meta using ?SLOG/3, or put in msg's report by ?SLOG/2
|
%% topic can be put in meta using ?SLOG/3, or put in msg's report by ?SLOG/2
|
||||||
|
@ -47,6 +59,7 @@ enrich_report(ReportRaw, Meta) ->
|
||||||
MFA = maps:get(mfa, Meta, undefined),
|
MFA = maps:get(mfa, Meta, undefined),
|
||||||
Line = maps:get(line, Meta, undefined),
|
Line = maps:get(line, Meta, undefined),
|
||||||
Msg = maps:get(msg, ReportRaw, undefined),
|
Msg = maps:get(msg, ReportRaw, undefined),
|
||||||
|
%% turn it into a list so that the order of the fields is determined
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun
|
fun
|
||||||
({_, undefined}, Acc) -> Acc;
|
({_, undefined}, Acc) -> Acc;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix REPORT_CB/2 CRASH error logs when erros happen during boot-up or shutdown.
|
|
@ -0,0 +1 @@
|
||||||
|
修复在启动和关闭过程中发生错误时,日志中的 REPORT_CB/2 CRASH 错误。
|
Loading…
Reference in New Issue