Ver a proveniência

ft: rumHWatcherSrv 修改

master
SisMaker há 4 anos
ascendente
cometimento
12bfea8581
5 ficheiros alterados com 66 adições e 46 eliminações
  1. +4
    -0
      include/eRum.hrl
  2. +0
    -2
      src/eRum.erl
  3. +5
    -5
      src/eRum_app.erl
  4. +38
    -39
      src/watcher/rumHWatcherSrv.erl
  5. +19
    -0
      进度.md

+ 4
- 0
include/eRum.hrl Ver ficheiro

@ -1,6 +1,10 @@
%%
-define(IIF(Cond, Ret1, Ret2), (case Cond of true -> Ret1; _ -> Ret2 end)).
%%
-define(ERR(Format), error_logger:error_msg(Format)).
-define(ERR(Format, Args), error_logger:error_msg(Format, Args)).
%%
-define(RumAppName, eRum).

+ 0
- 2
src/eRum.erl Ver ficheiro

@ -1,5 +1,3 @@
%% @doc The lager logging framework.
-module(eRum).
-include("eRum.hrl").

+ 5
- 5
src/eRum_app.erl Ver ficheiro

@ -9,7 +9,7 @@
, start/2
, stop/1
, doStart/0
, doStartExtraSink/1
, startSink/1
, startHandler/3
, startSink/2
]).
@ -22,7 +22,7 @@ start() ->
start(_StartType, _StartArgs) ->
{ok, Pid} = eRum_sup:start_link(),
SavedHandlers = doStart(),
_ = doStartExtraSink(),
doStartExtraSink(),
doStartTraces(),
{ok, Pid, SavedHandlers}.
@ -59,8 +59,8 @@ startTrace({Handler, Filter, Level}) when is_atom(Level) ->
doStartExtraSink() ->
doStartExtraSinks(rumUtil:get_env(extra_sinks, [])).
doStartExtraSink(?RumDefSink) -> doStart();
doStartExtraSink(Sink) ->
startSink(?RumDefSink) -> doStart();
startSink(Sink) ->
AllSinksDef = rumUtil:get_env(extra_sinks, []),
boot_sink(Sink, lists:keyfind(Sink, 1, AllSinksDef)).
@ -73,7 +73,7 @@ stop(Handlers) ->
[error_logger:add_report_handler(Handler) || Handler <- Handlers],
rumConfig:cleanup().
tryStartAsyncMgr(undefined, _Window, _SinkS) ->
tryStartAsyncMgr(undefined, _Window, _Sink) ->
ignore;
tryStartAsyncMgr(Threshold, Window, Sink) ->
case Window of

+ 38
- 39
src/watcher/rumHWatcherSrv.erl Ver ficheiro

