[erlang-questions] The best way to write user-friendly log from an OTP application

Martin Bjorklund mbj@REDACTED
Tue Nov 11 08:49:03 CET 2008


Hi,

"Sergey A." <n39052@REDACTED> wrote:
> I'm looking for the best way to write a plain text log containing the
> reasons of some well-known errors happening in my OTP applications.
> The log should be like this:
> 
> --------------------------------8<--------------------------------
> [2008-11-6 23:0:53] Such an ip and port already in use.
> [2008-11-6 23:1:45] Login or password is wrong
> --------------------------------8<--------------------------------
> 
> Here is what I'm doing just now to achieve this behaviour:
> 
> I use a gen_event module connected to the error_logger as a handler to
> catch all the errors (and it is where I write my log).

You might want to look at logger.erl and disk_log_h.erl in jungerl.

> But there are two mutually exclusive ways to denote that error has happened:
> 
> 1) Do nothing. Just let the crash happen. A process will crash and
> you'll get a huuuuge message in your gen_event handler:

[...]

> 2) Decide the point where an error happen, and then call:
> 
> error_logger:error_msg({my_error, Reason})

[...]

> What of the ways listed above is the best in your opinon and why?

As always, it depends on the application.  In our system, we separate
the normal error_logger log from logs aimed for the end user.

We use the error_logger to print crashes and other internal errors.
This log *should* always be empty, otherwise we have a bug in our
system.  We use the logger.erl and disk_log_h.erl modules for this
log.

Then we have a set of logs for the user (audit logs etc.) and for
these we use explicit calls in the code.


/martin



More information about the erlang-questions mailing list