[erlang-questions] logging with email output
Thu Nov 20 23:14:24 CET 2008
You can install a handler in error_logger.
I would suggest that your handler sends a message to a
process that in its turn generates the email. For one thing,
event handlers should do as little as possible, since they are
called sequentially in the error_logger process, and you probably
also want to be able to aggregate crash reports if you get many
at the same time.
How to send the actual email depends on what system you're
running on. With a working sendmail daemon, it's easy enough
to just generate an email and use os:cmd().
If your mail problem is more complex than that, perhaps erlmail
has a solution. It seems to have IMAP, SMTP and POP clients,
although I haven't tried it.
BTW, you may want to install a supervised event handler.
It can be pretty annoying if there's an exception in the handler
code, and the handler is quietly removed.
For that, you use gen_event:add_sup_handler/3
It's not written in the ref manual, but the way to do it
is to have a supervised process that installs the handler
on startup, and dies if it receives a gen_event_EXIT message.
This way, you get the same supervision strategy for your
handler as for processes.
2008/11/20 Adam Duston <>:
> In my Java application, I can use an email logging target with log4j
> and then, when an exception occurs, an email is politely delivered to
> my inbox. In my Erlang app, I'm logging info and errors using
> error_logger. I would like to be notified by email when one of my
> gen_servers trips badly enough to shutdown and get restarted by the
> supervisor. What is the idiomatic way to do this?
> Founder, 8 Planes
> Skype: aduston
> erlang-questions mailing list
More information about the erlang-questions