fix
This commit is contained in:
parent
f2847053b7
commit
d3decb00b5
@ -85,6 +85,10 @@
|
|||||||
{handler, default, logger_std_h,
|
{handler, default, logger_std_h,
|
||||||
#{
|
#{
|
||||||
level => debug,
|
level => debug,
|
||||||
|
filter_default => stop,
|
||||||
|
filters => [
|
||||||
|
{iot_only, {fun logger_filters:domain/2, {log, sub, [iot]}}}
|
||||||
|
],
|
||||||
formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}}
|
formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -92,6 +96,10 @@
|
|||||||
{handler, disk, logger_disk_log_h,
|
{handler, disk, logger_disk_log_h,
|
||||||
#{
|
#{
|
||||||
level => debug,
|
level => debug,
|
||||||
|
filter_default => stop,
|
||||||
|
filters => [
|
||||||
|
{iot_only, {fun logger_filters:domain/2, {log, sub, [iot]}}}
|
||||||
|
],
|
||||||
config => #{
|
config => #{
|
||||||
file => "log/debug.log",
|
file => "log/debug.log",
|
||||||
max_no_files => 10,
|
max_no_files => 10,
|
||||||
|
|||||||
@ -55,6 +55,10 @@
|
|||||||
{handler, default, logger_std_h,
|
{handler, default, logger_std_h,
|
||||||
#{
|
#{
|
||||||
level => debug,
|
level => debug,
|
||||||
|
filter_default => stop,
|
||||||
|
filters => [
|
||||||
|
{iot_only, {fun logger_filters:domain/2, {log, sub, [iot]}}}
|
||||||
|
],
|
||||||
formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}}
|
formatter => {logger_formatter, #{template => [time, " [", level, "] ", msg, "\n"]}}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -62,6 +66,10 @@
|
|||||||
{handler, disk, logger_disk_log_h,
|
{handler, disk, logger_disk_log_h,
|
||||||
#{
|
#{
|
||||||
level => debug,
|
level => debug,
|
||||||
|
filter_default => stop,
|
||||||
|
filters => [
|
||||||
|
{iot_only, {fun logger_filters:domain/2, {log, sub, [iot]}}}
|
||||||
|
],
|
||||||
config => #{
|
config => #{
|
||||||
file => "log/debug.log",
|
file => "log/debug.log",
|
||||||
max_no_files => 10,
|
max_no_files => 10,
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
%% exist but can be set manually, which
|
%% exist but can be set manually, which
|
||||||
%% is required if the names aren't exactly
|
%% is required if the names aren't exactly
|
||||||
%% sys.config and vm.args
|
%% sys.config and vm.args
|
||||||
{sys_config, "./config/sys.config"},
|
{sys_config, "./config/sys-dev.config"},
|
||||||
{vm_args, "./config/vm.args"}
|
{vm_args, "./config/vm.args"}
|
||||||
|
|
||||||
%% the .src form of the configuration files do
|
%% the .src form of the configuration files do
|
||||||
@ -60,7 +60,8 @@
|
|||||||
[%% prod is the default mode when prod
|
[%% prod is the default mode when prod
|
||||||
%% profile is used, so does not have
|
%% profile is used, so does not have
|
||||||
%% to be explicitly included like this
|
%% to be explicitly included like this
|
||||||
{mode, prod}
|
{mode, prod},
|
||||||
|
{sys_config, "./config/sys-prod.config"}
|
||||||
|
|
||||||
%% use minimal mode to exclude ERTS
|
%% use minimal mode to exclude ERTS
|
||||||
%% {mode, minimal}
|
%% {mode, minimal}
|
||||||
|
|||||||
@ -101,6 +101,7 @@ start_link(Opts) when is_list(Opts) ->
|
|||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([InfluxProps]) ->
|
init([InfluxProps]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
Token = proplists:get_value(token, InfluxProps),
|
Token = proplists:get_value(token, InfluxProps),
|
||||||
Host = proplists:get_value(host, InfluxProps),
|
Host = proplists:get_value(host, InfluxProps),
|
||||||
Port = proplists:get_value(port, InfluxProps),
|
Port = proplists:get_value(port, InfluxProps),
|
||||||
|
|||||||
@ -45,6 +45,7 @@ start_link(LocalName, Endpoint = #endpoint{config = #http_endpoint{}}) when is_a
|
|||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([Endpoint = #endpoint{matcher = Matcher}]) ->
|
init([Endpoint = #endpoint{matcher = Matcher}]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
endpoint_subscription:subscribe(Matcher, self()),
|
endpoint_subscription:subscribe(Matcher, self()),
|
||||||
Buffer = endpoint_buffer:new(Endpoint, 10),
|
Buffer = endpoint_buffer:new(Endpoint, 10),
|
||||||
{ok, #state{endpoint = Endpoint, buffer = Buffer}}.
|
{ok, #state{endpoint = Endpoint, buffer = Buffer}}.
|
||||||
|
|||||||
@ -51,6 +51,7 @@ start_link(LocalName, Endpoint = #endpoint{}) when is_atom(LocalName) ->
|
|||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([Endpoint = #endpoint{id = Id, matcher = Matcher}]) ->
|
init([Endpoint = #endpoint{id = Id, matcher = Matcher}]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
endpoint_subscription:subscribe(Matcher, self()),
|
endpoint_subscription:subscribe(Matcher, self()),
|
||||||
|
|
||||||
erlang:process_flag(trap_exit, true),
|
erlang:process_flag(trap_exit, true),
|
||||||
|
|||||||
@ -53,6 +53,7 @@ start_link(LocalName, Endpoint = #endpoint{}) when is_atom(LocalName) ->
|
|||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([Endpoint = #endpoint{matcher = Matcher}]) ->
|
init([Endpoint = #endpoint{matcher = Matcher}]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
% erlang:process_flag(trap_exit, true),
|
% erlang:process_flag(trap_exit, true),
|
||||||
endpoint_subscription:subscribe(Matcher, self()),
|
endpoint_subscription:subscribe(Matcher, self()),
|
||||||
|
|
||||||
|
|||||||
@ -69,6 +69,7 @@ start_link() ->
|
|||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([]) ->
|
init([]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
|
|||||||
@ -54,6 +54,7 @@ start_link(RetryInterval) when is_integer(RetryInterval) ->
|
|||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([RetryInterval]) ->
|
init([RetryInterval]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
{ok, #state{retry_interval = RetryInterval}}.
|
{ok, #state{retry_interval = RetryInterval}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
|
|||||||
@ -56,6 +56,7 @@ start_link() ->
|
|||||||
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
{ok, State :: #state{}} | {ok, State :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([]) ->
|
init([]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
|
|||||||
@ -174,6 +174,7 @@ start_link(Name, UUID) when is_atom(Name), is_binary(UUID) ->
|
|||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([UUID]) ->
|
init([UUID]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
case iot_api_client:get_host_by_uuid(UUID) of
|
case iot_api_client:get_host_by_uuid(UUID) of
|
||||||
{ok, #{<<"id">> := HostId, <<"authorize_status">> := AuthorizeStatus}} ->
|
{ok, #{<<"id">> := HostId, <<"authorize_status">> := AuthorizeStatus}} ->
|
||||||
%% 通过host_id注册别名, 可以避免通过查询数据库获取HostPid
|
%% 通过host_id注册别名, 可以避免通过查询数据库获取HostPid
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
-export([start/2, stop/1]).
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
io:setopts([{encoding, unicode}]),
|
io:setopts([{encoding, unicode}]),
|
||||||
%% 加速内存的回收
|
%% 加速内存的回收
|
||||||
erlang:system_flag(fullsweep_after, 16),
|
erlang:system_flag(fullsweep_after, 16),
|
||||||
|
|||||||
10
src/iot_log.erl
Normal file
10
src/iot_log.erl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% @doc Logger helper for project-scoped metadata.
|
||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
-module(iot_log).
|
||||||
|
|
||||||
|
-export([set_metadata/0]).
|
||||||
|
|
||||||
|
-spec set_metadata() -> ok.
|
||||||
|
set_metadata() ->
|
||||||
|
logger:set_process_metadata(#{domain => [iot]}).
|
||||||
@ -13,6 +13,7 @@
|
|||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
|
|
||||||
init(Req0, Opts) ->
|
init(Req0, Opts) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
Method = binary_to_list(cowboy_req:method(Req0)),
|
Method = binary_to_list(cowboy_req:method(Req0)),
|
||||||
Path = binary_to_list(cowboy_req:path(Req0)),
|
Path = binary_to_list(cowboy_req:path(Req0)),
|
||||||
GetParams0 = cowboy_req:parse_qs(Req0),
|
GetParams0 = cowboy_req:parse_qs(Req0),
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
|
|
||||||
init(Req0, Opts = [Mod|_]) ->
|
init(Req0, Opts = [Mod|_]) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
Method = binary_to_list(cowboy_req:method(Req0)),
|
Method = binary_to_list(cowboy_req:method(Req0)),
|
||||||
Path = binary_to_list(cowboy_req:path(Req0)),
|
Path = binary_to_list(cowboy_req:path(Req0)),
|
||||||
GetParams0 = cowboy_req:parse_qs(Req0),
|
GetParams0 = cowboy_req:parse_qs(Req0),
|
||||||
|
|||||||
@ -64,6 +64,7 @@ start_link(Ref, Transport, Opts) ->
|
|||||||
{ok, proc_lib:spawn_link(?MODULE, init, [Ref, Transport, Opts])}.
|
{ok, proc_lib:spawn_link(?MODULE, init, [Ref, Transport, Opts])}.
|
||||||
|
|
||||||
init(Ref, Transport, _Opts = []) ->
|
init(Ref, Transport, _Opts = []) ->
|
||||||
|
ok = iot_log:set_metadata(),
|
||||||
{ok, Socket} = ranch:handshake(Ref),
|
{ok, Socket} = ranch:handshake(Ref),
|
||||||
logger:debug("[sdlan_channel] get a new connection: ~p", [Socket]),
|
logger:debug("[sdlan_channel] get a new connection: ~p", [Socket]),
|
||||||
Transport:setopts(Socket, [binary, {active, true}, {packet, 4}]),
|
Transport:setopts(Socket, [binary, {active, true}, {packet, 4}]),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user