diff options
author | Siri Hansen <[email protected]> | 2018-06-05 19:22:16 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2018-06-08 14:42:52 +0200 |
commit | 6f753ccf5178a809a7a26f692249bdfb5985335e (patch) | |
tree | 34e53144479968d3e2ba864c9d8ffe37e2965454 | |
parent | 437d46f34b141af8e6361bfc5b2fe8dab9d88efd (diff) | |
download | otp-6f753ccf5178a809a7a26f692249bdfb5985335e.tar.gz otp-6f753ccf5178a809a7a26f692249bdfb5985335e.tar.bz2 otp-6f753ccf5178a809a7a26f692249bdfb5985335e.zip |
[logger] Don't use error_logger:warning_map/0
The warning map was added to allow backwards compatiblity with
error_logger event handlers that were not prepared to receive warning
reports. error_logger still uses this internally, if legacy error
logger event handlers are installed. But Logger does not use it for
new Logger handlers.
-rw-r--r-- | lib/kernel/src/error_logger.erl | 53 | ||||
-rw-r--r-- | lib/kernel/src/logger.erl | 2 |
2 files changed, 17 insertions, 38 deletions
diff --git a/lib/kernel/src/error_logger.erl b/lib/kernel/src/error_logger.erl index 9238029cef..4b3922cdd7 100644 --- a/lib/kernel/src/error_logger.erl +++ b/lib/kernel/src/error_logger.erl @@ -169,16 +169,25 @@ do_log(_Level,_Msg,_Meta) -> -spec notify(logger:level(), msg_tag(), any(), any(), map()) -> 'ok'. notify(Level,Tag0,FormatOrType0,ArgsOrReport,#{pid:=Pid0,gl:=GL,?MODULE:=My}) -> - Tag = fix_warning_tag(Level,Tag0), + {Tag,FormatOrType} = maybe_map_warnings(Level,Tag0,FormatOrType0), Pid = case maps:get(emulator,My,false) of true -> emulator; _ -> Pid0 end, - FormatOrType = fix_warning_type(Level,FormatOrType0), gen_event:notify(?MODULE,{Tag,GL,{Pid,FormatOrType,ArgsOrReport}}). -%% This is to fix the case when the client has explicitly added the -%% error logger tag and type in metadata, and not checked the warning map. +%% For backwards compatibility with really old even handlers, check +%% the warning map and update tag and type. +maybe_map_warnings(warning,Tag,FormatOrType) -> + case error_logger:warning_map() of + warning -> + {Tag,FormatOrType}; + Level -> + {fix_warning_tag(Level,Tag),fix_warning_type(Level,FormatOrType)} + end; +maybe_map_warnings(_,Tag,FormatOrType) -> + {Tag,FormatOrType}. + fix_warning_tag(error,warning_msg) -> error; fix_warning_tag(error,warning_report) -> error_report; fix_warning_tag(info,warning_msg) -> info_msg; @@ -263,29 +272,10 @@ warning_report(Report) -> Report :: report(). warning_report(Type, Report) -> - Level = error_logger:warning_map(), - {Tag, NType} = case Level of - info -> - if - Type =:= std_warning -> - {info_report, std_info}; - true -> - {info_report, Type} - end; - warning -> - {warning_report, Type}; - error -> - if - Type =:= std_warning -> - {error_report, std_error}; - true -> - {error_report, Type} - end - end, - logger:log(Level, + logger:log(warning, #{label=>{?MODULE,warning_report}, report=>Report}, - meta(Tag,NType)). + meta(warning_report,Type)). %%----------------------------------------------------------------- %% This function provides similar functions as error_msg for @@ -304,20 +294,11 @@ warning_msg(Format) -> Data :: list(). warning_msg(Format, Args) -> - Level = error_logger:warning_map(), - Tag = case Level of - warning -> - warning_msg; - info -> - info_msg; - error -> - error - end, - logger:log(Level, + logger:log(warning, #{label=>{?MODULE,warning_msg}, format=>Format, args=>Args}, - meta(Tag)). + meta(warning_msg)). %%----------------------------------------------------------------- %% This function should be used for information reports. Events diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl index f18f101930..f8661ea228 100644 --- a/lib/kernel/src/logger.erl +++ b/lib/kernel/src/logger.erl @@ -775,8 +775,6 @@ get_logger_env() -> %%%----------------------------------------------------------------- %%% Internal -do_log(warning,Msg,Meta) -> - do_log_1(error_logger:warning_map(),Msg,Meta); do_log(Level,Msg,Meta) -> do_log_1(Level,Msg,Meta). |