移除对lager的依赖
This commit is contained in:
parent
0ac66fedee
commit
2d10d37481
@ -162,7 +162,7 @@ do_register(RegisterName, Socket) ->
|
|||||||
receive
|
receive
|
||||||
{tcp, Socket, Data} ->
|
{tcp, Socket, Data} ->
|
||||||
RegisterPacket = unpack(Data),
|
RegisterPacket = unpack(Data),
|
||||||
lager:debug("[efka_client] get register reply packet: ~p", [RegisterPacket]),
|
logger:debug("[efka_client] get register reply packet: ~p", [RegisterPacket]),
|
||||||
case RegisterPacket of
|
case RegisterPacket of
|
||||||
#efka_packet{packet_id = PacketId, type = ?PACKET_TYPE_RESPONSE, message = #{<<"c">> := 1, <<"r">> := <<"ok">>}} ->
|
#efka_packet{packet_id = PacketId, type = ?PACKET_TYPE_RESPONSE, message = #{<<"c">> := 1, <<"r">> := <<"ok">>}} ->
|
||||||
ok;
|
ok;
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
[
|
[
|
||||||
jiffy,
|
jiffy,
|
||||||
emqtt,
|
emqtt,
|
||||||
lager,
|
|
||||||
kernel,
|
kernel,
|
||||||
stdlib
|
stdlib
|
||||||
]},
|
]},
|
||||||
|
|||||||
@ -69,13 +69,13 @@ init([]) ->
|
|||||||
{ok, Metrics} = efka_client:request_metric(),
|
{ok, Metrics} = efka_client:request_metric(),
|
||||||
try convert_metric(Metrics) of
|
try convert_metric(Metrics) of
|
||||||
{ok, MetricMap} ->
|
{ok, MetricMap} ->
|
||||||
lager:debug("[light_args] init load metric_map: ~p", [MetricMap]),
|
logger:debug("[light_args] init load metric_map: ~p", [MetricMap]),
|
||||||
{ok, Param} = efka_client:request_param(),
|
{ok, Param} = efka_client:request_param(),
|
||||||
|
|
||||||
{ok, #state{metrics = MetricMap, param = Param}}
|
{ok, #state{metrics = MetricMap, param = Param}}
|
||||||
catch
|
catch
|
||||||
_:Error:Stack->
|
_:Error:Stack->
|
||||||
lager:warning("[light_args] request_metric get error: ~p, stack: ~p", [Error, Stack]),
|
logger:warning("[light_args] request_metric get error: ~p, stack: ~p", [Error, Stack]),
|
||||||
{ok, #state{metrics = #{}, param = #{}}}
|
{ok, #state{metrics = #{}, param = #{}}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ handle_cast({push_param, Param}, State = #state{}) ->
|
|||||||
handle_cast({push_metric, Metrics}, State = #state{}) ->
|
handle_cast({push_metric, Metrics}, State = #state{}) ->
|
||||||
try convert_metric(Metrics) of
|
try convert_metric(Metrics) of
|
||||||
{ok, MetricMap} ->
|
{ok, MetricMap} ->
|
||||||
lager:debug("[light_args] push metric_map: ~p", [MetricMap]),
|
logger:debug("[light_args] push metric_map: ~p", [MetricMap]),
|
||||||
{noreply, State#state{metrics = MetricMap}}
|
{noreply, State#state{metrics = MetricMap}}
|
||||||
catch _:_ ->
|
catch _:_ ->
|
||||||
{noreply, State}
|
{noreply, State}
|
||||||
|
|||||||
@ -106,10 +106,10 @@ handle_cast({metric_data, Message}, State = #state{device_uuid = DeviceUUID, dat
|
|||||||
|
|
||||||
{noreply, State#state{data_counter = DataCounter + 1, status = 1}};
|
{noreply, State#state{data_counter = DataCounter + 1, status = 1}};
|
||||||
M when is_map(M) ->
|
M when is_map(M) ->
|
||||||
lager:notice("[light_device] invalid map: ~p", [M]),
|
logger:notice("[light_device] invalid map: ~p", [M]),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
Error ->
|
Error ->
|
||||||
lager:notice("[light_device] jiffy decode error: ~p", [Error]),
|
logger:notice("[light_device] jiffy decode error: ~p", [Error]),
|
||||||
{noreply, State}
|
{noreply, State}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
@ -51,23 +51,23 @@ start_link() ->
|
|||||||
init([]) ->
|
init([]) ->
|
||||||
%% 建立到emqx服务器的连接
|
%% 建立到emqx服务器的连接
|
||||||
Opts = emqx_opts(<<"light-subscriber">>),
|
Opts = emqx_opts(<<"light-subscriber">>),
|
||||||
lager:debug("[opts] is: ~p", [Opts]),
|
logger:debug("[opts] is: ~p", [Opts]),
|
||||||
case emqtt:start_link(Opts) of
|
case emqtt:start_link(Opts) of
|
||||||
{ok, ConnPid} ->
|
{ok, ConnPid} ->
|
||||||
lager:debug("[mqtt_subscriber] start conntecting, pid: ~p", [ConnPid]),
|
logger:debug("[mqtt_subscriber] start conntecting, pid: ~p", [ConnPid]),
|
||||||
{ok, _} = emqtt:connect(ConnPid),
|
{ok, _} = emqtt:connect(ConnPid),
|
||||||
lager:debug("[mqtt_subscriber] connect success"),
|
logger:debug("[mqtt_subscriber] connect success"),
|
||||||
|
|
||||||
%% 监听和设备的全部事件
|
%% 监听和设备的全部事件
|
||||||
SubscribeResult = emqtt:subscribe(ConnPid, ?Topics),
|
SubscribeResult = emqtt:subscribe(ConnPid, ?Topics),
|
||||||
lager:debug("[mqtt_subscriber] subscribe topics: ~p, result is: ~p", [?Topics, SubscribeResult]),
|
logger:debug("[mqtt_subscriber] subscribe topics: ~p, result is: ~p", [?Topics, SubscribeResult]),
|
||||||
|
|
||||||
{ok, #state{conn_pid = ConnPid}};
|
{ok, #state{conn_pid = ConnPid}};
|
||||||
ignore ->
|
ignore ->
|
||||||
lager:debug("[mqtt_subscriber] connect emqx get ignore"),
|
logger:debug("[mqtt_subscriber] connect emqx get ignore"),
|
||||||
{stop, ignore};
|
{stop, ignore};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:debug("[mqtt_subscriber] connect emqx get error: ~p", [Reason]),
|
logger:debug("[mqtt_subscriber] connect emqx get error: ~p", [Reason]),
|
||||||
{stop, Reason}
|
{stop, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -100,11 +100,11 @@ handle_cast(_Request, State = #state{}) ->
|
|||||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_info({disconnect, ReasonCode, Properties}, State = #state{}) ->
|
handle_info({disconnect, ReasonCode, Properties}, State = #state{}) ->
|
||||||
lager:debug("[mqtt_subscriber] Recv a DISONNECT packet - ReasonCode: ~p, Properties: ~p", [ReasonCode, Properties]),
|
logger:debug("[mqtt_subscriber] Recv a DISONNECT packet - ReasonCode: ~p, Properties: ~p", [ReasonCode, Properties]),
|
||||||
{stop, disconnected, State};
|
{stop, disconnected, State};
|
||||||
%% 必须要做到消息的快速分发,数据的json反序列需要在host进程进行
|
%% 必须要做到消息的快速分发,数据的json反序列需要在host进程进行
|
||||||
handle_info({publish, #{packet_id := _PacketId, payload := Payload, qos := Qos, topic := Topic}}, State = #state{conn_pid = _ConnPid}) ->
|
handle_info({publish, #{packet_id := _PacketId, payload := Payload, qos := Qos, topic := Topic}}, State = #state{conn_pid = _ConnPid}) ->
|
||||||
lager:debug("[mqtt_subscriber] Recv a topic: ~p, publish packet: ~p, qos: ~p", [Topic, Payload, Qos]),
|
logger:debug("[mqtt_subscriber] Recv a topic: ~p, publish packet: ~p, qos: ~p", [Topic, Payload, Qos]),
|
||||||
%% 将消息分发到对应的publisher进程去处理, 提高消息的处理速度; topic格式: /lighting/C0AA213BD7F0/data
|
%% 将消息分发到对应的publisher进程去处理, 提高消息的处理速度; topic格式: /lighting/C0AA213BD7F0/data
|
||||||
case Topic of
|
case Topic of
|
||||||
<<"/lighting/", DeviceInfo/binary>> ->
|
<<"/lighting/", DeviceInfo/binary>> ->
|
||||||
@ -115,11 +115,11 @@ handle_info({publish, #{packet_id := _PacketId, payload := Payload, qos := Qos,
|
|||||||
end,
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({puback, Packet = #{packet_id := _PacketId}}, State = #state{}) ->
|
handle_info({puback, Packet = #{packet_id := _PacketId}}, State = #state{}) ->
|
||||||
lager:debug("[mqtt_subscriber] receive puback packet: ~p", [Packet]),
|
logger:debug("[mqtt_subscriber] receive puback packet: ~p", [Packet]),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
handle_info(Info, State = #state{}) ->
|
handle_info(Info, State = #state{}) ->
|
||||||
lager:debug("[mqtt_subscriber] get info: ~p", [Info]),
|
logger:debug("[mqtt_subscriber] get info: ~p", [Info]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
@ -135,10 +135,10 @@ terminate(Reason, _State = #state{conn_pid = ConnPid}) when is_pid(ConnPid) ->
|
|||||||
{ok, _Props, _ReasonCode} = emqtt:unsubscribe(ConnPid, #{}, TopicNames),
|
{ok, _Props, _ReasonCode} = emqtt:unsubscribe(ConnPid, #{}, TopicNames),
|
||||||
|
|
||||||
ok = emqtt:disconnect(ConnPid),
|
ok = emqtt:disconnect(ConnPid),
|
||||||
lager:debug("[light_mqtt_subscriber] terminate with reason: ~p", [Reason]),
|
logger:debug("[light_mqtt_subscriber] terminate with reason: ~p", [Reason]),
|
||||||
ok;
|
ok;
|
||||||
terminate(Reason, _State) ->
|
terminate(Reason, _State) ->
|
||||||
lager:debug("[light_mqtt_subscriber] terminate with reason: ~p", [Reason]),
|
logger:debug("[light_mqtt_subscriber] terminate with reason: ~p", [Reason]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
@ -184,12 +184,12 @@ emqx_opts(ClientSuffix) when is_binary(ClientSuffix) ->
|
|||||||
dispatch(DeviceMac, Message) when is_binary(DeviceMac), is_binary(Message) ->
|
dispatch(DeviceMac, Message) when is_binary(DeviceMac), is_binary(Message) ->
|
||||||
case light_args:get_device_uuid(DeviceMac) of
|
case light_args:get_device_uuid(DeviceMac) of
|
||||||
error ->
|
error ->
|
||||||
lager:notice("[mqtt_subscriber] device_mac: ~p, device_uuid not found", [DeviceMac]);
|
logger:notice("[mqtt_subscriber] device_mac: ~p, device_uuid not found", [DeviceMac]);
|
||||||
{ok, DeviceUUID} ->
|
{ok, DeviceUUID} ->
|
||||||
case light_device_sup:ensure_device_started(DeviceUUID) of
|
case light_device_sup:ensure_device_started(DeviceUUID) of
|
||||||
{ok, DevicePid} ->
|
{ok, DevicePid} ->
|
||||||
light_device:metric_data(DevicePid, Message);
|
light_device:metric_data(DevicePid, Message);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:notice("[mqtt_subscriber] start device get error: ~p", [Reason])
|
logger:notice("[mqtt_subscriber] start device get error: ~p", [Reason])
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
@ -93,11 +93,11 @@ read_service_name() ->
|
|||||||
%% 获取配置的名称
|
%% 获取配置的名称
|
||||||
RootDir = code:root_dir(),
|
RootDir = code:root_dir(),
|
||||||
VersionFile = RootDir ++ "/.version",
|
VersionFile = RootDir ++ "/.version",
|
||||||
lager:debug("[gateway_sup] version path is: ~p", [VersionFile]),
|
logger:debug("[gateway_sup] version path is: ~p", [VersionFile]),
|
||||||
case file:read_file(VersionFile) of
|
case file:read_file(VersionFile) of
|
||||||
{ok, RegisterName0} ->
|
{ok, RegisterName0} ->
|
||||||
string:trim(RegisterName0);
|
string:trim(RegisterName0);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:warning("[light_app] read .version file get error: ~p", [Reason]),
|
logger:warning("[light_app] read .version file get error: ~p", [Reason]),
|
||||||
<<"light">>
|
<<"light">>
|
||||||
end.
|
end.
|
||||||
@ -20,39 +20,39 @@
|
|||||||
]}
|
]}
|
||||||
]},
|
]},
|
||||||
|
|
||||||
%% 系统日志配置,系统日志为lager, 支持日志按日期自动分割
|
%% 系统日志配置,使用 OTP Logger。
|
||||||
{lager, [
|
{kernel, [
|
||||||
{colored, true},
|
{logger_level, debug},
|
||||||
%% Whether to write a crash log, and where. Undefined means no crash logger.
|
{logger, [
|
||||||
{crash_log, "light.crash.log"},
|
{handler, default, logger_std_h, #{
|
||||||
%% Maximum size in bytes of events in the crash log - defaults to 65536
|
level => debug,
|
||||||
{crash_log_msg_size, 65536},
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
%% Maximum size of the crash log in bytes, before its rotated, set
|
}},
|
||||||
%% to 0 to disable rotation - default is 0
|
{handler, debug_file, logger_std_h, #{
|
||||||
{crash_log_size, 10485760},
|
level => debug,
|
||||||
%% What time to rotate the crash log - default is no time
|
config => #{file => "debug.log"},
|
||||||
%% rotation. See the README for a description of this format.
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
{crash_log_date, "$D0"},
|
}},
|
||||||
%% Number of rotated crash logs to keep, 0 means keep only the
|
{handler, info_file, logger_std_h, #{
|
||||||
%% current one - default is 0
|
level => info,
|
||||||
{crash_log_count, 5},
|
config => #{file => "info.log"},
|
||||||
%% Whether to redirect error_logger messages into lager - defaults to true
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
{error_logger_redirect, true},
|
}},
|
||||||
|
{handler, notice_file, logger_std_h, #{
|
||||||
%% How big the gen_event mailbox can get before it is switched into sync mode
|
level => notice,
|
||||||
{async_threshold, 20},
|
config => #{file => "notice.log"},
|
||||||
%% Switch back to async mode, when gen_event mailbox size decrease from `async_threshold'
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
%% to async_threshold - async_threshold_window
|
}},
|
||||||
{async_threshold_window, 5},
|
{handler, warning_file, logger_std_h, #{
|
||||||
|
level => warning,
|
||||||
{handlers, [
|
config => #{file => "warning.log"},
|
||||||
%% debug | info | warning | error, 日志级别
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
{lager_console_backend, debug},
|
}},
|
||||||
{lager_file_backend, [{file, "debug.log"}, {level, debug}, {size, 314572800}]},
|
{handler, error_file, logger_std_h, #{
|
||||||
{lager_file_backend, [{file, "info.log"}, {level, info}, {size, 314572800}]},
|
level => error,
|
||||||
{lager_file_backend, [{file, "notice.log"}, {level, notice}, {size, 314572800}]},
|
config => #{file => "error.log"},
|
||||||
{lager_file_backend, [{file, "warning.log"}, {level, warning}, {size, 314572800}]},
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
{lager_file_backend, [{file, "error.log"}, {level, error}, {size, 314572800}]}
|
}}
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
|||||||
@ -20,39 +20,38 @@
|
|||||||
]}
|
]}
|
||||||
]},
|
]},
|
||||||
|
|
||||||
%% 系统日志配置,系统日志为lager, 支持日志按日期自动分割
|
%% 系统日志配置,使用 OTP Logger。
|
||||||
{lager, [
|
{kernel, [
|
||||||
{colored, true},
|
{logger_level, debug},
|
||||||
%% Whether to write a crash log, and where. Undefined means no crash logger.
|
{logger, [
|
||||||
{crash_log, "light.crash.log"},
|
{handler, default, logger_std_h, #{
|
||||||
%% Maximum size in bytes of events in the crash log - defaults to 65536
|
level => none
|
||||||
{crash_log_msg_size, 65536},
|
}},
|
||||||
%% Maximum size of the crash log in bytes, before its rotated, set
|
{handler, debug_file, logger_std_h, #{
|
||||||
%% to 0 to disable rotation - default is 0
|
level => debug,
|
||||||
{crash_log_size, 10485760},
|
config => #{file => "debug.log"},
|
||||||
%% What time to rotate the crash log - default is no time
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
%% rotation. See the README for a description of this format.
|
}},
|
||||||
{crash_log_date, "$D0"},
|
{handler, info_file, logger_std_h, #{
|
||||||
%% Number of rotated crash logs to keep, 0 means keep only the
|
level => info,
|
||||||
%% current one - default is 0
|
config => #{file => "info.log"},
|
||||||
{crash_log_count, 5},
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
%% Whether to redirect error_logger messages into lager - defaults to true
|
}},
|
||||||
{error_logger_redirect, true},
|
{handler, notice_file, logger_std_h, #{
|
||||||
|
level => notice,
|
||||||
%% How big the gen_event mailbox can get before it is switched into sync mode
|
config => #{file => "notice.log"},
|
||||||
{async_threshold, 20},
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
%% Switch back to async mode, when gen_event mailbox size decrease from `async_threshold'
|
}},
|
||||||
%% to async_threshold - async_threshold_window
|
{handler, warning_file, logger_std_h, #{
|
||||||
{async_threshold_window, 5},
|
level => warning,
|
||||||
|
config => #{file => "warning.log"},
|
||||||
{handlers, [
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
%% debug | info | warning | error, 日志级别
|
}},
|
||||||
% {lager_console_backend, debug},
|
{handler, error_file, logger_std_h, #{
|
||||||
{lager_file_backend, [{file, "debug.log"}, {level, debug}, {size, 314572800}]},
|
level => error,
|
||||||
{lager_file_backend, [{file, "info.log"}, {level, info}, {size, 314572800}]},
|
config => #{file => "error.log"},
|
||||||
{lager_file_backend, [{file, "notice.log"}, {level, notice}, {size, 314572800}]},
|
formatter => {logger_formatter, #{single_line => true}}
|
||||||
{lager_file_backend, [{file, "warning.log"}, {level, warning}, {size, 314572800}]},
|
}}
|
||||||
{lager_file_backend, [{file, "error.log"}, {level, error}, {size, 314572800}]}
|
|
||||||
]}
|
]}
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
{erl_opts, [debug_info]}.
|
{erl_opts, [debug_info]}.
|
||||||
{deps, [
|
{deps, [
|
||||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}},
|
{jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "1.1.1"}}},
|
||||||
{emqtt, ".*", {git, "https://gitea.s5s8.com/anlicheng/emqtt.git", {tag, "v1.2"}}},
|
{emqtt, ".*", {git, "https://gitea.s5s8.com/anlicheng/emqtt.git", {tag, "v1.2"}}}
|
||||||
{lager, ".*", {git,"https://github.com/erlang-lager/lager.git", {tag, "3.9.2"}}}
|
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
{relx, [{release, {light, "1.0"},
|
{relx, [{release, {light, "1.0"},
|
||||||
@ -36,6 +35,4 @@
|
|||||||
]
|
]
|
||||||
}]}]}.
|
}]}]}.
|
||||||
|
|
||||||
{erl_opts, [{parse_transform,lager_transform}]}.
|
|
||||||
|
|
||||||
{rebar_packages_cdn, "https://hexpm.upyun.com"}.
|
{rebar_packages_cdn, "https://hexpm.upyun.com"}.
|
||||||
|
|||||||
11
rebar.lock
11
rebar.lock
@ -3,18 +3,11 @@
|
|||||||
{git,"https://gitea.s5s8.com/anlicheng/emqtt.git",
|
{git,"https://gitea.s5s8.com/anlicheng/emqtt.git",
|
||||||
{ref,"c5a52dcb57cd23a4318e342b705f9f726e8d67a1"}},
|
{ref,"c5a52dcb57cd23a4318e342b705f9f726e8d67a1"}},
|
||||||
0},
|
0},
|
||||||
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
|
|
||||||
{<<"jiffy">>,
|
{<<"jiffy">>,
|
||||||
{git,"https://github.com/davisp/jiffy.git",
|
{git,"https://github.com/davisp/jiffy.git",
|
||||||
{ref,"9ea1b35b6e60ba21dfd4adbd18e7916a831fd7d4"}},
|
{ref,"9ea1b35b6e60ba21dfd4adbd18e7916a831fd7d4"}},
|
||||||
0},
|
|
||||||
{<<"lager">>,
|
|
||||||
{git,"https://github.com/erlang-lager/lager.git",
|
|
||||||
{ref,"459a3b2cdd9eadd29e5a7ce5c43932f5ccd6eb88"}},
|
|
||||||
0}]}.
|
0}]}.
|
||||||
[
|
[
|
||||||
{pkg_hash,[
|
{pkg_hash,[]},
|
||||||
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}]},
|
{pkg_hash_ext,[]}
|
||||||
{pkg_hash_ext,[
|
|
||||||
{<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>}]}
|
|
||||||
].
|
].
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user