[erlang-questions] SASL event handler problem

Ivan Ostres iostres@REDACTED
Wed Dec 28 15:25:40 CET 2011


Hi Siri,

thanks for the answer - I definitely mixed info_report with info_msg :-(.

BR,
Ivan

On 12/28/11 3:10 PM, Siri Hansen wrote:
> Hi Ivan!
>
> The arguments for error_logger:info_report/2 shall be Type and Report, 
> not a format string and data. The documentation says:
>
> "info_report(Type, Report) -> ok
>
> Types:
>
> Type = any()
> Report = report()
>
> Sends a user defined information report event to the error logger. An 
> event handler to handle the event is supposed to have been added. *The 
> event is ignored by the standard event handler*.
>
> It is recommended that Report follows the same structure as for 
> info_report/1."
>
> In fact, if you give 'std_info' as Type to the call, then the standard 
> event handler will handle the report (equivalent to 
> error_logger:info_report/1), else it will be ignored.
>
> What you might be looking for is actually error_logger:info_msg/2 - 
> which takes a format string and data.
>
> Regards
> /siri
>
>
> 2011/12/28 Ivan Ostres <iostres@REDACTED <mailto:iostres@REDACTED>>
>
>     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
>     _______________________________________________
>     erlang-questions mailing list
>     erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>     http://erlang.org/mailman/listinfo/erlang-questions
>
>




More information about the erlang-questions mailing list