diff options
author | Siri Hansen <[email protected]> | 2018-05-14 17:01:15 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2018-05-21 17:43:53 +0200 |
commit | 033bcc2296d7d79c53d56798ab0ccf232f451574 (patch) | |
tree | 1737c8c27710aa3ea73844140a498f040ffa25c6 /lib/kernel | |
parent | ee9e7de41ec6b14857a2e32099cf76b425c3b778 (diff) | |
download | otp-033bcc2296d7d79c53d56798ab0ccf232f451574.tar.gz otp-033bcc2296d7d79c53d56798ab0ccf232f451574.tar.bz2 otp-033bcc2296d7d79c53d56798ab0ccf232f451574.zip |
Fix error_logger:tty/1 to turn on/off tty logging
This function earlier only added/removed the old error_logger_tty_h
report handler. Since it is mostly used for turning off logging to tty
in general, it now also checks the default logger handlers. It works
as follows:
tty(true):
* If default handler is logger_std_h of type standard_io, make sure it
has no 'error_logger_tty_false filter'.
* Else, add a new instance of logger_std_h with type standard_io with
id 'error_logger_tty_true'.
tty(false):
* Remove error_logger_tty_h report handler if it exists.
* Remove error_logger_tty_false logger handler if it exists.
* If default handler is logger_std_h of type standard_io, add a filter
named 'error_logger_tty_false', which stops all events.
Diffstat (limited to 'lib/kernel')
-rw-r--r-- | lib/kernel/src/error_logger.erl | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/kernel/src/error_logger.erl b/lib/kernel/src/error_logger.erl index 196c70d05f..6c3b308308 100644 --- a/lib/kernel/src/error_logger.erl +++ b/lib/kernel/src/error_logger.erl @@ -529,15 +529,36 @@ logfile(filename) -> Flag :: boolean(). tty(true) -> - case lists:member(error_logger_tty_h, which_report_handlers()) of - false -> - add_report_handler(error_logger_tty_h, []); - true -> - ignore - end, + _ = case lists:member(error_logger_tty_h, which_report_handlers()) of + false -> + case logger:get_handler_config(default) of + {ok,{logger_std_h,#{logger_std_h:=#{type:=standard_io}}}} -> + logger:remove_handler_filter(default, + error_logger_tty_false); + _ -> + logger:add_handler(error_logger_tty_true,logger_std_h, + #{filter_default=>stop, + filters=>?DEFAULT_HANDLER_FILTERS( + [beam,erlang,otp]), + formatter=>{?DEFAULT_FORMATTER, + ?DEFAULT_FORMAT_CONFIG}, + logger_std_h=>#{type=>standard_io}}) + end; + true -> + ok + end, ok; tty(false) -> - delete_report_handler(error_logger_tty_h). + delete_report_handler(error_logger_tty_h), + _ = logger:remove_handler(error_logger_tty_true), + _ = case logger:get_handler_config(default) of + {ok,{logger_std_h,#{logger_std_h:=#{type:=standard_io}}}} -> + logger:add_handler_filter(default,error_logger_tty_false, + {fun(_,_) -> stop end, ok}); + _ -> + ok + end, + ok. %%%----------------------------------------------------------------- -spec limit_term(term()) -> term(). |