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

Dave Smith <>
Thu Jun 12 17:11:42 CEST 2008


Actually, I was referring to the dbg module in runtime_tools. Also the
sys module in stdlib can be helpful when poking around OTP processes.

>From my perspective, Erlang has a very different take on logging due
to the fact that you can easily hop on a live system via a shell and
introspect without stopping. Other languages/platforms don't really
have the idea of being able to hook into the live system with a shell
and poke around. Obviously, this can be dangerous, but at the same
time it's something you simply MUST be able to do if you seriously
want your system to stay up.

There's always a place for error and/or transaction logging, of
course. But for the vast majority of "debug" logs, I find that tracing
can do the trick and help me work out exactly what's happening with my
system without requiring me to litter the code with io:format/2.
Perhaps I'm in the minority, but that's been my experience with
erlang. :)

D.

On Thu, Jun 12, 2008 at 9:02 AM, devdoer bird <> wrote:
> you mean "erlang:trace(PidSpec, How, FlagList)" ,"erlang:trace_pattern(MFA,
> MatchSpec, FlagList)" ?
>
> 2008/6/12, Dave Smith <>:
>>
>> I think it might be worth noting that Erlang provides some powerful
>> runtime tracing tools. Where in python/java/c++ I would litter my code
>> with logging statements to keep track of what's happening where, I
>> find myself not needing that as much, since I can simply throw a trace
>> on the things I'm interested in, when/if there are problem. That's why
>> (I think) erlang is so light on logging subsystems.
>>
>> Just a thought.. :)
>>
>> D.
>>
>> 2008/6/12 devdoer bird <>:
>> > thanks but it also doesn't support log filtering.
>> > Here is the explanation of filtering from python manual.
>> > "
>> >
>> > Filters can be used by Handlers and Loggers for more sophisticated
>> > filtering
>> > than is provided by levels. The base filter class only allows events
>> > which
>> > are below a certain point in the logger hierarchy. For example, a filter
>> > initialized with "A.B" will allow events logged by loggers "A.B",
>> > "A.B.C",
>> > "A.B.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If initialized with
>> > the
>> > empty string, all events are passed.
>> >
>> > class Filter( [name])
>> > Returns an instance of the Filter class. If name is specified, it names
>> > a
>> > logger which, together with its children, will have its events allowed
>> > through the filter. If no name is specified, allows every event.
>> >
>> > filter( record)
>> > Is the specified record to be logged? Returns zero for no, nonzero for
>> > yes.
>> > If deemed appropriate, the record may be modified in-place by this
>> > method.
>> >
>> > "
>> >  I think I need write one by myself.
>> > Thank you .
>> >
>> >
>> > 2008/6/12, Ulf Wiger (TN/EAB) <>:
>> >>
>> >> 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.
>> >
>> >
>> > _______________________________________________
>> > erlang-questions mailing list
>> > 
>> > http://www.erlang.org/mailman/listinfo/erlang-questions
>> >
>
>



More information about the erlang-questions mailing list