erlang/otp — pull request #359 by josevalim (2014-05-09 17:43:25+00:00)
Title: Send terms to error_logger from emulator on process termination

Hello folks,

This pull request changes the emulator to send terms to the error_logger instead of a string on process termination. There has been a discussion on the erlang-patches mailing list: http://erlang.org/pipermail/erlang-questions/2014-April/078875.html

Besides the benefits pointed out in the mailing list discussion, this patch allows custom error loggers (like lager) to change how those error messages are formatted.

Although this pull request only changes the process termination, it does add a `erts_send_error_term_to_logger` function which could be used by any future code.

This pull request is made of two commits:

1. The first one simply adds a `do_send_term_to_logger`, similar to the existing `do_send_to_logger`, and extracts all duplicate code to two separate functions (`do_allocate_logger_message` and `do_send_error_message`)

2. The second one changes the process termination logic to build a format string and send erlang terms as arguments to the logger

Regarding stacktraces, `add_stacktrace` invoked on process termination already performs truncation. For the error message, we keep the same io:format modified as proc_lib (i.e. we use `~p`).