[erlang-questions] is there any logging module for erlang?

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Thu Jun 12 08:03:47 CEST 2008


devdoer bird skrev:
> Thanks.
> I've seen the error logger,but I  need code something to make It support 
> ciritcal levelt setting(info/debug/warming/error)  and filterting(which 
> can define conditions control  whether one specific log record should be 
> printed )
>  
> What I need is more like log4cpp or python's logging module.
>  
> And I've stolen some logging code from couchdb and ejabbered ,but they 
> only support critical level setting .
>  
> Is any other logging package you guys know?

You can take a look at how mnesia does it.
Basically, it's this code in mnesia_lib.erl.

BR,
Ulf W


report_system_event({'EXIT', Reason}, Event) ->
     Mod = mnesia_monitor:get_env(event_module),
     case mnesia_sup:start_event() of
	{ok, Pid} ->
	    link(Pid),
	    gen_event:call(mnesia_event, Mod, Event, infinity),
	    unlink(Pid),

             %% We get an exit signal if server dies
             receive
                 {'EXIT', Pid, _Reason} ->
                     {error, {node_not_running, node()}}
             after 0 ->
		    gen_event:stop(mnesia_event),
                     ok
             end;

	Error ->
	    Msg = "Mnesia(~p): Cannot report event ~p: ~p (~p)~n",
	    error_logger:format(Msg, [node(), Event, Reason, Error])
     end;
report_system_event(_Res, _Event) ->
     ignore.

%% important messages are reported regardless of debug level
important(Format, Args) ->
     save({Format, Args}),
     report_system_event({mnesia_info, Format, Args}).

%% Warning messages are reported regardless of debug level
warning(Format, Args) ->
     save({Format, Args}),
     report_system_event({mnesia_warning, Format, Args}).

%% error messages are reported regardless of debug level
error(Format, Args) ->
     save({Format, Args}),
     report_system_event({mnesia_error, Format, Args}).

%% verbose messages are reported if debug level == debug or verbose
verbose(Format, Args) ->
     case mnesia_monitor:get_env(debug) of
	none ->    save({Format, Args});
	verbose -> important(Format, Args);
	debug ->   important(Format, Args);
	trace ->   important(Format, Args)
     end.

%% debug message are display if debug level == 2
dbg_out(Format, Args) ->
     case mnesia_monitor:get_env(debug) of
	none ->    ignore;
	verbose -> save({Format, Args});
	_ ->  report_system_event({mnesia_info, Format, Args})
     end.



More information about the erlang-questions mailing list