瀏覽代碼

ft: 代码修改

SisMaker 4 年之前
父節點
當前提交
494d1da1a7
共有 7 個檔案被更改,包括 36 行新增35 行删除
  1. +6
    -6
      README.md
  2. +4
    -3
      eRum.sample.config
  3. +2
    -2
      src/backend/rumBackendFile.erl
  4. +17
    -17
      src/eRum_app.erl
  5. +2
    -2
      test/lager_manager_killer_test.erl
  6. +1
    -1
      test/lager_rotate.erl
  7. +4
    -4
      test/lager_test_backend.erl

+ 6
- 6
README.md 查看文件

@ -95,8 +95,8 @@ include a list of sink names (without the `_lager_event` suffix) in `erl_opts`:
To be useful, sinks must be configured at runtime with backends.
In `app.config` for the project that requires lager, for example, extend the lager configuration to include
an `extra_sinks` tuple with backends (aka "handlers") and optionally `async_threshold` and
`async_threshold_window` values (see **Overload Protection**
an `extra_sinks` tuple with backends (aka "handlers") and optionally `asyncThreshold` and
`asyncThresholdWindow` values (see **Overload Protection**
below). If async values are not configured, no overload protection will be applied on that sink.
```erlang
@ -113,8 +113,8 @@ below). If async values are not configured, no overload protection will be appli
{extra_sinks, [
{audit_lager_event,
[{handlers, [{lager_file_backend, [{file, "sink1.log"}, {level, info}]}]},
{async_threshold, 500},
{async_threshold_window, 50}]
{asyncThreshold, 500},
{asyncThresholdWindow, 50}]
}]}
]}].
```
@ -205,8 +205,8 @@ will send all `error_logger` messages to `error_logger.log` file.
它轮询自己的邮箱大小,并根据邮箱大小在同步和异步之间切换消息传递。
```erlang
{async_threshold, 20},
{async_threshold_window, 5}
{asyncThreshold, 20},
{asyncThresholdWindow, 5}
```
这将使用异步消息传递,直到邮箱超过20条消息为止,此时将使用同步消息传递,并在大小减小为时切换回异步20 - 5 = 15。

+ 4
- 3
eRum.sample.config 查看文件

@ -17,10 +17,11 @@
%%*********************************************** 异步日志相关 *****************************************************
%% 异步切换到同步时模式gen_event邮箱的最大消息数,此值仅应用于默认接收器; 额外的接收器也可以自己配置。
{async_threshold, 20},
%%当gen_event 邮箱大小从 async_threshold 减小到 async_threshold-async_threshold_window 时,切换回异步模式。
%% 格式 integer() | undefined 当值为undefined 禁用此功能
{asyncThreshold, 20},
%%当gen_event 邮箱大小从 asyncThreshold 减小到 asyncThreshold-asyncThresholdWindow 时,切换回异步模式。
%% 此值仅适用于默认接收器。额外的接收器可以自己配置。
{async_threshold_window, 5},
{asyncThresholdWindow, 5},
%%*********************************************** handler与接收器(sink) *****************************************
%% 消息处理模块可以存在多个,[{Name, [Optins]}]=Handler() {lager_file_backend, [{file, "console.log"}, {level, info}]} 消息处理模块可以存在多个

+ 2
- 2
src/backend/rumBackendFile.erl 查看文件

@ -591,7 +591,7 @@ filesystem_test_() ->
ok = rumUtil:safe_application_load(lager),
ok = application:set_env(lager, handlers, [{lager_test_backend, info}]),
ok = application:set_env(lager, error_logger_redirect, false),
ok = application:set_env(lager, async_threshold, undefined),
ok = application:set_env(lager, asyncThreshold, undefined),
{ok, _TestDir} = rumUtil:create_test_dir(),
ok = eRum:start(),
%% race condition where lager logs its own start up
@ -1026,7 +1026,7 @@ trace_files_test_() ->
{lager_file_backend, Events}, [{module, ?MODULE}], notice
}
]),
ok = application:set_env(lager, async_threshold, undefined),
ok = application:set_env(lager, asyncThreshold, undefined),
ok = eRum:start(),
{Log, Debug, Events}
end,

