aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2018-12-17 16:24:41 +0100
committerSiri Hansen <[email protected]>2019-01-16 09:59:24 +0100
commitdc9108ff7a4414d702fb8006df82668309ad3d5b (patch)
tree3b64395f086c1fb06c3ef875fb16127142748f88 /lib
parentb28f162139049a3105e33936cbbef1f0fa3a30f1 (diff)
downloadotp-dc9108ff7a4414d702fb8006df82668309ad3d5b.tar.gz
otp-dc9108ff7a4414d702fb8006df82668309ad3d5b.tar.bz2
otp-dc9108ff7a4414d702fb8006df82668309ad3d5b.zip
[logger] Use persistent_term for storing proxy reference
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/src/logger.erl21
-rw-r--r--lib/kernel/src/logger_proxy.erl10
-rw-r--r--lib/kernel/src/logger_server.erl16
-rw-r--r--lib/kernel/test/logger_proxy_SUITE.erl6
4 files changed, 19 insertions, 34 deletions
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 0ab3addfef..f05e756fd0 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -937,14 +937,13 @@ log_allowed(Location,Level,Msg,Meta0) when is_map(Meta0) ->
%% (function or macro).
Meta = add_default_metadata(
maps:merge(Location,maps:merge(proc_meta(),Meta0))),
- Tid = tid(),
case node(maps:get(gl,Meta)) of
Node when Node=/=node() ->
- log_remote(Node,Level,Msg,Meta,Tid),
- do_log_allowed(Level,Msg,Meta,Tid);
+ log_remote(Node,Level,Msg,Meta);
_ ->
- do_log_allowed(Level,Msg,Meta,Tid)
- end.
+ ok
+ end,
+ do_log_allowed(Level,Msg,Meta,tid()).
do_log_allowed(Level,{Format,Args}=Msg,Meta,Tid)
when ?IS_LEVEL(Level),
@@ -967,13 +966,13 @@ do_log_allowed(Level,String,Meta,Tid)
tid() ->
ets:whereis(?LOGGER_TABLE).
-log_remote(Node,Level,{Format,Args},Meta,Tid) ->
- log_remote(Node,{log,Level,Format,Args,Meta},Tid);
-log_remote(Node,Level,Msg,Meta,Tid) ->
- log_remote(Node,{log,Level,Msg,Meta},Tid).
+log_remote(Node,Level,{Format,Args},Meta) ->
+ log_remote(Node,{log,Level,Format,Args,Meta});
+log_remote(Node,Level,Msg,Meta) ->
+ log_remote(Node,{log,Level,Msg,Meta}).
-log_remote(Node,Request,Tid) ->
- logger_proxy:log(logger_server:get_proxy_ref(Tid),{remote,Node,Request}),
+log_remote(Node,Request) ->
+ logger_proxy:log({remote,Node,Request}),
ok.
add_default_metadata(Meta) ->
diff --git a/lib/kernel/src/logger_proxy.erl b/lib/kernel/src/logger_proxy.erl
index 45a3011828..a72952df2f 100644
--- a/lib/kernel/src/logger_proxy.erl
+++ b/lib/kernel/src/logger_proxy.erl
@@ -20,7 +20,7 @@
-module(logger_proxy).
%% API
--export([start_link/0, restart/0, log/2, child_spec/0, get_default_config/0]).
+-export([start_link/0, restart/0, log/1, child_spec/0, get_default_config/0]).
%% logger_olp callbacks
-export([init/1, handle_load/2, handle_info/2, terminate/2,
@@ -32,8 +32,7 @@
%%%-----------------------------------------------------------------
%%% API
--spec log(Olp, RemoteLog) -> ok when
- Olp :: logger_olp:olp_ref(),
+-spec log(RemoteLog) -> ok when
RemoteLog :: {remote,node(),LogEvent},
LogEvent :: {log,Level,Format,Args,Meta} |
{log,Level,StringOrReport,Meta},
@@ -42,7 +41,8 @@
Args :: list(term()),
StringOrReport :: unicode:chardata() | logger:report(),
Meta :: logger:metadata().
-log(Olp, RemoteLog) ->
+log(RemoteLog) ->
+ Olp = persistent_term:get(?MODULE),
case logger_olp:get_pid(Olp) =:= self() of
true ->
%% This happens when the log event comes from the
@@ -107,7 +107,7 @@ get_default_config() ->
init([]) ->
process_flag(trap_exit, true),
_ = erlang:system_flag(system_logger,self()),
- logger_server:set_proxy_ref(logger_olp:get_ref()),
+ persistent_term:put(?MODULE,logger_olp:get_ref()),
{ok,no_state}.
%% Log event to send to the node where the group leader of it's client resides
diff --git a/lib/kernel/src/logger_server.erl b/lib/kernel/src/logger_server.erl
index c58edf51f8..f123eec8dd 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -22,8 +22,7 @@
-behaviour(gen_server).
%% API
--export([start_link/0, set_proxy_ref/1, get_proxy_ref/1,
- add_handler/3, remove_handler/1,
+-export([start_link/0, add_handler/3, remove_handler/1,
add_filter/2, remove_filter/2,
set_module_level/2, unset_module_level/0,
unset_module_level/1, cache_module_level/1,
@@ -52,14 +51,6 @@
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
--spec set_proxy_ref(logger_olp:olp_ref()) -> ok.
-set_proxy_ref(ProxyRef) ->
- call({set_proxy_ref,ProxyRef}).
-
--spec get_proxy_ref(ets:tid()) -> logger_olp:olp_ref().
-get_proxy_ref(Tid) ->
- ets:lookup_element(Tid,proxy_ref,2).
-
add_handler(Id,Module,Config0) ->
try {check_id(Id),check_mod(Module)} of
{ok,ok} ->
@@ -319,10 +310,7 @@ handle_call({set_module_level,Modules,Level}, _From, #state{tid=Tid}=State) ->
{reply,Reply,State};
handle_call({unset_module_level,Modules}, _From, #state{tid=Tid}=State) ->
Reply = logger_config:unset_module_level(Tid,Modules),
- {reply,Reply,State};
-handle_call({set_proxy_ref,ProxyRef},_From,#state{tid=Tid}=State) ->
- true = ets:insert(Tid,{proxy_ref,ProxyRef}),
- {reply,ok,State}.
+ {reply,Reply,State}.
handle_cast({async_req_reply,_Ref,_Reply} = Reply,State) ->
call_h_reply(Reply,State);
diff --git a/lib/kernel/test/logger_proxy_SUITE.erl b/lib/kernel/test/logger_proxy_SUITE.erl
index ea3733dae7..92a41eb255 100644
--- a/lib/kernel/test/logger_proxy_SUITE.erl
+++ b/lib/kernel/test/logger_proxy_SUITE.erl
@@ -85,14 +85,12 @@ basic(_Config) ->
ok = ensure(L1),
logger_proxy ! {log,notice,[{test_case,?FUNCTION_NAME},{line,?LINE}],L2=?LOC},
ok = ensure(L2),
- logger_proxy:log(logger_server:get_proxy_ref(logger),
- {remote,node(),{log,notice,
+ logger_proxy:log({remote,node(),{log,notice,
"Log from: ~p; ~p",
[?FUNCTION_NAME,?LINE],
L3=?LOC}}),
ok = ensure(L3),
- logger_proxy:log(logger_server:get_proxy_ref(logger),
- {remote,node(),{log,notice,
+ logger_proxy:log({remote,node(),{log,notice,
[{test_case,?FUNCTION_NAME},
{line,?LINE}],
L4=?LOC}}),