[erlang-questions] Extending error_logger
Serge Aleynikov
saleyn@REDACTED
Wed Aug 15 13:08:30 CEST 2007
Another alternative is the LAMA application in jungerl that offers
logging messages to syslog and provides debug / info / warning / error /
critical report types formatted in the same way as standard SASL
reports. It swaps default error_logger handler with its own.
Serge
Martin Bjorklund wrote:
> "denis" <dloutrein.lists@REDACTED> wrote:
>> Hi all,
>>
>> In my server, which is an OTP application using supervisor, gen_servers, .,
>> I use error_logger to log my information.
>> I would like to modify error_logger to add one kind of message: debug, link
>> error, debug, info.
>> Is there a clean way to add it to error_logger ? I dug the source, but not
>> find an easy way.
>> For now, the only solution I found is to implement my own logger
>> implementing all I need, and trap the events sent to error_logger by OTP
>> framework.
>> If I'm not mistaken, I can do it by writing my logger as event handler and
>> register it with error_logger: add_report_handler.
>> Am I one the good track ? Maybe there is a simpler method to do it ?
>
> You can use error_logger:error_report/1,2 for this, and make sure your
> handler formats these reports.
>
>> Note that I also want to store logs as text file. I think that write a new
>> error handler should do the job, like log_mf_h.
>
> IMO, the log_mf_h/rb approach in OTP was a mistake. The last 10 years
> or so we have always used text based error logs in all our projects.
> I think the standard log_mf_h should be replaced with disk_log_h which
> is in Jungerl.
>
> Anyway, since OTP R10B-9, you can use the disk_log_h and logger
> modules in jungerl w/o having to patch OTP. So, go to jungerl and
> grab the files lib/msc/src/disk_log_h.erl and logger.erl. (I just
> checked in my updated versions of these modules) Then, create the
> following module:
>
> -module(aa).
> -export([start_errlog/0, test/0]).
>
> start_errlog() ->
> Opts = [{name, logger},
> {file, "./elog"},
> {type, wrap},
> {format, external},
> {force_size, true},
> {size, {1024*1024, 5}}], % 5 files
> gen_event:add_sup_handler(
> error_logger,
> {disk_log_h, logger},
> disk_log_h:init(fun logger:form_no_progress/1, Opts)).
>
> test() ->
> error_logger:error_msg("testing ~p\n", [self()]).
>
>
> Start erlang:
>
> erl -pa jungerl/lib/msc/ebin/ -boot start_sasl
>
> 1> aa:start_errlog().
> ok
> 2> exit(whereis(overload), foo).
> true
> 3> aa:test().
> ok
>
> You should have some nicely formatted errors in elog.1. You can of
> course you halt logs and everything else supported by disk_log.
>
>
> Disclaimer: I haven't tested with R11.
>
>
>
> /martin
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list