+ 17
- 17
src/eRum_app.erl 查看文件

@ -7,8 +7,8 @@
-export([
start/0
, start/2
, boot/1
, stop/1
, doStart/1
, start_handler/3
, configure_sink/2
]).
@ -21,14 +21,14 @@ start() ->
start(_StartType, _StartArgs) ->
{ok, Pid} = eRum_sup:start_link(),
SavedHandlers = boot(),
_ = boot('__all_extra'),
_ = boot('__traces'),
_ = doStart('__all_extra'),
_ = doStart('__traces'),
clean_up_config_checks(),
{ok, Pid, SavedHandlers}.
boot() ->
%% Handle the default sink.
determine_async_behavior(?RumDefSink, application:get_env(lager, async_threshold, undefined), application:get_env(lager, async_threshold_window, undefined)),
tryStartAsyncer(?RumDefSink, rumUtil:get_env(?RumAppName, asyncThreshold, undefined), rumUtil:get_env(?RumAppName, asyncThresholdWindow, undefined)),
_ = maybe_install_sink_killer(?RumDefSink, application:get_env(lager, killer_hwm, undefined),
application:get_env(lager, killer_reinstall_after, undefined)),
@ -45,15 +45,15 @@ boot() ->
SavedHandlers.
boot('__traces') ->
doStart('__traces') ->
_ = rumUtil:trace_filter(none),
ok = add_configured_traces();
boot('__all_extra') ->
doStart('__all_extra') ->
configure_extra_sinks(application:get_env(lager, extra_sinks, []));
boot(?RumDefSink) -> boot();
boot(Sink) ->
doStart(?RumDefSink) -> boot();
doStart(Sink) ->
AllSinksDef = application:get_env(lager, extra_sinks, []),
boot_sink(Sink, lists:keyfind(Sink, 1, AllSinksDef)).
@ -68,21 +68,21 @@ stop(Handlers) ->
end, Handlers),
rumConfig:cleanup().
determine_async_behavior(_Sink, undefined, _Window) ->
tryStartAsyncer(_Sink, undefined, _Window) ->
ok;
determine_async_behavior(_Sink, Threshold, _Window) when not is_integer(Threshold) orelse Threshold < 0 ->
error_logger:error_msg("Invalid value for 'async_threshold': ~p~n", [Threshold]),
tryStartAsyncer(_Sink, Threshold, _Window) when not is_integer(Threshold) orelse Threshold < 0 ->
error_logger:error_msg("Invalid value for 'asyncThreshold': ~p~n", [Threshold]),
throw({error, bad_config});
determine_async_behavior(Sink, Threshold, undefined) ->
tryStartAsyncer(Sink, Threshold, undefined) ->
startThrottle(Sink, Threshold, erlang:trunc(Threshold * 0.2));
determine_async_behavior(_Sink, Threshold, Window) when not is_integer(Window) orelse Window > Threshold orelse Window < 0 ->
error_logger:error_msg("Invalid value for 'async_threshold_window': ~p~n", [Window]),
tryStartAsyncer(_Sink, Threshold, Window) when not is_integer(Window) orelse Window > Threshold orelse Window < 0 ->
error_logger:error_msg("Invalid value for 'asyncThresholdWindow': ~p~n", [Window]),
throw({error, bad_config});
determine_async_behavior(Sink, Threshold, Window) ->
tryStartAsyncer(Sink, Threshold, Window) ->
startThrottle(Sink, Threshold, Window).
startThrottle(Sink, Threshold, Window) ->
_ = supervisor:start_child(rumHandlerWatcherSup, [Sink, ?RumBackendThrottle, [Threshold, Window]]),
_ = supervisor:start_child(rumHWatcherSup, [Sink, ?RumBackendThrottle, [Threshold, Window]]),
ok.
start_handlers(_Sink, undefined) ->
@ -214,7 +214,7 @@ configure_sink(Sink, SinkDef) ->
rumConfig:initSink(Sink),
ChildId = rumUtil:make_internal_sink_name(Sink),
_ = supervisor:start_child(eRum_sup, {ChildId, {gen_event, start_link, [{local, Sink}]}, permanent, 5000, worker, dynamic}),
determine_async_behavior(Sink, proplists:get_value(async_threshold, SinkDef), proplists:get_value(async_threshold_window, SinkDef)),
tryStartAsyncer(Sink, proplists:get_value(asyncThreshold, SinkDef), proplists:get_value(asyncThresholdWindow, SinkDef)),
_ = maybe_install_sink_killer(Sink, proplists:get_value(killer_hwm, SinkDef),
proplists:get_value(killer_reinstall_after, SinkDef)),
start_handlers(Sink, proplists:get_value(handlers, SinkDef, [])),

