Merge pull request #12590 from zmstone/0226-remove-mfa-from-logs
refactor: delete mfa from log metadata
This commit is contained in:
commit
bb6a95bae8
|
@ -30,10 +30,7 @@
|
|||
logger:log(
|
||||
Level,
|
||||
(Data),
|
||||
(Meta#{
|
||||
mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY},
|
||||
line => ?LINE
|
||||
})
|
||||
Meta
|
||||
);
|
||||
false ->
|
||||
ok
|
||||
|
|
|
@ -272,7 +272,6 @@ json_obj_root(Data0, Config) ->
|
|||
_ ->
|
||||
json(Msg1, Config)
|
||||
end,
|
||||
Mfal = emqx_utils:format_mfal(Data0),
|
||||
Data =
|
||||
maps:fold(
|
||||
fun(K, V, D) ->
|
||||
|
@ -281,12 +280,12 @@ json_obj_root(Data0, Config) ->
|
|||
end,
|
||||
[],
|
||||
maps:without(
|
||||
[time, gl, file, report_cb, msg, '$kind', mfa, level, line, is_trace], Data0
|
||||
[time, gl, file, report_cb, msg, '$kind', level, is_trace], Data0
|
||||
)
|
||||
),
|
||||
lists:filter(
|
||||
fun({_, V}) -> V =/= undefined end,
|
||||
[{time, Time}, {level, Level}, {msg, Msg}, {mfa, Mfal}]
|
||||
[{time, Time}, {level, Level}, {msg, Msg}]
|
||||
) ++ Data.
|
||||
|
||||
json_obj(Data, Config) ->
|
||||
|
|
|
@ -37,9 +37,8 @@ format(#{msg := {string, String}} = Event, Config) ->
|
|||
%% trace
|
||||
format(#{msg := Msg0, meta := Meta} = Event, Config) ->
|
||||
Msg1 = enrich_client_info(Msg0, Meta),
|
||||
Msg2 = enrich_mfa(Msg1, Meta),
|
||||
Msg3 = enrich_topic(Msg2, Meta),
|
||||
logger_formatter:format(Event#{msg := Msg3}, Config).
|
||||
Msg2 = enrich_topic(Msg1, Meta),
|
||||
logger_formatter:format(Event#{msg := Msg2}, Config).
|
||||
|
||||
is_list_report_acceptable(#{report_cb := Cb}) ->
|
||||
Cb =:= fun logger:format_otp_report/1 orelse Cb =:= fun logger:format_report/1;
|
||||
|
@ -61,7 +60,6 @@ enrich_report(ReportRaw, Meta) ->
|
|||
end,
|
||||
ClientId = maps:get(clientid, Meta, undefined),
|
||||
Peer = maps:get(peername, Meta, undefined),
|
||||
MFA = emqx_utils:format_mfal(Meta),
|
||||
Msg = maps:get(msg, ReportRaw, undefined),
|
||||
%% turn it into a list so that the order of the fields is determined
|
||||
lists:foldl(
|
||||
|
@ -75,7 +73,6 @@ enrich_report(ReportRaw, Meta) ->
|
|||
{topic, try_format_unicode(Topic)},
|
||||
{clientid, try_format_unicode(ClientId)},
|
||||
{peername, Peer},
|
||||
{mfa, try_format_unicode(MFA)},
|
||||
{msg, Msg}
|
||||
]
|
||||
).
|
||||
|
@ -99,11 +96,6 @@ try_format_unicode(Char) ->
|
|||
_ -> List
|
||||
end.
|
||||
|
||||
enrich_mfa({Fmt, Args}, Data) when is_list(Fmt) ->
|
||||
{Fmt ++ " mfa: ~ts", Args ++ [emqx_utils:format_mfal(Data)]};
|
||||
enrich_mfa(Msg, _) ->
|
||||
Msg.
|
||||
|
||||
enrich_client_info({Fmt, Args}, #{clientid := ClientId, peername := Peer}) when is_list(Fmt) ->
|
||||
{" ~ts@~ts " ++ Fmt, [ClientId, Peer | Args]};
|
||||
enrich_client_info({Fmt, Args}, #{clientid := ClientId}) when is_list(Fmt) ->
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
flattermap/2,
|
||||
tcp_keepalive_opts/4,
|
||||
format/1,
|
||||
format_mfal/1,
|
||||
call_first_defined/1,
|
||||
ntoa/1
|
||||
]).
|
||||
|
@ -553,30 +552,6 @@ tcp_keepalive_opts(OS, _Idle, _Interval, _Probes) ->
|
|||
format(Term) ->
|
||||
iolist_to_binary(io_lib:format("~0p", [Term])).
|
||||
|
||||
%% @doc Helper function for log formatters.
|
||||
-spec format_mfal(map()) -> undefined | binary().
|
||||
format_mfal(Data) ->
|
||||
Line =
|
||||
case maps:get(line, Data, undefined) of
|
||||
undefined ->
|
||||
<<"">>;
|
||||
Num ->
|
||||
["(", integer_to_list(Num), ")"]
|
||||
end,
|
||||
case maps:get(mfa, Data, undefined) of
|
||||
{M, F, A} ->
|
||||
iolist_to_binary([
|
||||
atom_to_binary(M, utf8),
|
||||
$:,
|
||||
atom_to_binary(F, utf8),
|
||||
$/,
|
||||
integer_to_binary(A),
|
||||
Line
|
||||
]);
|
||||
_ ->
|
||||
undefined
|
||||
end.
|
||||
|
||||
-spec call_first_defined(list({module(), atom(), list()})) -> term() | no_return().
|
||||
call_first_defined([{Module, Function, Args} | Rest]) ->
|
||||
try
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Removed `mfa` meta data from log messages to improve clarity.
|
Loading…
Reference in New Issue