diff --git a/include/rum.hrl b/include/eRum.hrl similarity index 100% rename from include/rum.hrl rename to include/eRum.hrl diff --git a/rebar.config b/rebar.config index 4cd012f..d08fe42 100644 --- a/rebar.config +++ b/rebar.config @@ -29,6 +29,7 @@ ]}. {deps, [ + {eGbh, ".*", {git, "http://192.168.0.88:53000/SisMaker/eGbh.git", {branch, "master"}}}, {goldrush, "0.1.9"} ]}. diff --git a/src/backend/rumBackendConsole.erl b/src/backend/rumBackendConsole.erl index 2fcc43a..76a0db6 100644 --- a/src/backend/rumBackendConsole.erl +++ b/src/backend/rumBackendConsole.erl @@ -30,7 +30,7 @@ -endif. --include("rum.hrl"). +-include("eRum.hrl"). -define(TERSE_FORMAT, [time, " ", color, "[", severity, "] ", message]). -define(DEFAULT_FORMAT_CONFIG, ?TERSE_FORMAT ++ [eol()]). diff --git a/src/backend/rumBackendFile.erl b/src/backend/rumBackendFile.erl index c9a5832..be53523 100644 --- a/src/backend/rumBackendFile.erl +++ b/src/backend/rumBackendFile.erl @@ -14,7 +14,7 @@ -module(rumBackendFile). --include("rum.hrl"). +-include("eRum.hrl"). -include_lib("kernel/include/file.hrl"). -behaviour(gen_event). diff --git a/src/backend/rumBackendThrottle.erl b/src/backend/rumBackendThrottle.erl index 0bdb0f4..883dcf2 100644 --- a/src/backend/rumBackendThrottle.erl +++ b/src/backend/rumBackendThrottle.erl @@ -8,7 +8,7 @@ -behaviour(gen_event). --include("rum.hrl"). +-include("eRum.hrl"). -export([ init/1 diff --git a/src/eRum.erl b/src/eRum.erl index 50c23e1..617a896 100644 --- a/src/eRum.erl +++ b/src/eRum.erl @@ -18,7 +18,7 @@ -module(eRum). --include("rum.hrl"). +-include("eRum.hrl"). -define(LAGER_MD_KEY, '__lager_metadata'). -define(TRACE_SINK, '__trace_sink'). diff --git a/src/eRum_app.erl b/src/eRum_app.erl index e3e0205..bd27c96 100644 --- a/src/eRum_app.erl +++ b/src/eRum_app.erl @@ -2,7 +2,7 @@ -behaviour(application). --include("rum.hrl"). +-include("eRum.hrl"). -export([ start/0 diff --git a/src/formatter/rumFormatter.erl b/src/formatter/rumFormatter.erl index c08c5d9..a7c236b 100644 --- a/src/formatter/rumFormatter.erl +++ b/src/formatter/rumFormatter.erl @@ -19,7 +19,7 @@ %% %% Include files %% --include("rum.hrl"). +-include("eRum.hrl"). -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -endif. diff --git a/src/misc/rumConfig.erl b/src/misc/rumConfig.erl index b69a29b..865e33a 100644 --- a/src/misc/rumConfig.erl +++ b/src/misc/rumConfig.erl @@ -1,6 +1,6 @@ -module(rumConfig). --include("rum.hrl"). +-include("eRum.hrl"). -export([ new/0 diff --git a/src/misc/rumCrashLog.erl b/src/misc/rumCrashLog.erl index 7a057fb..b7d75a2 100644 --- a/src/misc/rumCrashLog.erl +++ b/src/misc/rumCrashLog.erl @@ -33,7 +33,7 @@ -module(rumCrashLog). --include("rum.hrl"). +-include("eRum.hrl"). -behaviour(gen_server). diff --git a/src/misc/rumErrLoggerH.erl b/src/misc/rumErrLoggerH.erl index 883bfdf..6e6fdc7 100644 --- a/src/misc/rumErrLoggerH.erl +++ b/src/misc/rumErrLoggerH.erl @@ -23,7 +23,7 @@ -module(rumErrLoggerH). --include("rum.hrl"). +-include("eRum.hrl"). -behaviour(gen_event). diff --git a/src/misc/rumMgrKiller.erl b/src/misc/rumMgrKiller.erl index c6dc88e..3ce2437 100644 --- a/src/misc/rumMgrKiller.erl +++ b/src/misc/rumMgrKiller.erl @@ -6,7 +6,7 @@ -export([kill_me/0]). --include("rum.hrl"). +-include("eRum.hrl"). -record(state, { killer_hwm :: non_neg_integer(), diff --git a/src/misc/rumUtil.erl b/src/misc/rumUtil.erl index dc57601..75b9555 100644 --- a/src/misc/rumUtil.erl +++ b/src/misc/rumUtil.erl @@ -38,7 +38,7 @@ -include_lib("eunit/include/eunit.hrl"). -endif. --include("rum.hrl"). +-include("eRum.hrl"). -include_lib("kernel/include/file.hrl"). diff --git a/src/test/lager_common_test_backend.erl b/src/test/lager_common_test_backend.erl index 3f488df..68ad122 100644 --- a/src/test/lager_common_test_backend.erl +++ b/src/test/lager_common_test_backend.erl @@ -19,7 +19,7 @@ format_config :: any(), log = [] :: list()}). --include("rum.hrl"). +-include("eRum.hrl"). -define(TERSE_FORMAT, [time, " ", color, "[", severity, "] ", message]). %% @doc Before every test, just diff --git a/src/transform/rumTransform.erl b/src/transform/rumTransform.erl index 90fd1ee..9a74a20 100644 --- a/src/transform/rumTransform.erl +++ b/src/transform/rumTransform.erl @@ -1,6 +1,6 @@ -module(rumTransform). --include("rum.hrl"). +-include("eRum.hrl"). -export([parse_transform/2]). diff --git a/src/watcher/rumHleWatcherSrv.erl b/src/watcher/rumHleWatcherSrv.erl index 9e800bc..439200c 100644 --- a/src/watcher/rumHleWatcherSrv.erl +++ b/src/watcher/rumHleWatcherSrv.erl @@ -1,40 +1,22 @@ -%% Copyright (c) 2011-2012 Basho Technologies, Inc. All Rights Reserved. -%% -%% This file is provided to you under the Apache License, -%% Version 2.0 (the "License"); you may not use this file -%% except in compliance with the License. You may obtain -%% a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, -%% software distributed under the License is distributed on an -%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -%% KIND, either express or implied. See the License for the -%% specific language governing permissions and limitations -%% under the License. - -%% @doc A process that does a gen_event:add_sup_handler and attempts to re-add -%% event handlers when they exit. - -%% @private - -module(rumHleWatcherSrv). --behaviour(gen_server). - --include("rum.hrl"). +-behaviour(gen_srv). --ifdef(TEST). --include_lib("eunit/include/eunit.hrl"). --export([pop_until/2]). --endif. +-include("eRum.hrl"). -%% callbacks --export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, - code_change/3]). +-export([ + start/3 + , start_link/3 +]). --export([start_link/3, start/3]). +-export([ + init/1 + , handleCall/3 + , handleCast/2 + , handleInfo/2 + , terminate/2, + code_change/3 +]). -record(state, { module :: atom(), @@ -53,17 +35,17 @@ init([Sink, Module, Config]) -> install_handler(Sink, Module, Config), {ok, #state{sink = Sink, module = Module, config = Config}}. -handle_call(_Call, _From, State) -> +handleCall(_Call, State, _From) -> {reply, ok, State}. -handle_cast(_Request, State) -> +handleCast(_Request, State) -> {noreply, State}. -handle_info({gen_event_EXIT, Module, normal}, #state{module = Module} = State) -> +handleInfo({gen_event_EXIT, Module, normal}, #state{module = Module} = State) -> {stop, normal, State}; -handle_info({gen_event_EXIT, Module, shutdown}, #state{module = Module} = State) -> +handleInfo({gen_event_EXIT, Module, shutdown}, #state{module = Module} = State) -> {stop, normal, State}; -handle_info({gen_event_EXIT, Module, {'EXIT', {kill_me, [_KillerHWM, KillerReinstallAfter]}}}, +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. %% @@ -77,10 +59,9 @@ handle_info({gen_event_EXIT, Module, {'EXIT', {kill_me, [_KillerHWM, KillerReins exit(SinkPid, kill), _ = timer:apply_after(KillerReinstallAfter, lager_app, start_handler, [Sink, Module, Config]), {stop, normal, State}; -handle_info({gen_event_EXIT, Module, Reason}, #state{module = Module, +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 + 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); {error, _} -> @@ -88,19 +69,19 @@ handle_info({gen_event_EXIT, Module, Reason}, #state{module = Module, ok end, {noreply, State}; -handle_info(reinstall_handler, #state{module = Module, config = Config, sink = Sink} = State) -> +handleInfo(reinstall_handler, #state{module = Module, config = Config, sink = Sink} = State) -> install_handler(Sink, Module, Config), {noreply, State}; -handle_info({reboot, Sink}, State) -> +handleInfo({reboot, Sink}, State) -> _ = lager_app:boot(Sink), {noreply, State}; -handle_info(stop, State) -> +handleInfo(stop, State) -> {stop, normal, State}; -handle_info({'EXIT', _Pid, killed}, #state{module = Module, config = Config, sink = Sink} = State) -> +handleInfo({'EXIT', _Pid, killed}, #state{module = Module, config = Config, sink = Sink} = State) -> Tmr = application:get_env(lager, killer_reinstall_after, 5000), _ = timer:apply_after(Tmr, lager_app, start_handler, [Sink, Module, Config]), {stop, normal, State}; -handle_info(_Info, State) -> +handleInfo(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> @@ -128,15 +109,13 @@ install_handler2(Sink, Module, Config) -> eRum:update_loglevel_config(Sink), ok; {error, {fatal, Reason}} -> - ?INT_LOG(error, "Lager fatally failed to install handler ~p into" - " ~p, NOT retrying: ~p", [Module, Sink, Reason]), + ?INT_LOG(error, "Lager fatally failed to install handler ~p into ~p, NOT retrying: ~p", [Module, Sink, Reason]), %% tell ourselves to stop self() ! stop, ok; Error -> %% try to reinstall it later - ?INT_LOG(error, "Lager failed to install handler ~p into" - " ~p, retrying later : ~p", [Module, Sink, Error]), + ?INT_LOG(error, "Lager failed to install handler ~p into ~p, retrying later : ~p", [Module, Sink, Error]), erlang:send_after(5000, self(), reinstall_handler), ok end. diff --git a/src/watcher/rumHleWatcherSup.erl b/src/watcher/rumHleWatcherSup.erl index f25ef49..cdc440b 100644 --- a/src/watcher/rumHleWatcherSup.erl +++ b/src/watcher/rumHleWatcherSup.erl @@ -1,23 +1,47 @@ -%% @doc A supervisor for monitoring lager_handler_watcher processes. - -%% @private - -module(rumHleWatcherSup). -behaviour(supervisor). -%% API --export([start_link/0]). +-export([ + start_link/0 +]). -%% Callbacks -export([init/1]). start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). +% 主管的孩子被定义为孩子规格列表 。当主管启动时,将根据此列表从左到右依次启动子进程。主管终止时,它首先以相反的启动顺序从右到左终止其子进程。 +% sup_flags() = +% #{ +% strategy => strategy(), % optional one_for_one | one_for_all | rest_for_one | simple_one_for_one +% intensity => non_neg_integer(), % optional MaxR 周期时间内最大重启次数 +% period => pos_integer() % optional MaxT 重启时间周期 MaxT里重启次数大于MaxR +% } +% child_spec() = +% #{ +% id => child_id(), % mandatory Id用来内部标识子规范 +% start => mfargs(), % mandatory {M,F,A} +% restart => restart(), % optional permanent(总是重启) | transient(异常关闭会重启即关闭原因非 normal,shutdown,{shutdown,Term}) | temporary(不会重启) +% shutdown => shutdown(), % optional brutal_kill | infinity | integer +% type => worker(), % optional supervisor | worker +% modules => modules() % optional [Module] 假如子进程是supervisor、gen_server 或 gen_fsm,那么Module 是回调模块的名称;假如子进程是gen_event,那么Modules 应该是dynamic +% } init([]) -> - {ok, {{simple_one_for_one, 10, 60}, - [ - {lager_handler_watcher, {lager_handler_watcher, start_link, []}, - temporary, 5000, worker, [lager_handler_watcher]} - ]}}. + SupFlags = + #{ + strategy => simple_one_for_one, + intensity => 10, + period => 60 + }, + ChildSpecs = [ + #{ + id => rumHleWatcherSrv, + start => {rumHleWatcherSrv, start_link, []}, + restart => temporary, + shutdown => 5000, + type => worker, + modules => [rumHleWatcherSrv] + } + ], + {ok, {SupFlags, ChildSpecs}}. diff --git a/test/lager_crash_backend.erl b/test/lager_crash_backend.erl index ea44b8c..705fd3d 100644 --- a/test/lager_crash_backend.erl +++ b/test/lager_crash_backend.erl @@ -16,7 +16,7 @@ -module(lager_crash_backend). --include("rum.hrl"). +-include("eRum.hrl"). -behaviour(gen_event). diff --git a/test/lager_slow_backend.erl b/test/lager_slow_backend.erl index dc69a9e..2129698 100644 --- a/test/lager_slow_backend.erl +++ b/test/lager_slow_backend.erl @@ -4,7 +4,7 @@ -export([init/1, handle_call/2, handle_event/2, handle_info/2, terminate/2, code_change/3]). --include("rum.hrl"). +-include("eRum.hrl"). -record(state, { delay :: non_neg_integer() diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index d7d27cc..0ae8e34 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -25,7 +25,7 @@ -export([init/1, handle_call/2, handle_event/2, handle_info/2, terminate/2, code_change/3]). --include("rum.hrl"). +-include("eRum.hrl"). -define(TEST_SINK_NAME, '__lager_test_sink'). %% <-- used by parse transform -define(TEST_SINK_EVENT, '__lager_test_sink_lager_event'). %% <-- used by lager API calls and internals for gen_event diff --git a/test/lager_test_function_transform.erl b/test/lager_test_function_transform.erl index 16a1191..f3b0539 100644 --- a/test/lager_test_function_transform.erl +++ b/test/lager_test_function_transform.erl @@ -20,7 +20,7 @@ -module(lager_test_function_transform). --include("rum.hrl"). +-include("eRum.hrl"). -compile([{nowarn_deprecated_function, [{erlang, now, 0}]}]).