[erlang-questions] SASL event handler problem
Ivan Ostres
iostres@REDACTED
Wed Dec 28 14:24:56 CET 2011
Hi all,
I am trying to make a custom SASL handler (gen_event) as follows:
-module(logger_event).
-behaviour(gen_event).
%% API
-export([start_link/0, register_with_logger/0, unregister_with_logger/0]).
%% gen_event callbacks
-export([init/1, handle_event/2, handle_call/2,
handle_info/2, terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
-record(state, {}).
start_link() ->
gen_event:start_link({local, ?SERVER}).
register_with_logger() ->
error_logger:add_report_handler(?MODULE).
init([]) ->
{ok, #state{}}.
handle_event({info_report,_Gleader, {Pid, Type, Report}}, State) ->
io:fwrite("INFO <~p> ~p ~p~n",[Pid, Type, Report]),
{ok, State};
handle_event(_Event, State) ->
io:fwrite("ERR unknown event ~p~n",[_Event]),
{ok, State}.
handle_call(_Request, State) ->
Reply = ok,
{ok, Reply, State}.
handle_info(_Info, State) ->
{ok, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
The problem is that I get different results for following cases:
Eshell V5.8.5 (abort with ^G)
(emacs@REDACTED)1> logger_event:start_link().
{ok,<0.39.0>}
(emacs@REDACTED)2> logger_event:register_with_logger().
ok
(emacs@REDACTED)3> error_logger:info_report("test1").
INFO <<0.37.0>> std_info "test1"
=INFO REPORT==== 28-Dec-2011::14:23:07 ===
test1
ok
(emacs@REDACTED)4> error_logger:info_report("test~p",2).
INFO <<0.37.0>> "test~p" 2
ok
(emacs@REDACTED)5>
The problem is that for std_info (error_logger:info_report/1) I get both
"my" version of log and standard log, while for
(error_logger:info_report/2) I get just my version of log.
Please help,
Ivan
More information about the erlang-questions
mailing list