+ 2
- 2
test/lager_manager_killer_test.erl 查看文件

@ -18,7 +18,7 @@ overload_test_() ->
KillerHWM = 10, % kill the manager if there are more than 10 pending logs
KillerReinstallAfter = 1000, % reinstall killer after 1 sec
application:set_env(lager, handlers, [{lager_slow_backend, [{delay, Delay}]}]),
application:set_env(lager, async_threshold, undefined),
application:set_env(lager, asyncThreshold, undefined),
application:set_env(lager, error_logger_redirect, true),
application:set_env(lager, killer_hwm, KillerHWM),
application:set_env(lager, killer_reinstall_after, KillerReinstallAfter),
@ -59,7 +59,7 @@ overload_alternate_sink_test_() ->
{handlers, [{lager_slow_backend, [{delay, Delay}]}]},
{killer_hwm, KillerHWM},
{killer_reinstall_after, KillerReinstallAfter},
{async_threshold, undefined}
{asyncThreshold, undefined}
]}]),
application:set_env(lager, error_logger_redirect, true),
ensure_started(lager),

+ 1
- 1
test/lager_rotate.erl 查看文件

@ -65,7 +65,7 @@ rotate_test_() ->
[{lager_file_backend, [{file, Sink}, {level, info}]}]}
]}]),
application:set_env(lager, error_logger_redirect, false),
application:set_env(lager, async_threshold, undefined),
application:set_env(lager, asyncThreshold, undefined),
eRum:start(),
timer:sleep(1000),
State

+ 4
- 4
test/lager_test_backend.erl 查看文件

@ -1758,7 +1758,7 @@ async_threshold_test_() ->
_ = error_logger:tty(false),
_ = application:stop(lager),
_ = application:stop(goldrush),
_ = application:unset_env(lager, async_threshold),
_ = application:unset_env(lager, asyncThreshold),
if
Reset ->
true = ets:delete(async_threshold_test),
@ -1777,8 +1777,8 @@ async_threshold_test_() ->
?assertEqual(true, ets:insert_new(async_threshold_test, {async_toggled, 0})),
_ = application:load(lager),
ok = application:set_env(lager, error_logger_redirect, false),
ok = application:set_env(lager, async_threshold, 2),
ok = application:set_env(lager, async_threshold_window, 1),
ok = application:set_env(lager, asyncThreshold, 2),
ok = application:set_env(lager, asyncThresholdWindow, 1),
ok = application:set_env(lager, handlers, [{?MODULE, info}]),
ok = lager:start(),
true
@ -1874,7 +1874,7 @@ high_watermark_test_() ->
application:load(lager),
application:set_env(lager, error_logger_redirect, true),
application:set_env(lager, handlers, [{lager_test_backend, info}]),
application:set_env(lager, async_threshold, undefined),
application:set_env(lager, asyncThreshold, undefined),
lager:start()
end,
fun(_) ->

Loading…
取消
儲存