@ -24,29 +24,30 @@
sink :: pid() | atom()
}).
start_link(Sink, Module, Config) ->
gen_server:start_link(?MODULE, [Sink, Module, Config], []).
start(Sink, Module, Config) ->
gen_server:start(?MODULE, [Sink, Module, Config], []).
gen_srv:start(?MODULE, {Sink, Module, Config}, []).
start_link(Sink, Module, Config) ->
gen_srv:start_link(?MODULE, {Sink, Module, Config}, []).
init([Sink, Module, Config]) ->
init({Sink, Module, Config}) ->
process_flag(trap_exit, true),
install_handler(Sink, Module, Config),
installHandler(Module, Config, Sink),
{ok, #state{sink = Sink, module = Module, config = Config}}.
handleCall(_Call, State, _From) ->
{reply, ok, State}.
handleCall(_Msg, _State, _From) ->
?ERR("~p call receive unexpect msg ~p ~n ", [?MODULE, _Msg]),
{reply, ok}.
handleCast(_Request, State) ->
{noreply, State}.
handleCast(_Msg, _State) ->
?ERR("~p cast receive unexpect msg ~p ~n ", [?MODULE, _Msg]),
kpS.
handleInfo({gen_event_EXIT, Module, normal}, #state{module = Module} = State) ->
{stop, normal, State};
handleInfo({gen_event_EXIT, Module, shutdown}, #state{module = Module} = State) ->
{stop, normal, State};
handleInfo({gen_event_EXIT, Module, {'EXIT', {kill_me, [_KillerHWM, KillerReinstallAfter]}}},
#state{module = Module, sink = Sink, config = Config} = State) ->
handleInfo({gen_event_EXIT, Module, {'EXIT', {kill_me, [_KillerHWM, KillerReinstallAfter]}}}, #state{module = Module, sink = Sink, config = Config} = State) ->
%% Brutally kill the manager but stay alive to restore settings.
%%
%% SinkPid here means the gen_event process. Handlers *all* live inside the
@ -59,30 +60,30 @@ handleInfo({gen_event_EXIT, Module, {'EXIT', {kill_me, [_KillerHWM, KillerReinst
exit(SinkPid, kill),
_ = timer:apply_after(KillerReinstallAfter, lager_app, start_handler, [Sink, Module, Config]),
{stop, normal, State};
handleInfo({gen_event_EXIT, Module, Reason}, #state{module = Module,
config = Config, sink = Sink} = State) ->
handleInfo({gen_event_EXIT, Module, Reason}, #state{module = Module, config = Config, sink = Sink} = State) ->
case eRum:log(error, self(), "Lager event handler ~p exited with reason ~s", [Module, rumErrLoggerH:format_reason(Reason)]) of
ok ->
install_handler(Sink, Module, Config);
installHandler(Module, Config, Sink);
{error, _} ->
%% lager is not working, so installing a handler won't work
ok
end,
{noreply, State};
handleInfo(reinstall_handler, #state{module = Module, config = Config, sink = Sink} = State) ->
install_handler(Sink, Module, Config),
{noreply, State};
handleInfo({reboot, Sink}, State) ->
_ = lager_app:boot(Sink),
{noreply, State};
handleInfo(reinstall_handler, #state{module = Module, config = Config, sink = Sink}) ->
installHandler(Module, Config, Sink),
kpS;
handleInfo({reboot, Sink}, _State) ->
eRum_app:startSink(Sink),
kpS;
handleInfo(stop, State) ->
{stop, normal, State};
handleInfo({'EXIT', _Pid, killed}, #state{module = Module, config = Config, sink = Sink} = State) ->
Tmr = application:get_env(lager, killerReTime, 5000),
_ = timer:apply_after(Tmr, lager_app, start_handler, [Sink, Module, Config]),
Tmr = rumUtil:get_env(killerReTime, 5000),
_ = timer:apply_after(Tmr, eRum_app, startHandler, [Sink, Module, Config]),
{stop, normal, State};
handleInfo(_Info, State) ->
{noreply, State}.
handleInfo(_Msg, _State) ->
?ERR("~p info receive unexpect msg ~p ~n ", [?MODULE, _Msg]),
kpS.
terminate(_Reason, _State) ->
ok.
@ -90,20 +91,18 @@ terminate(_Reason, _State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%% internal
install_handler(Sink, lager_backend_throttle, Config) ->
%% The lager_backend_throttle needs to know to which sink it is
%% attached, hence this admittedly ugly workaround. Handlers are
%% sensitive to the structure of the configuration sent to `init',
%% sadly, so it's not trivial to add a configuration item to be
%% ignored to backends without breaking 3rd party handlers.
install_handler2(Sink, lager_backend_throttle, [{sink, Sink} | Config]);
install_handler(Sink, Module, Config) ->
install_handler2(Sink, Module, Config).
%% private
install_handler2(Sink, Module, Config) ->
case gen_event:add_sup_handler(Sink, Module, Config) of
installHandler(Module, Config, Sink) ->
Ret =
case Module of
rumBackendThrottle ->
%% lager_backend_throttle需要知道它连接到哪个接收器' init'
%%
gen_emm:add_sup_epm(Sink, Module, [{sink, Sink} | Config]);
_ ->
gen_emm:add_sup_epm(Sink, Module, Config)
end,
case Ret of
ok ->
?INT_LOG(debug, "Lager installed handler ~p into ~p", [Module, Sink]),
eRum:updateLogevelCfg(Sink),

+ 19
- 0
进度.md Ver ficheiro

@ -0,0 +1,19 @@
# Done complete
eRum_sup
eRum.app.src
rumHWatcherSup
# Done incomplete
app.config done
eRum_app
rumHWatcherSrv 部分还需要修改 删除测试代码
# Doing
# TODO

Carregando…
Cancelar
Guardar