Merge pull request #12927 from SergeTupchiy/refactor-slog_throttle-macro

refactor: avoid evaluating Data more than once in SLOG_THROTTE macro
This commit is contained in:
SergeTupchiy 2024-04-24 19:14:32 +03:00 committed by GitHub
commit 7fb309c429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 3 deletions

View File

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