diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2021-03-17 02:36:14 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2021-03-18 17:45:16 -0400 |
commit | 4f0574d1b2cbbd64501ec0468ad37b553a8a86de (patch) | |
tree | 3e94f7179b92b4548ee1dafac3d2d2856312ab10 | |
parent | 69ed2dab27302619cad774bbe72c92aaf5905c4b (diff) | |
download | couchdb-4f0574d1b2cbbd64501ec0468ad37b553a8a86de.tar.gz |
Fix error_logger reports for OTP >= 21
Starting with OTP 21 there is a new logging system, and we forgot to
add the legacy error logger handler for it. Without it `couch_log`
cannot emit gen_server, supervisor and other such system events.
Luckily, there is OTP support to enable legacy error_logger behavior and
that's what we're doing here. The `add_report_handler/1` call will
auto-start the `error_logger` app if needed, and it will also add an
`error_logger` handler to the global `logger` system.
We also keep the `gen_event:add_sup_handler/3` call, as that will
ensure we'll find out when `error_logger` dies so that
`couch_log_monitor` can restart everything.
Someday(TM) we'll write a proper log event handler for the new logger
and have nicely formatted structured logs, but it's better to do that
once we don't have to support OTP versions =< 20.
Issue: https://github.com/apache/couchdb/pull/3422
-rw-r--r-- | src/couch_log/src/couch_log_monitor.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/couch_log/src/couch_log_monitor.erl b/src/couch_log/src/couch_log_monitor.erl index ab0ae115f..96d7f3698 100644 --- a/src/couch_log/src/couch_log_monitor.erl +++ b/src/couch_log/src/couch_log_monitor.erl @@ -37,11 +37,24 @@ start_link() -> gen_server:start_link(?MODULE, [], []). +% OTP_RELEASE defined in OTP >= 21 only +-ifdef(OTP_RELEASE). + +init(_) -> + % see https://erlang.org/doc/man/error_logger.html#add_report_handler-1 + ok = error_logger:add_report_handler(?HANDLER_MOD), + ok = gen_event:add_sup_handler(error_logger, ?HANDLER_MOD, []), + {ok, nil}. + +-else. + init(_) -> error_logger:start(), ok = gen_event:add_sup_handler(error_logger, ?HANDLER_MOD, []), {ok, nil}. +-endif. + terminate(_, _) -> ok. |