fix logger

This commit is contained in:
anlicheng 2025-05-09 21:36:01 +08:00
parent 77d3b765d7
commit d66ab5a5ca
4 changed files with 8 additions and 27 deletions

View File

@ -171,7 +171,7 @@ handle_info({connect_reply, Reply}, State = #state{status = ?STATE_CONNECTING, t
efka_transport:auth_request(TransportPid, 5000), efka_transport:auth_request(TransportPid, 5000),
{noreply, State#state{status = ?STATE_AUTH}}; {noreply, State#state{status = ?STATE_AUTH}};
{error, Reason} -> {error, Reason} ->
efka_logger:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]), lager:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]),
efka_transport:stop(TransportPid), efka_transport:stop(TransportPid),
{noreply, State#state{status = ?STATE_DENIED}} {noreply, State#state{status = ?STATE_DENIED}}
end; end;
@ -200,7 +200,7 @@ handle_info({auth_reply, Reply}, State = #state{status = ?STATE_AUTH, transport_
{noreply, State#state{status = ?STATE_RESTRICTED}}; {noreply, State#state{status = ?STATE_RESTRICTED}};
2 -> 2 ->
% %
efka_logger:debug("[efka_agent] auth failed, message: ~p", [Message]), lager:debug("[efka_agent] auth failed, message: ~p", [Message]),
efka_transport:stop(TransportPid), efka_transport:stop(TransportPid),
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}; {noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};
_ -> _ ->
@ -300,7 +300,7 @@ handle_info({server_command, ?COMMAND_AUTH, <<Auth:8>>}, State = #state{transpor
%% %%
handle_info({server_pub, Topic, Content}, State = #state{status = ?STATE_ACTIVATED}) -> handle_info({server_pub, Topic, Content}, State = #state{status = ?STATE_ACTIVATED}) ->
efka_logger:debug("[efka_agent] get pub topic: ~p, content: ~p", [Topic, Content]), lager:debug("[efka_agent] get pub topic: ~p, content: ~p", [Topic, Content]),
%% %%
efka_subscription:publish(Topic, Content), efka_subscription:publish(Topic, Content),
@ -337,7 +337,7 @@ handle_info({timeout, _, {request_timeout, Ref}}, State = #state{inflight = Infl
%% transport进程退出 %% transport进程退出
handle_info({'EXIT', TransportPid, Reason}, State = #state{transport_pid = TransportPid}) -> handle_info({'EXIT', TransportPid, Reason}, State = #state{transport_pid = TransportPid}) ->
efka_logger:debug("[efka_agent] transport pid: ~p, exit with reason: ~p", [TransportPid, Reason]), lager:debug("[efka_agent] transport pid: ~p, exit with reason: ~p", [TransportPid, Reason]),
erlang:start_timer(5000, self(), create_transport), erlang:start_timer(5000, self(), create_transport),
{noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}}; {noreply, State#state{transport_pid = undefined, status = ?STATE_DENIED}};

View File

@ -1,19 +0,0 @@
%%%-------------------------------------------------------------------
%%% @author anlicheng
%%% @copyright (C) 2025, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 29. 4 2025 22:39
%%%-------------------------------------------------------------------
-module(efka_logger).
-author("anlicheng").
%% API
-export([debug/2, notice/2]).
debug(Format, Args) ->
io:format(Format ++ "~n", Args).
notice(Format, Args) ->
io:format(Format ++ "~n", Args).

View File

@ -108,7 +108,7 @@ handle_cast({publish, Topic, Content}, State = #state{subscribers = Subscribers}
SubscriberPid ! {topic_broadcast, Topic, Content} SubscriberPid ! {topic_broadcast, Topic, Content}
end, MatchedSubscribers), end, MatchedSubscribers),
efka_logger:debug("[efka_subscription] topic: ~p, content: ~p, match subscribers: ~p", [Topic, Content, MatchedSubscribers]), lager:debug("[efka_subscription] topic: ~p, content: ~p, match subscribers: ~p", [Topic, Content, MatchedSubscribers]),
{noreply, State}. {noreply, State}.
%% @private %% @private
@ -118,12 +118,12 @@ handle_cast({publish, Topic, Content}, State = #state{subscribers = Subscribers}
{noreply, NewState :: #state{}, timeout() | hibernate} | {noreply, NewState :: #state{}, timeout() | hibernate} |
{stop, Reason :: term(), NewState :: #state{}}). {stop, Reason :: term(), NewState :: #state{}}).
handle_info({'DOWN', _Ref, process, SubscriberPid, Reason}, State = #state{subscribers = Subscribers}) -> handle_info({'DOWN', _Ref, process, SubscriberPid, Reason}, State = #state{subscribers = Subscribers}) ->
efka_logger:debug("[efka_subscription] subscriber: ~p, down with reason: ~p", [SubscriberPid, Reason]), lager:debug("[efka_subscription] subscriber: ~p, down with reason: ~p", [SubscriberPid, Reason]),
NSubscribers = lists:filter(fun(#subscriber{subscriber_pid = Pid0}) -> SubscriberPid /= Pid0 end, Subscribers), NSubscribers = lists:filter(fun(#subscriber{subscriber_pid = Pid0}) -> SubscriberPid /= Pid0 end, Subscribers),
{noreply, State#state{subscribers = NSubscribers}}; {noreply, State#state{subscribers = NSubscribers}};
handle_info(Info, State = #state{}) -> handle_info(Info, State = #state{}) ->
efka_logger:debug("[efka_subscription] get unknown info: ~p", [Info]), lager:debug("[efka_subscription] get unknown info: ~p", [Info]),
{noreply, State}. {noreply, State}.
%% @private %% @private

View File

@ -182,7 +182,7 @@ handle_info(Info, State = #state{}) ->
-spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()), -spec(terminate(Reason :: (normal | shutdown | {shutdown, term()} | term()),
State :: #state{}) -> term()). State :: #state{}) -> term()).
terminate(Reason, #state{}) -> terminate(Reason, #state{}) ->
efka_logger:notice("[efka_transport] terminate with reason: ~p", [Reason]), lager:notice("[efka_transport] terminate with reason: ~p", [Reason]),
ok. ok.
%% @private %% @private