Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logger): fix REPORT_CB/2 CRASH logs #9923

Merged
merged 1 commit into from Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/emqx/src/emqx_logger_textfmt.erl
Expand Up @@ -23,7 +23,14 @@
check_config(X) -> logger_formatter:check_config(X).

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);
format(#{msg := {string, String}} = Event, Config) ->
format(Event#{msg => {"~ts ", [String]}}, Config);
Expand All @@ -34,6 +41,11 @@ format(#{msg := Msg0, meta := Meta} = Event, Config) ->
Msg3 = enrich_topic(Msg2, Meta),
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) ->
%% 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
Expand All @@ -47,6 +59,7 @@ enrich_report(ReportRaw, Meta) ->
MFA = maps:get(mfa, Meta, undefined),
Line = maps:get(line, Meta, undefined),
Msg = maps:get(msg, ReportRaw, undefined),
%% turn it into a list so that the order of the fields is determined
lists:foldl(
fun
({_, undefined}, Acc) -> Acc;
Expand Down
1 change: 1 addition & 0 deletions changes/v5.0.17/fix-9923.en.md
@@ -0,0 +1 @@
Fix REPORT_CB/2 CRASH error logs when erros happen during boot-up or shutdown.
1 change: 1 addition & 0 deletions changes/v5.0.17/fix-9923.zh.md
@@ -0,0 +1 @@
修复在启动和关闭过程中发生错误时,日志中的 REPORT_CB/2 CRASH 错误。