summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2021-03-17 02:36:14 -0400
committerNick Vatamaniuc <vatamane@apache.org>2021-03-17 10:33:26 -0400
commit23c6436310e537c5dc59c770e38e2ef1b1385f5f (patch)
tree24785ddb59d7c17a071fa3d72904d38770906924
parent7e0661bf8af7a37b183aef225d68fce2c50fa815 (diff)
downloadcouchdb-fix-error-logger-in-otp-gt-21.tar.gz
Fix error_logger reports for OTP >= 21fix-error-logger-in-otp-gt-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.erl13
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.