From 4306b94bf08aeadd83003fe7188b0f7fd74cbf59 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Mon, 25 Dec 2023 15:53:51 +0800 Subject: [PATCH] fix logger --- apps/iot/src/consumer/iot_zd_consumer.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/iot/src/consumer/iot_zd_consumer.erl b/apps/iot/src/consumer/iot_zd_consumer.erl index 4f8e58c..ce701dd 100644 --- a/apps/iot/src/consumer/iot_zd_consumer.erl +++ b/apps/iot/src/consumer/iot_zd_consumer.erl @@ -154,6 +154,12 @@ handle_info({'EXIT', ConnPid, Reason}, State = #state{conn_pid = ConnPid}) -> {noreply, State#state{conn_pid = undefined}}; +handle_info({'EXIT', LoggerPid, Reason}, State = #state{logger_pid = LoggerPid}) -> + lager:warning("[iot_zd_consumer] logger exited with reason: ~p", [Reason]), + {ok, LoggerPid} = iot_logger:start_link("zd_directive_data"), + + {noreply, State#state{logger_pid = LoggerPid}}; + handle_info({directive_reply, Reply}, State = #state{logger_pid = LoggerPid, flight_num = FlightNum}) -> FlightInfo = <<"flight_num: ", (integer_to_binary(FlightNum - 1))/binary>>, case Reply of @@ -170,8 +176,7 @@ handle_info({directive_reply, Reply}, State = #state{logger_pid = LoggerPid, fli true -> <<"Unknow error">> end, iot_logger:write(LoggerPid, [<<"[error]">>, RawReq, Reason, FlightInfo]) - end, - iot_logger:write(LoggerPid, [<<"[success]">>, RawReq, DirectiveResult, FlightInfo]); + end; {error, RawReq, Error} when is_binary(Error) -> iot_logger:write(LoggerPid, [<<"[error]">>, RawReq, Error, FlightInfo]) end,