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

Sergey A. n39052@REDACTED
Mon Nov 10 16:41:49 CET 2008


Hello.

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).

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:

{error, _, {_, _, [_, {_, _, {pg_error, [_, {code, "28000"}, {message,
Message}, _, _, _]}}, _, _, authentication_error]}}

all's OK, but working with messages like this is somewhat weary.

2) Decide the point where an error happen, and then call:

error_logger:error_msg({my_error, Reason})

In this case, the message to catch in gen_event module will be like this:

{error, _, {_, {my_error, Reason}, _}}

[+] That message is much more easy to operate.
[-] You need to call fun error_logger:error_msg/1 by hand (which
sometimes can involve some tricky code)

Is there any other way to catch errors in a centralised manner?

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

--
Sergey.



More information about the erlang-bugs mailing list