diff options
Diffstat (limited to 'lib/kernel')
-rw-r--r-- | lib/kernel/src/logger_proxy.erl | 18 | ||||
-rw-r--r-- | lib/kernel/test/logger_proxy_SUITE.erl | 14 |
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/kernel/src/logger_proxy.erl b/lib/kernel/src/logger_proxy.erl index 24b293805c..6ab8e3e4c5 100644 --- a/lib/kernel/src/logger_proxy.erl +++ b/lib/kernel/src/logger_proxy.erl @@ -42,11 +42,16 @@ StringOrReport :: unicode:chardata() | logger:report(), Meta :: logger:metadata(). log(RemoteLog) -> - Olp = persistent_term:get(?MODULE), - case logger_olp:get_pid(Olp) =:= self() of + Olp = persistent_term:get(?MODULE, undefined), + case (Olp =:= undefined) orelse (logger_olp:get_pid(Olp) =:= self()) of true -> %% This happens when the log event comes from the %% emulator, and the group leader is on a remote node. + %% + %% OR + %% + %% when we are to log a remote message before the logger_proxy + %% has started _ = handle_load(RemoteLog, no_state), ok; false -> @@ -112,9 +117,12 @@ init([]) -> %% Log event to send to the node where the group leader of it's client resides handle_load({remote,Node,Log},State) -> - %% If the connection is overloaded (send_nosuspend returns false), - %% we drop the message. - _ = erlang:send_nosuspend({?SERVER,Node},Log), + case erlang:send({?SERVER,Node},Log,[nosuspend]) of + _ok_or_nosuspend -> + %% If the connection is overloaded (send returns nosuspend), + %% we drop the message. + ok + end, State; %% Log event to log on this node handle_load({log,Level,Format,Args,Meta},State) -> diff --git a/lib/kernel/test/logger_proxy_SUITE.erl b/lib/kernel/test/logger_proxy_SUITE.erl index 777531e4ed..bae2bd8d17 100644 --- a/lib/kernel/test/logger_proxy_SUITE.erl +++ b/lib/kernel/test/logger_proxy_SUITE.erl @@ -72,6 +72,7 @@ all() -> [basic, emulator, remote, + remote_disconnect, remote_emulator, config, restart_after, @@ -118,6 +119,19 @@ remote(Config) -> remote(cleanup,_Config) -> ok = logger:remove_handler(?HNAME). +remote_disconnect(Config) -> + {ok,_,Node} = logger_test_lib:setup(Config,[{logger,[{proxy,#{}}]}]), + ok = logger:add_handler(?HNAME,?MODULE,#{config=>self()}), + RemoteGL = rpc:call(Node, erlang, whereis, [user]), + net_kernel:disconnect(Node), + L1 = ?LOC#{ gl => RemoteGL }, logger:notice("Log from ~p; ~p",[?FUNCTION_NAME,?LINE],L1), + ok = ensure(L1), + L2 = ?LOC#{ gl => RemoteGL }, logger:notice([{test_case,?FUNCTION_NAME},{line,?LINE}],L2), + ok = ensure(L2), + ok. +remote_disconnect(cleanup,_Config) -> + ok = logger:remove_handler(?HNAME). + remote_emulator(Config) -> {ok,_,Node} = logger_test_lib:setup(Config,[{logger,[{proxy,#{}}]}]), ok = logger:add_handler(?HNAME,?MODULE,#{config=>self()}), |