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