refactor: avoid evaluating Data more than once in SLOG_THROTTE macro

This commit is contained in:
Serge Tupchii 2024-04-24 16:01:32 +03:00
parent 712008bc1d
commit 02a0faa1d6
1 changed files with 12 additions and 3 deletions

View File

@ -44,11 +44,20 @@
). ).
-define(SLOG_THROTTLE(Level, Data, Meta), -define(SLOG_THROTTLE(Level, Data, Meta),
case emqx_log_throttler:allow(maps:get(msg, Data)) of case logger:allow(Level, ?MODULE) of
true -> true ->
?SLOG(Level, Data, Meta); (fun(#{msg := __Msg} = __Data) ->
case emqx_log_throttler:allow(__Msg) of
true ->
logger:log(Level, __Data, Meta);
false -> false ->
?_DO_TRACE(Level, maps:get(msg, Data), maps:merge(Data, Meta)) ?_DO_TRACE(Level, __Msg, maps:merge(__Data, Meta))
end
end)(
Data
);
false ->
ok
end end
). ).