chore: refactor ?SLOG
This commit is contained in:
parent
b40dbd160e
commit
ca2660d609
|
@ -292,7 +292,7 @@ handle_in(?CONNECT_PACKET(ConnPkt) = Packet, Channel) ->
|
|||
fun check_banned/2
|
||||
], ConnPkt, Channel#channel{conn_state = connecting}) of
|
||||
{ok, NConnPkt, NChannel = #channel{clientinfo = ClientInfo}} ->
|
||||
?LOG(debug, "RECV ~s", [emqx_packet:format(Packet)]),
|
||||
?SLOG(debug, #{msg => "recv_packet", packet => emqx_packet:format(Packet)}),
|
||||
NChannel1 = NChannel#channel{
|
||||
will_msg = emqx_packet:will_msg(NConnPkt),
|
||||
alias_maximum = init_alias_maximum(NConnPkt, ClientInfo)
|
||||
|
|
|
@ -138,7 +138,7 @@ init([]) ->
|
|||
{stop, Reason :: term(), Reply :: term(), NewState :: term()} |
|
||||
{stop, Reason :: term(), NewState :: term()}.
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignore, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -153,7 +153,7 @@ handle_call(Req, _From, State) ->
|
|||
{noreply, NewState :: term(), hibernate} |
|
||||
{stop, Reason :: term(), NewState :: term()}.
|
||||
handle_cast(Req, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Req}),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -168,7 +168,7 @@ handle_cast(Req, State) ->
|
|||
{noreply, NewState :: term(), hibernate} |
|
||||
{stop, Reason :: normal | term(), NewState :: term()}.
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -98,7 +98,7 @@ connect(Type, BucketName) when is_atom(BucketName) ->
|
|||
Path = [emqx_limiter, Type, bucket, BucketName],
|
||||
case emqx:get_config(Path, undefined) of
|
||||
undefined ->
|
||||
?LOG(error, "can't find the config of this bucket: ~p~n", [Path]),
|
||||
?SLOG(error, #{msg => "bucket_config_not_found", path => Path}),
|
||||
throw("bucket's config not found");
|
||||
#{zone := Zone,
|
||||
aggregated := #{rate := AggrRate, capacity := AggrSize},
|
||||
|
@ -113,7 +113,7 @@ connect(Type, BucketName) when is_atom(BucketName) ->
|
|||
emqx_htb_limiter:make_ref_limiter(Cfg, Bucket)
|
||||
end;
|
||||
undefined ->
|
||||
?LOG(error, "can't find the bucket:~p~n", [Path]),
|
||||
?SLOG(error, #{msg => "bucket_not_found", path => Path}),
|
||||
throw("invalid bucket")
|
||||
end
|
||||
end;
|
||||
|
@ -182,7 +182,7 @@ init([Type]) ->
|
|||
{stop, Reason :: term(), Reply :: term(), NewState :: term()} |
|
||||
{stop, Reason :: term(), NewState :: term()}.
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -197,7 +197,7 @@ handle_call(Req, _From, State) ->
|
|||
{noreply, NewState :: term(), hibernate} |
|
||||
{stop, Reason :: term(), NewState :: term()}.
|
||||
handle_cast(Req, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Req}),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -215,7 +215,7 @@ handle_info(oscillate, State) ->
|
|||
{noreply, oscillation(State)};
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -103,7 +103,7 @@ uninstall(Type, Name) ->
|
|||
-spec uninstall(HandlerId :: atom()) -> ok | {error, term()}.
|
||||
uninstall(HandlerId) ->
|
||||
Res = logger:remove_handler(HandlerId),
|
||||
show_prompts(Res, HandlerId, "Stop trace"),
|
||||
show_prompts(Res, HandlerId, "stop_trace"),
|
||||
Res.
|
||||
|
||||
%% @doc Return all running trace handlers information.
|
||||
|
@ -151,7 +151,7 @@ install_handler(Who = #{name := Name, type := Type}, Level, LogFile) ->
|
|||
config => ?CONFIG(LogFile)
|
||||
},
|
||||
Res = logger:add_handler(HandlerId, logger_disk_log_h, Config),
|
||||
show_prompts(Res, Who, "Start trace"),
|
||||
show_prompts(Res, Who, "start_trace"),
|
||||
Res.
|
||||
|
||||
filters(#{type := clientid, filter := Filter, name := Name}) ->
|
||||
|
@ -223,6 +223,6 @@ ensure_list(Bin) when is_binary(Bin) -> unicode:characters_to_list(Bin, utf8);
|
|||
ensure_list(List) when is_list(List) -> List.
|
||||
|
||||
show_prompts(ok, Who, Msg) ->
|
||||
?LOG(info, Msg ++ " ~p " ++ "successfully~n", [Who]);
|
||||
?SLOG(info, #{msg => "trace_action_succeeded", action => Msg, traced => Who});
|
||||
show_prompts({error, Reason}, Who, Msg) ->
|
||||
?LOG(error, Msg ++ " ~p " ++ "failed with ~p~n", [Who, Reason]).
|
||||
?SLOG(info, #{msg => "trace_action_failed", action => Msg, traced => Who, reason => Reason}).
|
||||
|
|
|
@ -310,7 +310,7 @@ group_trace_file(ZipDir, TraceLog, TraceFiles) ->
|
|||
_ -> Acc
|
||||
end;
|
||||
{error, Node, Reason} ->
|
||||
?LOG(error, "download trace log error:~p", [{Node, TraceLog, Reason}]),
|
||||
?SLOG(error, #{msg => "download_trace_log_error", node => Node, log => TraceLog, reason => Reason}),
|
||||
Acc
|
||||
end
|
||||
end, [], TraceFiles).
|
||||
|
|
|
@ -97,7 +97,7 @@ on_message_publish(Msg = #message{
|
|||
case store(#delayed_message{key = {PubAt, Id}, delayed = Delayed, msg = PubMsg}) of
|
||||
ok -> ok;
|
||||
{error, Error} ->
|
||||
?LOG(error, "Store delayed message fail: ~p", [Error])
|
||||
?SLOG(error, #{msg => "store_delayed_message_fail", error => Error})
|
||||
end,
|
||||
{stop, PubMsg#message{headers = Headers#{allow_publish => false}}};
|
||||
|
||||
|
@ -230,11 +230,11 @@ handle_call(disable, _From, State) ->
|
|||
{reply, ok, State};
|
||||
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
|
||||
{noreply, State}.
|
||||
|
||||
%% Do Publish...
|
||||
|
@ -248,7 +248,7 @@ handle_info(stats, State = #{stats_fun := StatsFun}) ->
|
|||
{noreply, State, hibernate};
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, #{timer := TRef}) ->
|
||||
|
|
|
@ -173,15 +173,15 @@ handle_call(get_telemetry, _From, State) ->
|
|||
{reply, {ok, get_telemetry(State)}, State};
|
||||
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?LOG(error, "Unexpected msg: ~p", [Msg]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
|
||||
{noreply, State}.
|
||||
|
||||
handle_continue(Continue, State) ->
|
||||
?LOG(error, "Unexpected continue: ~p", [Continue]),
|
||||
?SLOG(error, #{msg => "unexpected_continue", continue => Continue}),
|
||||
{noreply, State}.
|
||||
|
||||
handle_info({timeout, TRef, time_to_report_telemetry_data}, State = #state{timer = TRef}) ->
|
||||
|
@ -192,7 +192,7 @@ handle_info({timeout, TRef, time_to_report_telemetry_data}, State = #state{timer
|
|||
{noreply, ensure_report_timer(State)};
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
|
|
|
@ -261,7 +261,7 @@ handle_call({get_rates, Topic, Metric}, _From, State = #state{speeds = Speeds})
|
|||
end.
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(ticking, State = #state{speeds = Speeds}) ->
|
||||
|
@ -276,7 +276,7 @@ handle_info(ticking, State = #state{speeds = Speeds}) ->
|
|||
{noreply, State#state{speeds = NSpeeds}};
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
|
|
|
@ -217,11 +217,11 @@ handle_call({page_read, Topic, Page, Limit}, _, #{context := Context} = State) -
|
|||
{reply, Result, State};
|
||||
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(clear_expired, #{context := Context} = State) ->
|
||||
|
@ -248,7 +248,7 @@ handle_info(release_deliver_quota, #{context := Context, wait_quotas := Waits} =
|
|||
wait_quotas := []}};
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, #{clear_timer := TRef1, release_quota_timer := TRef2}) ->
|
||||
|
|
|
@ -91,14 +91,13 @@ store_retained(_, Msg =#message{topic = Topic}) ->
|
|||
expiry_time = ExpiryTime},
|
||||
write);
|
||||
[] ->
|
||||
?LOG(error,
|
||||
"Cannot retain message(topic=~ts) for table is full!",
|
||||
[Topic]),
|
||||
ok
|
||||
mnesia:abort(table_is_full)
|
||||
end
|
||||
end,
|
||||
{atomic, ok} = mria:transaction(?RETAINER_SHARD, Fun),
|
||||
ok
|
||||
case mria:transaction(?RETAINER_SHARD, Fun) of
|
||||
{atomic, ok} -> ok;
|
||||
{aborted, Reason} -> ?SLOG(error, #{msg => "failed_to_retain_message", topic => Topic, reason => Reason})
|
||||
end
|
||||
end.
|
||||
|
||||
clear_expired(_) ->
|
||||
|
|
|
@ -84,7 +84,7 @@ init([Pool, Id]) ->
|
|||
{stop, Reason :: term(), Reply :: term(), NewState :: term()} |
|
||||
{stop, Reason :: term(), NewState :: term()}.
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -101,12 +101,12 @@ handle_call(Req, _From, State) ->
|
|||
handle_cast({async_submit, Task}, State) ->
|
||||
try run(Task)
|
||||
catch _:Error:Stacktrace ->
|
||||
?LOG(error, "Error: ~0p, ~0p", [Error, Stacktrace])
|
||||
?SLOG(error, #{msg => "crashed_handling_async_task", exception => Error, stacktrace => Stacktrace})
|
||||
end,
|
||||
{noreply, State};
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -121,7 +121,7 @@ handle_cast(Msg, State) ->
|
|||
{noreply, NewState :: term(), hibernate} |
|
||||
{stop, Reason :: normal | term(), NewState :: term()}.
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -153,11 +153,11 @@ handle_call(clear_history, _, State) ->
|
|||
{reply, ok, State};
|
||||
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
?SLOG(error, #{msg => "unexpected_call", call => Req}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?LOG(error, "Unexpected cast: ~p", [Msg]),
|
||||
?SLOG(error, #{msg => "unexpected_cast", cast => Msg}),
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(expire_tick, State) ->
|
||||
|
@ -173,7 +173,7 @@ handle_info(notice_tick, State) ->
|
|||
{noreply, State#{last_tick_at := ?NOW}};
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?LOG(error, "Unexpected info: ~p", [Info]),
|
||||
?SLOG(error, #{msg => "unexpected_info", info => Info}),
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _) ->
|
||||
|
|
Loading…
Reference in New Issue