refactor: delete deprecated logging macros
This commit is contained in:
parent
586ecaf031
commit
1718360156
|
@ -17,46 +17,6 @@
|
||||||
-ifndef(EMQX_LOGGER_HRL).
|
-ifndef(EMQX_LOGGER_HRL).
|
||||||
-define(EMQX_LOGGER_HRL, true).
|
-define(EMQX_LOGGER_HRL, true).
|
||||||
|
|
||||||
%% debug | info | notice | warning | error | critical | alert | emergency
|
|
||||||
-define(DEBUG(Format), ?LOG(debug, Format, [])).
|
|
||||||
-define(DEBUG(Format, Args), ?LOG(debug, Format, Args)).
|
|
||||||
|
|
||||||
-define(INFO(Format), ?LOG(info, Format, [])).
|
|
||||||
-define(INFO(Format, Args), ?LOG(info, Format, Args)).
|
|
||||||
|
|
||||||
-define(NOTICE(Format), ?LOG(notice, Format, [])).
|
|
||||||
-define(NOTICE(Format, Args), ?LOG(notice, Format, Args)).
|
|
||||||
|
|
||||||
-define(WARN(Format), ?LOG(warning, Format, [])).
|
|
||||||
-define(WARN(Format, Args), ?LOG(warning, Format, Args)).
|
|
||||||
|
|
||||||
-define(ERROR(Format), ?LOG(error, Format, [])).
|
|
||||||
-define(ERROR(Format, Args), ?LOG(error, Format, Args)).
|
|
||||||
|
|
||||||
-define(CRITICAL(Format), ?LOG(critical, Format, [])).
|
|
||||||
-define(CRITICAL(Format, Args), ?LOG(critical, Format, Args)).
|
|
||||||
|
|
||||||
-define(ALERT(Format), ?LOG(alert, Format, [])).
|
|
||||||
-define(ALERT(Format, Args), ?LOG(alert, Format, Args)).
|
|
||||||
|
|
||||||
-define(LOG(Level, Format), ?LOG(Level, Format, [])).
|
|
||||||
|
|
||||||
%% deprecated
|
|
||||||
-define(LOG(Level, Format, Args, Meta),
|
|
||||||
%% check 'allow' here so we do not have to pass an anonymous function
|
|
||||||
%% down to logger which may cause `badfun` exception during upgrade
|
|
||||||
case logger:allow(Level, ?MODULE) of
|
|
||||||
true ->
|
|
||||||
logger:log(Level, (Format), (Args),
|
|
||||||
(Meta)#{ mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY}
|
|
||||||
, line => ?LINE
|
|
||||||
});
|
|
||||||
false ->
|
|
||||||
ok
|
|
||||||
end).
|
|
||||||
|
|
||||||
-define(LOG(Level, Format, Args), ?LOG(Level, Format, Args, #{})).
|
|
||||||
|
|
||||||
%% structured logging
|
%% structured logging
|
||||||
-define(SLOG(Level, Data),
|
-define(SLOG(Level, Data),
|
||||||
?SLOG(Level, Data, #{})).
|
?SLOG(Level, Data, #{})).
|
||||||
|
|
|
@ -105,7 +105,10 @@ run_command(Cmd, Args) when is_atom(Cmd) ->
|
||||||
_ -> ok
|
_ -> ok
|
||||||
catch
|
catch
|
||||||
_:Reason:Stacktrace ->
|
_:Reason:Stacktrace ->
|
||||||
?ERROR("CMD Error:~0p, Stacktrace:~0p", [Reason, Stacktrace]),
|
?SLOG(error, #{msg => "ctl_command_crashed",
|
||||||
|
stacktrace => Stacktrace,
|
||||||
|
reason => Reason
|
||||||
|
}),
|
||||||
{error, Reason}
|
{error, Reason}
|
||||||
end;
|
end;
|
||||||
[] ->
|
[] ->
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2022 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
%% you may not use this file except in compliance with the License.
|
||||||
|
%% You may obtain a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing, software
|
||||||
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
%% See the License for the specific language governing permissions and
|
||||||
|
%% limitations under the License.
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
|
%% @doc HOCON schema help module
|
||||||
|
-module(emqx_hocon).
|
||||||
|
|
||||||
|
-export([format_path/1]).
|
||||||
|
|
||||||
|
format_path([]) -> "";
|
||||||
|
format_path([Name]) -> iol(Name);
|
||||||
|
format_path([Name | Rest]) ->
|
||||||
|
[iol(Name) , "." | format_path(Rest)].
|
||||||
|
|
||||||
|
%% Ensure iolist()
|
||||||
|
iol(B) when is_binary(B) -> B;
|
||||||
|
iol(A) when is_atom(A) -> atom_to_binary(A, utf8);
|
||||||
|
iol(L) when is_list(L) -> L.
|
|
@ -245,7 +245,8 @@ handle_timeout(_TRef, force_close, Channel = #channel{closed_reason = Reason}) -
|
||||||
{shutdown, {error, {force_close, Reason}}, Channel};
|
{shutdown, {error, {force_close, Reason}}, Channel};
|
||||||
|
|
||||||
handle_timeout(_TRef, Msg, Channel) ->
|
handle_timeout(_TRef, Msg, Channel) ->
|
||||||
?WARN("Unexpected timeout: ~p", [Msg]),
|
?SLOG(warning, #{msg => "unexpected_timeout_signal",
|
||||||
|
signal => Msg}),
|
||||||
{ok, Channel}.
|
{ok, Channel}.
|
||||||
|
|
||||||
-spec handle_call(Req :: any(), From :: any(), channel())
|
-spec handle_call(Req :: any(), From :: any(), channel())
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
|
|
||||||
-define(DEF_MAX_PAYLOAD_SIZE, (1024 * 1024)).
|
-define(DEF_MAX_PAYLOAD_SIZE, (1024 * 1024)).
|
||||||
-define(DEF_EXPIRY_INTERVAL, 0).
|
-define(DEF_EXPIRY_INTERVAL, 0).
|
||||||
|
-define(MAX_PAYLOAD_SIZE_CONFIG_PATH, [retainer, max_payload_size]).
|
||||||
|
|
||||||
-define(CAST(Msg), gen_server:cast(?MODULE, Msg)).
|
-define(CAST(Msg), gen_server:cast(?MODULE, Msg)).
|
||||||
|
|
||||||
|
@ -293,9 +294,9 @@ new_state() ->
|
||||||
new_context(Id) ->
|
new_context(Id) ->
|
||||||
#{context_id => Id}.
|
#{context_id => Id}.
|
||||||
|
|
||||||
is_too_big(Size) ->
|
|
||||||
Limit = emqx_conf:get([retainer, max_payload_size], ?DEF_MAX_PAYLOAD_SIZE),
|
payload_size_limit() ->
|
||||||
Limit > 0 andalso (Size > Limit).
|
emqx_conf:get(?MAX_PAYLOAD_SIZE_CONFIG_PATH, ?DEF_MAX_PAYLOAD_SIZE).
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
dispatch(Context, Topic) ->
|
dispatch(Context, Topic) ->
|
||||||
|
@ -309,13 +310,17 @@ delete_message(Context, Topic) ->
|
||||||
|
|
||||||
-spec store_retained(context(), message()) -> ok.
|
-spec store_retained(context(), message()) -> ok.
|
||||||
store_retained(Context, #message{topic = Topic, payload = Payload} = Msg) ->
|
store_retained(Context, #message{topic = Topic, payload = Payload} = Msg) ->
|
||||||
case is_too_big(erlang:byte_size(Payload)) of
|
Size = iolist_size(Payload),
|
||||||
false ->
|
case payload_size_limit() of
|
||||||
Mod = get_backend_module(),
|
Limit when Limit > 0 andalso Limit < Size ->
|
||||||
Mod:store_retained(Context, Msg);
|
?SLOG(error, #{msg => "retain_failed_for_payload_size_exceeded_limit",
|
||||||
|
topic => Topic,
|
||||||
|
config => emqx_hocon:format_path(?MAX_PAYLOAD_SIZE_CONFIG_PATH),
|
||||||
|
size => Size,
|
||||||
|
limit => Limit});
|
||||||
_ ->
|
_ ->
|
||||||
?ERROR("Cannot retain message(topic=~ts, payload_size=~p) for payload is too big!",
|
Mod = get_backend_module(),
|
||||||
[Topic, iolist_size(Payload)])
|
Mod:store_retained(Context, Msg)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec clean(context()) -> ok.
|
-spec clean(context()) -> ok.
|
||||||
|
|
Loading…
Reference in New Issue