Hi:I wonder whether any logging module for erlang exists,like python's logging module which support :critical level setting ,filtering ,diffrent handlers (stream handler,socket handler,ram handler,file handler...).Thanks a lot!
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
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.
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]) |
filter( | record) |
Just a thought.. :)
D.
2008/6/12 devdoer bird <devd...@gmail.com>:
>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.
> 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.
Logging is useful to detect errors in the first place (see the other
thread where the bug wasn't noticed until the logfiles were read).
tracing is useful if it's known that there's an error, but it's not
clear that where that error actually is.
Bye,NAR
--
"Beware of bugs in the above code; I have only proved it correct, not
tried it."
I understand what you want. Having used log4j myself, I've tried to
find something similar for my own. Eventually, I had to write it
myself. This module only supports file logs but it also have support
for multiple log levels, including critical (fatal) level, different
loggers for different modules, size-based rotation...etc.
I haven't shared the project yet, as it has some shortcomings I need
to address before releasing it, however, I'll announce it soon. I hope
this is what you're look for. I'll keep you updated.
Best regards,
Ahmed Al-Issaei
2008/6/12 devdoer bird <devd...@gmail.com>:
For a while now I've been planning to update that contrib with the newer
version of lama that supports pluggable logging destinations of two types:
1. Single-line logger (e.g. syslog) that formats the error
reports in one line
2. Multi-line logger (e.g. console) that writes the report to
a destination similar to how SASL does it.
Will try to push this version out when I find some time. Maybe within a
month or so.
Serge
> ------------------------------------------------------------------------
Sure. Let me clean up my code and then post it somewhere in the
internet. I'll do that within the coming week.
Best regards,
Ahmed Al-Issaei
You can find this logging module in:
http://code.google.com/p/log4erl/. Please let me know if it didn't
work. You can find instructions for using it in "README.txt" in the
downloaded file.
Best regards,
Ahmed Al-Issaei