今日学习用OTP构建系统的警报管理,
首先进行配置错误记录器
[
{sasl,
[
{sasl_error_logger, false},
{error_logger_mf_dir, "/code/erlang/erlangstudy"},
{error_logger_mf_maxbytes, 10485760},
{error_logger_mf_maxfiles, 10}
]
}
].
警报处理器gen_event的回调代码
-module(my_alarm_handler).
-behaviour(gen_event).
-export([init/1, code_change/3, handle_event/2, handle_call/2, handle_info/2, terminate/2]).
init(Args) ->
io:format("*** my_alarm_handler init:~p~n", [Args]),
{ok, 0}.
handle_event({set_alarm, tooHot}, N) ->
error_logger:error_msg("*** Tell the Engineer to turn on the fan~n"),
{ok, N + 1};
handle_event({clear_alarm, tooHot}, N) ->
error_logger:error_msg("*** Danger over. Turn off the fan~n"),
{ok, N};
handle_event(Event, N) ->
io:format("*** unmatched event:~p~n", [Event]),
{ok, N}.
handle_call(_Request, N) ->
Reply = N, {ok, Reply, N}.
handle_info(_Info, N) ->
{ok, N}.
terminate(_Reason, _N) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
错误记录器方面相关内容配置完成了,并得到成功运行截图
启动系统,生成一个警报,安装警报处理器,再生成一个警报执行代码截图