fix: trace throttled log events
This commit is contained in:
parent
de5e4491f7
commit
5b48b06d4a
|
@ -51,7 +51,7 @@
|
||||||
true ->
|
true ->
|
||||||
?SLOG(Level, Data, Meta);
|
?SLOG(Level, Data, Meta);
|
||||||
false ->
|
false ->
|
||||||
ok
|
?_DO_TRACE(Level, maps:get(msg, Data), maps:merge(Data, Meta))
|
||||||
end
|
end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@
|
||||||
|
|
||||||
-define(TRACE(Tag, Msg, Meta), ?TRACE(debug, Tag, Msg, Meta)).
|
-define(TRACE(Tag, Msg, Meta), ?TRACE(debug, Tag, Msg, Meta)).
|
||||||
|
|
||||||
%% Only evaluate when necessary
|
%% Internal macro
|
||||||
-define(TRACE(Level, Tag, Msg, Meta), begin
|
-define(_DO_TRACE(Tag, Msg, Meta),
|
||||||
case persistent_term:get(?TRACE_FILTER, []) of
|
case persistent_term:get(?TRACE_FILTER, []) of
|
||||||
[] -> ok;
|
[] -> ok;
|
||||||
%% We can't bind filter list to a variable because we pollute the calling scope with it.
|
%% We can't bind filter list to a variable because we pollute the calling scope with it.
|
||||||
|
@ -70,7 +70,12 @@
|
||||||
%% because this adds overhead to the happy path.
|
%% because this adds overhead to the happy path.
|
||||||
%% So evaluate `persistent_term:get` twice.
|
%% So evaluate `persistent_term:get` twice.
|
||||||
_ -> emqx_trace:log(persistent_term:get(?TRACE_FILTER, []), Msg, (Meta)#{trace_tag => Tag})
|
_ -> emqx_trace:log(persistent_term:get(?TRACE_FILTER, []), Msg, (Meta)#{trace_tag => Tag})
|
||||||
end,
|
end
|
||||||
|
).
|
||||||
|
|
||||||
|
%% Only evaluate when necessary
|
||||||
|
-define(TRACE(Level, Tag, Msg, Meta), begin
|
||||||
|
?_DO_TRACE(Tag, Msg, Meta),
|
||||||
?SLOG(
|
?SLOG(
|
||||||
Level,
|
Level,
|
||||||
(emqx_trace_formatter:format_meta_map(Meta))#{msg => Msg, tag => Tag},
|
(emqx_trace_formatter:format_meta_map(Meta))#{msg => Msg, tag => Tag},
|
||||||
|
|
|
@ -35,7 +35,9 @@ format(
|
||||||
ClientId = to_iolist(maps:get(clientid, Meta, "")),
|
ClientId = to_iolist(maps:get(clientid, Meta, "")),
|
||||||
Peername = maps:get(peername, Meta, ""),
|
Peername = maps:get(peername, Meta, ""),
|
||||||
MetaBin = format_meta(Meta, PEncode),
|
MetaBin = format_meta(Meta, PEncode),
|
||||||
[Time, " [", Tag, "] ", ClientId, "@", Peername, " msg: ", Msg, ", ", MetaBin, "\n"];
|
Msg1 = to_iolist(Msg),
|
||||||
|
Tag1 = to_iolist(Tag),
|
||||||
|
[Time, " [", Tag1, "] ", ClientId, "@", Peername, " msg: ", Msg1, ", ", MetaBin, "\n"];
|
||||||
format(Event, Config) ->
|
format(Event, Config) ->
|
||||||
emqx_logger_textfmt:format(Event, Config).
|
emqx_logger_textfmt:format(Event, Config).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue