aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common_test/src/cth_log_redirect.erl4
-rw-r--r--lib/common_test/test_server/ts_run.erl8
-rw-r--r--lib/debugger/src/dbg_wx_trace.erl6
-rwxr-xr-xlib/diameter/bin/diameterc6
-rw-r--r--lib/diameter/src/Makefile5
-rw-r--r--lib/diameter/src/app.sed41
-rw-r--r--lib/diameter/src/base/diameter_codec.erl12
-rw-r--r--lib/diameter/src/base/diameter_config.erl14
-rw-r--r--lib/diameter/src/base/diameter_gen.erl19
-rw-r--r--lib/diameter/src/base/diameter_internal.hrl5
-rw-r--r--lib/diameter/src/base/diameter_lib.erl15
-rw-r--r--lib/diameter/src/base/diameter_service.erl20
-rw-r--r--lib/diameter/src/compiler/diameter_make.erl6
-rw-r--r--lib/diameter/src/diameter.app.src17
-rw-r--r--lib/diameter/src/transport/diameter_tcp.erl4
-rw-r--r--lib/diameter/test/diameter_app_SUITE.erl14
-rw-r--r--lib/diameter/test/diameter_traffic_SUITE.erl6
-rw-r--r--lib/diameter/test/diameter_watchdog_SUITE.erl9
-rw-r--r--lib/edoc/src/edoc_layout.erl2
-rw-r--r--lib/erl_docgen/src/docgen_otp_specs.erl4
-rw-r--r--lib/hipe/doc/src/hipe_app.xml62
-rw-r--r--lib/kernel/doc/src/error_logger.xml35
-rw-r--r--lib/kernel/doc/src/kernel_app.xml117
-rw-r--r--lib/kernel/doc/src/logger.xml883
-rw-r--r--lib/kernel/doc/src/logger_arch.pngbin32377 -> 32407 bytes
-rw-r--r--lib/kernel/doc/src/logger_chapter.xml843
-rw-r--r--lib/kernel/doc/src/logger_disk_log_h.xml20
-rw-r--r--lib/kernel/doc/src/logger_filters.xml164
-rw-r--r--lib/kernel/doc/src/logger_formatter.xml148
-rw-r--r--lib/kernel/doc/src/logger_std_h.xml21
-rw-r--r--lib/kernel/doc/src/part.xml11
-rw-r--r--lib/kernel/src/application_controller.erl20
-rw-r--r--lib/kernel/src/error_logger.erl77
-rw-r--r--lib/kernel/src/kernel.app.src5
-rw-r--r--lib/kernel/src/logger.erl279
-rw-r--r--lib/kernel/src/logger_backend.erl4
-rw-r--r--lib/kernel/src/logger_config.erl46
-rw-r--r--lib/kernel/src/logger_disk_log_h.erl412
-rw-r--r--lib/kernel/src/logger_formatter.erl129
-rw-r--r--lib/kernel/src/logger_h_common.erl165
-rw-r--r--lib/kernel/src/logger_h_common.hrl55
-rw-r--r--lib/kernel/src/logger_internal.hrl15
-rw-r--r--lib/kernel/src/logger_server.erl96
-rw-r--r--lib/kernel/src/logger_std_h.erl348
-rw-r--r--lib/kernel/test/Makefile1
-rw-r--r--lib/kernel/test/error_logger_SUITE.erl20
-rw-r--r--lib/kernel/test/kernel.spec1
-rw-r--r--lib/kernel/test/logger_SUITE.erl374
-rw-r--r--lib/kernel/test/logger_bench_SUITE.erl500
-rw-r--r--lib/kernel/test/logger_bench_SUITE_data/Emakefile1
-rw-r--r--lib/kernel/test/logger_bench_SUITE_data/lager_helper.erl73
-rw-r--r--lib/kernel/test/logger_disk_log_h_SUITE.erl508
-rw-r--r--lib/kernel/test/logger_env_var_SUITE.erl415
-rw-r--r--lib/kernel/test/logger_formatter_SUITE.erl201
-rw-r--r--lib/kernel/test/logger_legacy_SUITE.erl19
-rw-r--r--lib/kernel/test/logger_simple_h_SUITE.erl22
-rw-r--r--lib/kernel/test/logger_std_h_SUITE.erl496
-rw-r--r--lib/kernel/test/logger_test_lib.erl6
-rw-r--r--lib/public_key/doc/src/public_key.xml57
-rw-r--r--lib/public_key/doc/src/using_public_key.xml4
-rw-r--r--lib/sasl/doc/src/error_logging.xml15
-rw-r--r--lib/sasl/doc/src/sasl_app.xml24
-rw-r--r--lib/sasl/src/sasl.erl16
-rw-r--r--lib/sasl/test/sasl_report_SUITE.erl2
-rw-r--r--lib/snmp/src/compile/snmpc.erl66
-rw-r--r--lib/snmp/test/snmp_compiler_test.erl23
-rw-r--r--lib/snmp/test/snmp_test_data/OTP14196-MIB.mib47
-rw-r--r--lib/ssl/doc/src/ssl.xml12
-rw-r--r--lib/ssl/src/ssl.erl12
-rw-r--r--lib/ssl/src/ssl_cipher.erl28
-rw-r--r--lib/ssl/test/ssl_basic_SUITE.erl25
-rw-r--r--lib/stdlib/doc/src/io.xml17
-rw-r--r--lib/stdlib/src/gen_event.erl4
-rw-r--r--lib/stdlib/src/gen_fsm.erl4
-rw-r--r--lib/stdlib/src/gen_server.erl4
-rw-r--r--lib/stdlib/src/gen_statem.erl6
-rw-r--r--lib/stdlib/src/io_lib_pretty.erl2
-rw-r--r--lib/stdlib/src/maps.erl9
-rw-r--r--lib/stdlib/src/proc_lib.erl2
-rw-r--r--lib/stdlib/src/supervisor.erl6
-rw-r--r--lib/stdlib/src/supervisor_bridge.erl4
-rw-r--r--lib/stdlib/src/uri_string.erl206
-rw-r--r--lib/stdlib/test/Makefile3
-rw-r--r--lib/stdlib/test/io_SUITE.erl22
-rw-r--r--lib/stdlib/test/maps_SUITE.erl4
-rw-r--r--lib/stdlib/test/proc_lib_SUITE.erl10
-rw-r--r--lib/stdlib/test/property_test/uri_string_recompose.erl260
-rw-r--r--lib/stdlib/test/uri_string_SUITE.erl261
-rw-r--r--lib/stdlib/test/uri_string_property_test_SUITE.erl7
89 files changed, 4401 insertions, 3570 deletions
diff --git a/lib/common_test/src/cth_log_redirect.erl b/lib/common_test/src/cth_log_redirect.erl
index 68742ab0ee..99c484de48 100644
--- a/lib/common_test/src/cth_log_redirect.erl
+++ b/lib/common_test/src/cth_log_redirect.erl
@@ -136,7 +136,7 @@ start_log_handler() ->
init([]) ->
{ok, #eh_state{log_func = tc_log_async}}.
-log(#{msg:={report,Msg},meta:=#{domain:=[beam,erlang,otp,sasl]}}=Log,Config) ->
+log(#{msg:={report,Msg},meta:=#{domain:=[otp,sasl]}}=Log,Config) ->
case whereis(sasl_sup) of
undefined ->
ok; % sasl application is not started
@@ -162,7 +162,7 @@ log(#{msg:={report,Msg},meta:=#{domain:=[beam,erlang,otp,sasl]}}=Log,Config) ->
do_log(add_log_category(Log,sasl),Config)
end
end;
-log(#{meta:=#{domain:=[beam,erlang,otp]}}=Log,Config) ->
+log(#{meta:=#{domain:=[otp]}}=Log,Config) ->
do_log(add_log_category(Log,error_logger),Config);
log(#{meta:=#{domain:=_}},_) ->
ok;
diff --git a/lib/common_test/test_server/ts_run.erl b/lib/common_test/test_server/ts_run.erl
index 5dbbaca916..7e12b9652c 100644
--- a/lib/common_test/test_server/ts_run.erl
+++ b/lib/common_test/test_server/ts_run.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -411,9 +411,9 @@ make_common_test_args(Args0, Options0, _Vars) ->
end,
ConfigFiles = [{config,[filename:join(ConfigPath,File)
|| File <- get_config_files()]}],
- io_lib:format("~100000p",[[{abort_if_missing_suites,true} |
- Args0++Trace++Cover++Logdir++
- ConfigFiles++Options++TimeTrap]]).
+ io_lib:format("~0p",[[{abort_if_missing_suites,true} |
+ Args0++Trace++Cover++Logdir++
+ ConfigFiles++Options++TimeTrap]]).
to_list(X) when is_atom(X) ->
atom_to_list(X);
diff --git a/lib/debugger/src/dbg_wx_trace.erl b/lib/debugger/src/dbg_wx_trace.erl
index 505d53005f..25f32ca7e7 100644
--- a/lib/debugger/src/dbg_wx_trace.erl
+++ b/lib/debugger/src/dbg_wx_trace.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2008-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2008-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -518,8 +518,8 @@ gui_cmd({user_command, Cmd}, State) ->
gui_cmd({edit, {Var, Value}}, State) ->
Window = dbg_wx_trace_win:get_window(State#state.win),
Val = case State#state.strings of
- [] -> dbg_wx_win:to_string("~999999lp",[Value]);
- [str_on] -> dbg_wx_win:to_string("~999999tp",[Value])
+ [] -> dbg_wx_win:to_string("~0lp",[Value]);
+ [str_on] -> dbg_wx_win:to_string("~0tp",[Value])
end,
case dbg_wx_win:entry(Window, "Edit variable", Var, {term, Val}) of
cancel ->
diff --git a/lib/diameter/bin/diameterc b/lib/diameter/bin/diameterc
index 3dbd238c19..4d415ece78 100755
--- a/lib/diameter/bin/diameterc
+++ b/lib/diameter/bin/diameterc
@@ -4,7 +4,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -78,8 +78,8 @@ compile(#argv{file = File, options = Opts, output = Out}) ->
error_msg(diameter_make:format_error(Reason), []),
1
catch
- error: Reason ->
- error_msg("ERROR: ~p~n ~p", [Reason, erlang:get_stacktrace()]),
+ error: Reason: Stack ->
+ error_msg("ERROR: ~p~n ~p", [Reason, Stack]),
2
end.
diff --git a/lib/diameter/src/Makefile b/lib/diameter/src/Makefile
index 3af856f63e..f78a163591 100644
--- a/lib/diameter/src/Makefile
+++ b/lib/diameter/src/Makefile
@@ -149,7 +149,7 @@ gen/$(DICT_YRL).erl: compiler/$(DICT_YRL).yrl
$(ERLC) -Werror -o $(@D) $<
# Generate the app file.
-$(APP_TARGET): $(APP_SRC) ../vsn.mk modules.mk app.sed
+$(APP_TARGET): $(APP_SRC) ../vsn.mk modules.mk
$(gen_verbose) \
M=`echo $(notdir $(APP_MODULES)) | tr ' ' ,`; \
C=`echo $(COMPILER_MODULES) | tr ' ' ,`; \
@@ -160,8 +160,7 @@ $(APP_TARGET): $(APP_SRC) ../vsn.mk modules.mk app.sed
-e "s;%COMPILER%;$$C;" \
-e "s;%INFO%;$$I;" \
-e "s;%REGISTERED%;$$R;" \
- $< \
- | sed -f app.sed > $@
+ $< > $@
$(APPUP_TARGET): $(APPUP_SRC) ../vsn.mk
$(vsn_verbose) \
diff --git a/lib/diameter/src/app.sed b/lib/diameter/src/app.sed
deleted file mode 100644
index dd3806f5f1..0000000000
--- a/lib/diameter/src/app.sed
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# %CopyrightBegin%
-#
-# Copyright Ericsson AB 2014-2016. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# %CopyrightEnd%
-
-#
-# Generate runtime_dependencies from applications to avoid having to
-# specify the same application more than once.
-#
-
-/{runtime_dependencies,/b v
-/{[-a-z]*, "[0-9.]*"}/!b
-/{vsn,/b
-
-/%%/!H
-s/{\([^,]*\)[^}]*}/\1/g
-s/%%/%,/
-b
-
-:v
-
-p
-x
-s/\n//
-s/%//g
-s/\n */ /g
-s/{\([^,]*\), "\([^"]*"\)}/"\1-\2/g
diff --git a/lib/diameter/src/base/diameter_codec.erl b/lib/diameter/src/base/diameter_codec.erl
index 2dd2c906a2..5c0a24cdf6 100644
--- a/lib/diameter/src/base/diameter_codec.erl
+++ b/lib/diameter/src/base/diameter_codec.erl
@@ -92,8 +92,8 @@ encode(Mod, Opts, #diameter_packet{} = Pkt) ->
%% count encode errors.
?LOG(encode_error, {Reason, Stack, H}),
exit({?MODULE, encode, T});
- error: Reason ->
- T = {Reason, diameter_lib:get_stacktrace()},
+ error: Reason: Stack ->
+ T = {Reason, diameter_lib:stacktrace(Stack)},
?LOG(encode_error, T),
exit({?MODULE, encode, T})
end;
@@ -134,8 +134,8 @@ enc(_, Opts, #diameter_packet{msg = [#diameter_header{} = Hdr | As]}
Eid:32,
Bin/binary>>}
catch
- error: Reason ->
- exit({Reason, diameter_lib:get_stacktrace(), Hdr})
+ error: Reason: Stack ->
+ exit({Reason, diameter_lib:stacktrace(Stack), Hdr})
end;
enc(Mod, Opts, #diameter_packet{header = Hdr0, msg = Msg} = Pkt) ->
@@ -179,14 +179,14 @@ enc(Mod, Opts, #diameter_packet{header = Hdr0, msg = Msg} = Pkt) ->
Eid:32,
Bin/binary>>}
catch
- error: Reason ->
+ error: Reason: Stack ->
Hdr = Hdr0#diameter_header{cmd_code = Code,
application_id = Aid,
is_request = RB,
is_proxiable = PB,
is_error = EB,
is_retransmitted = TB},
- exit({Reason, diameter_lib:get_stacktrace(), Hdr})
+ exit({Reason, diameter_lib:stacktrace(Stack), Hdr})
end.
%% values/1
diff --git a/lib/diameter/src/base/diameter_config.erl b/lib/diameter/src/base/diameter_config.erl
index 90a9282349..36ae4c2276 100644
--- a/lib/diameter/src/base/diameter_config.erl
+++ b/lib/diameter/src/base/diameter_config.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -633,8 +633,8 @@ opt(service, {K, F})
Nodes ->
is_list(Nodes) orelse {error, Nodes}
catch
- E:R ->
- {error, {E, R, ?STACK}}
+ E:R:Stack ->
+ {error, {E, R, Stack}}
end;
opt(service, {sequence, {H,N}}) ->
@@ -651,8 +651,8 @@ opt(service = S, {sequence = K, F}) ->
V ->
{error, V}
catch
- E:R ->
- {error, {E, R, ?STACK}}
+ E:R:Stack ->
+ {error, {E, R, Stack}}
end;
opt(transport, {transport_module, M}) ->
@@ -932,8 +932,8 @@ cb(M,F) ->
try M:F() of
V -> V
catch
- E: Reason ->
- ?THROW({callback, E, Reason, ?STACK})
+ E: Reason: Stack ->
+ ?THROW({callback, E, Reason, Stack})
end.
%% call/1
diff --git a/lib/diameter/src/base/diameter_gen.erl b/lib/diameter/src/base/diameter_gen.erl
index 93ebe57685..d110a3015e 100644
--- a/lib/diameter/src/base/diameter_gen.erl
+++ b/lib/diameter/src/base/diameter_gen.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -76,8 +76,7 @@ encode_avps(Name, Vals, #{module := Mod} = Opts) ->
?LINE,
{Reason, Name, Vals, Mod}),
erlang:error(list_to_tuple(Reason ++ [Name]));
- error: Reason ->
- Stack = erlang:get_stacktrace(),
+ error: Reason: Stack ->
diameter_lib:log({encode, failure},
?MODULE,
?LINE,
@@ -555,8 +554,8 @@ dec(Data, Name, AvpName, Type, Mod, Dict, Fmt, Failed, Opts, Avp) ->
catch
throw: {?MODULE, T} ->
decode_error(Failed, Fmt, T, Avp);
- error: Reason ->
- decode_error(Failed, Reason, Name, Mod, Opts, Avp)
+ error: Reason: Stack ->
+ decode_error(Failed, Reason, Stack, Name, Mod, Opts, Avp)
end.
%% dec_AVP/7
@@ -623,19 +622,19 @@ set(none, Avp, _Name) ->
set(_, Avp, Rec) ->
Avp#diameter_avp{value = Rec}.
-%% decode_error/6
+%% decode_error/7
%%
%% Error when decoding a non-grouped AVP.
-decode_error(true, _, _, _, _, Avp) ->
+decode_error(true, _, _, _, _, _, Avp) ->
Avp;
-decode_error(false, Reason, Name, Mod, Opts, Avp) ->
- Stack = diameter_lib:get_stacktrace(),
+decode_error(false, Reason, Stack, Name, Mod, Opts, Avp) ->
+ Z = diameter_lib:stacktrace(Stack),
diameter_lib:log(decode_error,
?MODULE,
?LINE,
- {Reason, Name, Avp#diameter_avp.name, Mod, Stack}),
+ {Reason, Name, Avp#diameter_avp.name, Mod, Z}),
case Reason of
{'DIAMETER', 5014 = RC, _} ->
%% Length error communicated from diameter_types or a
diff --git a/lib/diameter/src/base/diameter_internal.hrl b/lib/diameter/src/base/diameter_internal.hrl
index a0f4a8567d..4a678643c2 100644
--- a/lib/diameter/src/base/diameter_internal.hrl
+++ b/lib/diameter/src/base/diameter_internal.hrl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -35,9 +35,6 @@
%% A corresponding error when failure is the best option.
-define(ERROR(T), erlang:error({T, ?MODULE, ?LINE})).
-%% Failure reports always get a stack trace.
--define(STACK, erlang:get_stacktrace()).
-
%% Warning report for unexpected messages in various processes.
-define(UNEXPECTED(F,A),
diameter_lib:warning_report(unexpected, {?MODULE, F, A})).
diff --git a/lib/diameter/src/base/diameter_lib.erl b/lib/diameter/src/base/diameter_lib.erl
index 1c1ea42cb5..edd9d5a4ce 100644
--- a/lib/diameter/src/base/diameter_lib.erl
+++ b/lib/diameter/src/base/diameter_lib.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
time/1,
eval/1,
eval_name/1,
- get_stacktrace/0,
+ stacktrace/1,
ipaddr/1,
spawn_opts/2,
wait/1,
@@ -42,16 +42,13 @@
log/4]).
%% ---------------------------------------------------------------------------
-%% # get_stacktrace/0
+%% # stacktrace/1
%% ---------------------------------------------------------------------------
%% Return a stacktrace with a leading, potentially large, argument
-%% list replaced by an arity. Trace on stacktrace/0 to see the
+%% list replaced by an arity. Trace on stacktrace/1 to see the
%% original.
-get_stacktrace() ->
- stacktrace(erlang:get_stacktrace()).
-
stacktrace([{M,F,A,L} | T]) when is_list(A) ->
[{M, F, length(A), L} | T];
stacktrace(L) ->
@@ -268,8 +265,8 @@ ipaddr(Addr) ->
try
ip(Addr)
catch
- error: _ ->
- erlang:error({invalid_address, erlang:get_stacktrace()})
+ error: _: Stack ->
+ erlang:error({invalid_address, Stack})
end.
%% Already a tuple: ensure non-negative integers of the right size.
diff --git a/lib/diameter/src/base/diameter_service.erl b/lib/diameter/src/base/diameter_service.erl
index cbe66ef27a..77d184cfc7 100644
--- a/lib/diameter/src/base/diameter_service.erl
+++ b/lib/diameter/src/base/diameter_service.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -808,8 +808,8 @@ remotes(F) ->
error_report(invalid_return, share_peers, F),
[]
catch
- E:R ->
- ?LOG(failure, {E, R, F, diameter_lib:get_stacktrace()}),
+ E:R:S ->
+ ?LOG(failure, {E, R, F, diameter_lib:stacktrace(S)}),
error_report(failure, share_peers, F),
[]
end.
@@ -1146,11 +1146,11 @@ peer_cb(App, F, A) ->
mod_state(App#diameter_app.alias, ModS),
true
catch
- E:R ->
+ E:R:S ->
%% Don't include arguments since a #diameter_caps{} strings
%% from the peer, which could be anything (especially, large).
[Mod|X] = App#diameter_app.module,
- ?LOG(failure, {E, R, Mod, F, diameter_lib:get_stacktrace()}),
+ ?LOG(failure, {E, R, Mod, F, diameter_lib:stacktrace(S)}),
error_report(failure, F, {Mod, F, A ++ X}),
false
end.
@@ -1376,9 +1376,9 @@ cm([#diameter_app{alias = Alias} = App], Req, From, Svc) ->
?LOG(invalid_return, {ModX, handle_call, Args, T}),
invalid
catch
- E: Reason ->
+ E: Reason: S ->
ModX = App#diameter_app.module,
- Stack = diameter_lib:get_stacktrace(),
+ Stack = diameter_lib:stacktrace(S),
?LOG(failure, {E, Reason, ModX, handle_call, Stack}),
failure
end;
@@ -1585,10 +1585,10 @@ pick_peer(Local,
?LOG(invalid_return, {ModX, pick_peer, T}),
false
catch
- E: Reason when M ->
+ E: Reason: Stack when M ->
ModX = App#diameter_app.module,
- Stack = diameter_lib:get_stacktrace(),
- ?LOG(failure, {E, Reason, ModX, pick_peer, Stack}),
+ Z = diameter_lib:stacktrace(Stack),
+ ?LOG(failure, {E, Reason, ModX, pick_peer, Z}),
false
end.
diff --git a/lib/diameter/src/compiler/diameter_make.erl b/lib/diameter/src/compiler/diameter_make.erl
index eae40dbafd..03cfc03edc 100644
--- a/lib/diameter/src/compiler/diameter_make.erl
+++ b/lib/diameter/src/compiler/diameter_make.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2016. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -271,6 +271,6 @@ make(File, Opts, Dict, Mode) ->
try
diameter_codegen:from_dict(File, Dict, Opts, Mode)
catch
- error: Reason ->
- erlang:error({Reason, Mode, erlang:get_stacktrace()})
+ error: Reason: Stack ->
+ erlang:error({Reason, Mode, Stack})
end.
diff --git a/lib/diameter/src/diameter.app.src b/lib/diameter/src/diameter.app.src
index 9a6e47006b..18202f033e 100644
--- a/lib/diameter/src/diameter.app.src
+++ b/lib/diameter/src/diameter.app.src
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -28,14 +28,21 @@
]},
{registered, [%REGISTERED%]},
{applications, [
- {stdlib, "2.4"}, {kernel, "3.2"}%, {erts, "6.4"}
- %% {syntax-tools, "1.6,18"}
- %% {runtime-tools, "1.8.16"}
- %, {ssl, "6.0"}
+ stdlib,
+ kernel
+ %, ssl
+ %, syntax-tools
+ %, runtime-tools
]},
{env, []},
{mod, {diameter_app, []}},
{runtime_dependencies, [
+ "erts-10.0",
+ "stdlib-2.4",
+ "kernel-3.2",
+ "ssl-9.0"
+ %, "syntax-tools-1.6.18"
+ %, "runtime-tools-1.8.16"
]}
%%
%% Note that ssl is only required if configured on TCP transports,
diff --git a/lib/diameter/src/transport/diameter_tcp.erl b/lib/diameter/src/transport/diameter_tcp.erl
index a8639baa11..681d273d07 100644
--- a/lib/diameter/src/transport/diameter_tcp.erl
+++ b/lib/diameter/src/transport/diameter_tcp.erl
@@ -716,7 +716,7 @@ tls_handshake(_, false, S) ->
tls(connect, Sock, Opts) ->
ssl:connect(Sock, Opts);
tls(accept, Sock, Opts) ->
- ssl:ssl_accept(Sock, Opts).
+ ssl:handshake(Sock, Opts). %% assume no handshake option
%% recv/2
%%
@@ -839,7 +839,7 @@ start_fragment_timer(#transport{timeout = Tmo} = S) ->
accept(ssl, LSock) ->
case ssl:transport_accept(LSock) of
{ok, Sock} ->
- {ssl:ssl_accept(Sock), Sock};
+ ssl:handshake(Sock);
{error, _} = No ->
No
end;
diff --git a/lib/diameter/test/diameter_app_SUITE.erl b/lib/diameter/test/diameter_app_SUITE.erl
index 71256020f5..ef4a28d3f4 100644
--- a/lib/diameter/test/diameter_app_SUITE.erl
+++ b/lib/diameter/test/diameter_app_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2015. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -208,9 +208,9 @@ xref(Config) ->
CTmods = CTmods -- Mods,
%% Ensure that runtime modules only call other runtime modules, or
- %% applications declared as in runtime_dependencies in the app
- %% file. Note that the declared application versions are ignored
- %% since we only know what we can see now.
+ %% applications declared in runtime_dependencies in the app file.
+ %% The declared application versions are ignored since we only
+ %% know what we see now.
[] = lists:filter(fun(M) -> not lists:member(app(M), Deps) end,
RTdeps -- Mods).
@@ -261,8 +261,12 @@ app(Mod) ->
case code:which(Mod) of
preloaded ->
"erts";
+ Reason when is_atom(Reason) ->
+ error({Reason, Mod});
Path ->
- unversion(lists:nth(3, lists:reverse(filename:split(Path))))
+ %% match to identify an unexpectedly short path
+ {_, _, [_,_,_|_] = Split} = {Mod, Path, filename:split(Path)},
+ unversion(lists:nth(3, lists:reverse(Split)))
end.
add_application(XRef, App) ->
diff --git a/lib/diameter/test/diameter_traffic_SUITE.erl b/lib/diameter/test/diameter_traffic_SUITE.erl
index c224f9a27e..434aef01dd 100644
--- a/lib/diameter/test/diameter_traffic_SUITE.erl
+++ b/lib/diameter/test/diameter_traffic_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -1924,8 +1924,8 @@ compile_and_load() ->
{module, nas4005} = code:load_binary(nas4005, "nas4005", Bin),
true
catch
- E:R ->
- {E, R, erlang:get_stacktrace()}
+ E:R:Stack ->
+ {E, R, Stack}
end.
here() ->
diff --git a/lib/diameter/test/diameter_watchdog_SUITE.erl b/lib/diameter/test/diameter_watchdog_SUITE.erl
index 39c4f051a5..f3f168e671 100644
--- a/lib/diameter/test/diameter_watchdog_SUITE.erl
+++ b/lib/diameter/test/diameter_watchdog_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -638,10 +638,9 @@ run1([F|A]) ->
apply(?MODULE, F, A),
ok
catch
- E:R ->
- S = erlang:get_stacktrace(),
- ?WARN("~p", [{A, E, R, S}]),
- S
+ E:R:Stack ->
+ ?WARN("~p", [{A, E, R, Stack}]),
+ Stack
end.
%% jitter/2
diff --git a/lib/edoc/src/edoc_layout.erl b/lib/edoc/src/edoc_layout.erl
index baa147410b..47ff7b21fc 100644
--- a/lib/edoc/src/edoc_layout.erl
+++ b/lib/edoc/src/edoc_layout.erl
@@ -1193,6 +1193,8 @@ ot_name(Es, T) ->
{atom,0,list_to_atom(Atom)},T]};
"tuple" when T =:= [] ->
{type,0,tuple,any};
+ "map" when T =:= [] ->
+ {type,0,map,any};
Atom ->
{type,0,list_to_atom(Atom),T}
end.
diff --git a/lib/erl_docgen/src/docgen_otp_specs.erl b/lib/erl_docgen/src/docgen_otp_specs.erl
index 9f2b401f93..311ec1471a 100644
--- a/lib/erl_docgen/src/docgen_otp_specs.erl
+++ b/lib/erl_docgen/src/docgen_otp_specs.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -658,6 +658,8 @@ ot_name(Es, T) ->
{atom,0,list_to_atom(Atom)},T]};
"tuple" when T =:= [] ->
{type,0,tuple,any};
+ "map" when T =:= [] ->
+ {type,0,map,any};
Atom ->
{type,0,list_to_atom(Atom),T}
end.
diff --git a/lib/hipe/doc/src/hipe_app.xml b/lib/hipe/doc/src/hipe_app.xml
index fc42ecd97d..4d40db086c 100644
--- a/lib/hipe/doc/src/hipe_app.xml
+++ b/lib/hipe/doc/src/hipe_app.xml
@@ -35,6 +35,14 @@
<app>HiPE</app>
<appsummary>The HiPE Application</appsummary>
<description>
+ <note>
+ <p>
+ HiPE and execution of HiPE compiled code only have limited support by
+ the OTP team at Ericsson. The OTP team only does limited maintenance
+ of HiPE and does not actively develop HiPE. HiPE is mainly supported
+ by the HiPE team at Uppsala University.
+ </p>
+ </note>
<p>
The normal way to native-compile an Erlang module using HiPE is to include the atom native
in the Erlang compiler options, as in:</p>
@@ -108,7 +116,7 @@
queue when the reference was created will be bypassed, as they
cannot possibly contain the reference. HiPE currently has an
optimization similar this, but it is not guaranteed to
- bypass all messages. In the worst case scenario it, cannot
+ bypass all messages. In the worst case scenario, it cannot
bypass any messages at all.
</p>
<p>
@@ -117,21 +125,55 @@
</p>
</item>
+ <tag>Garbage collection after BIFs</tag>
+ <item>
+ <p>
+ The condition for determining whether a garbage collection
+ is needed or not has changed in later releases. HiPE has not
+ been updated regarding this which may cause premature garbage
+ collections after BIF calls.
+ </p>
+ </item>
+
</taglist>
</section>
<section>
<title>Stability Issues</title>
<taglist>
- <tag>Not yielding in <c>receive</c> statements</tag>
+ <tag>Not checking reduction count on function returns</tag>
<item>
- <p>HiPE will not yield in <c>receive</c> statements where
- appropriate. If a process have lots of signals in its signal
- queue and execute a HiPE compiled <c>receive</c> statement,
- the scheduler thread performing the execution may be stuck
- in the <c>receive</c> statement for a very long time. This
- can in turn cause various severe issues such as for example
- prevent the runtime system from being able to release
- memory.
+ <p>
+ BEAM checks the reduction count and schedules out the executing
+ process if needed both when calling a function and when returning
+ from a function call that was not called using a tail call.
+ HiPE only checks the reduction count when calling a function.
+ </p>
+ <p>
+ The runtime system might need to schedule out a process
+ in order to reclaim memory. If the process isn't scheduled
+ out soon after the process has entered this state, memory
+ consumption will quickly grow. Maintaining this state is also
+ quite expensive performance wise.
+ </p>
+ <p>
+ Processes executing code that performs large recursions and
+ produce data after returning from recursive calls may have to
+ be scheduled out when returning from a function call. Since
+ HiPE does not check reductions on returns, processes executing
+ such HiPE compiled code may cause huge peeks in memory
+ consumption as well as severe performance degradation.
+ </p>
+ </item>
+
+ <tag>Not bumping appropriate amount of reductions in <c>receive</c> statements</tag>
+ <item>
+ <p>
+ The process signaling improvements made in ERTS version
+ 10.0 moved potentially significant amounts of work into the
+ receive statement from other places. In order to account for
+ this work, the reduction count should be bumped on the
+ executing process. Reductions are not bumped when entering
+ the <c>receive</c> statement from HiPE compiled code.
</p>
</item>
</taglist>
diff --git a/lib/kernel/doc/src/error_logger.xml b/lib/kernel/doc/src/error_logger.xml
index f418aa5bbe..27fb1488c7 100644
--- a/lib/kernel/doc/src/error_logger.xml
+++ b/lib/kernel/doc/src/error_logger.xml
@@ -305,14 +305,22 @@ ok</pre>
<type name="open_error"/>
<desc>
<p>Enables or disables printout of standard events to a file.</p>
- <p>This is done by adding or deleting the standard event handler
- for output to file. Thus, calling this function overrides
- the value of the Kernel <c>error_logger</c> configuration
- parameter.</p>
- <p>Enabling file logging can be used together with calling
- <c>tty(false)</c>, to have a silent system where
- all standard events are logged to a file only.
- Only one log file can be active at a time.</p>
+ <p>This is done by adding or deleting
+ the <c>error_logger_file_h</c> event handler, and thus
+ indirectly adding <c>error_logger</c> as a Logger
+ handler.</p>
+ <p>Notice that this function does not manipulate the Logger
+ configuration directly, meaning that if the default Logger
+ handler is already logging to a file, this function can
+ potentially cause logging to a second file.</p>
+ <p>This function is useful as a shortcut during development
+ and testing, but must not be used in a production
+ system. See
+ section <seealso marker="logger_chapter">Logging</seealso>
+ in the Kernel User's Guide, and
+ the <seealso marker="logger"><c>logger(3)</c></seealso>
+ manual page for information about how to configure Logger
+ for live systems.</p>
<p><c>Request</c> is one of the following:</p>
<taglist>
<tag><c>{open, <anno>Filename</anno>}</c></tag>
@@ -344,9 +352,14 @@ ok</pre>
<p>Enables (<c><anno>Flag</anno> == true</c>) or disables
(<c><anno>Flag</anno> == false</c>) printout of standard events
to the terminal.</p>
- <p>This is done by adding or deleting the standard event handler
- for output to the terminal. Thus, calling this function overrides
- the value of the Kernel <c>error_logger</c> configuration parameter.</p>
+ <p>This is done by manipulating the Logger configuration. The
+ function is useful as a shortcut during development and
+ testing, but must not be used in a production system. See
+ section <seealso marker="logger_chapter">Logging</seealso>
+ in the Kernel User's Guide, and
+ the <seealso marker="logger"><c>logger(3)</c></seealso>
+ manual page for information about how to configure Logger
+ for live systems.</p>
</desc>
</func>
<func>
diff --git a/lib/kernel/doc/src/kernel_app.xml b/lib/kernel/doc/src/kernel_app.xml
index e2a6d30249..3914226a3e 100644
--- a/lib/kernel/doc/src/kernel_app.xml
+++ b/lib/kernel/doc/src/kernel_app.xml
@@ -54,9 +54,9 @@
<p>Two standard logger handlers are defined in
the Kernel application. These are described in the
<seealso marker="logger_chapter">Kernel User's Guide</seealso>,
- and in <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>
+ and in the <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>
and <seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c>
- </seealso>.</p>
+ </seealso> manual pages.</p>
</section>
<section>
@@ -166,57 +166,71 @@
</item>
<tag><marker id="logger"/><c>logger = [Config]</c></tag>
<item>
- <p>Specifies how <seealso marker="logger"><c>logger</c></seealso> should be
- configured.</p>
- <p>For more details and examples, see the <seealso marker="logger_chapter#logger">
- Configuration</seealso> section in the <seealso marker="logger_chapter">
- Logger User's Guide</seealso>.
- </p>
+ <p>Specifies the configuration
+ for <seealso marker="logger">Logger</seealso>, except the
+ primary log level, which is specified
+ with <seealso marker="#logger_level"><c>logger_level</c></seealso>,
+ and the compatibility
+ with <seealso marker="sasl:error_logging">SASL Error
+ Logging</seealso>, which is specified
+ with <seealso marker="#logger_sasl_compatible">
+ <c>logger_sasl_compatible</c></seealso>.</p>
+ <p>The <c>logger </c> parameter is described in
+ section <seealso marker="logger_chapter#logger_parameter">
+ Logging</seealso> in the Kernel User's Guide.</p>
</item>
<tag><marker id="logger_level"/><c>logger_level = Level</c></tag>
<item>
- <p><c>Level = emergency | alert | critical | error | warning |
- notice | info | debug</c></p>
- <p>This parameter specifies which log levels to log. The
- specified level, and all levels that are more severe, will
- be logged.</p>
- <p>The default value is <c>info</c>.</p>
- <p>To change the global log level at run-time, use
- <seealso marker="logger#set_logger_config/2">
- <c>logger:set_logger_config(level, error)</c></seealso>.</p>
+ <p>Specifies the primary log level for Logger. Log events with
+ the same, or a more severe level, pass through the primary
+ log level check. See
+ section <seealso marker="logger_chapter">Logging</seealso>
+ in the Kernel User's Guide for more information about Logger
+ and log levels.</p>
+ <p><c>Level = emergency | alert | critical | error | warning |
+ notice | info | debug | all | none</c></p>
+ <p>To change the primary log level at runtime, use
+ <seealso marker="logger#set_primary_config/2">
+ <c>logger:set_primary_config(level, Level)</c></seealso>.</p>
+ <p>Defaults to <c>info</c>.</p>
</item>
<tag><marker id="logger_sasl_compatible"/>
- <c>logger_sasl_compatible = boolean()</c></tag>
- <item>
- <p>If this parameter is set to true, then the <c>default</c> logger handler
- will not log any progress-, crash-, or supervisor reports.
- If the SASL application is started,
- these log events will be sent to a second handler instance
- named <c>sasl</c>, according to values of the SASL
- configuration parameter <c>sasl_error_logger</c>
- and <c>sasl_errlog_type</c>, see
- <seealso marker="sasl:sasl_app#deprecated_error_logger_config">sasl(6)
- </seealso></p>
- <p>The default value is <c>false</c>.</p>
- <p>See chapter <seealso marker="logger_chapter#compatibility">Backwards
- compatibility with error_logger</seealso> for more
- information about handling of the so called SASL reports.</p>
- <note><p>This configuration option only effects the <c>default</c>
- and <c>sasl</c> handler. Any other handlers are uneffected.</p></note>
- </item>
- <tag><marker id="logger_progress_reports"/>
- <c>logger_progress_reports = stop | log</c></tag>
- <item>
- <p>If <c>logger_sasl_compatible = false</c>,
- then <c>logger_progress_reports</c> specifies if progress
- reports from <c>supervisor</c>
- and <c>application_controller</c> shall be logged by the
- default logger.</p>
- <p>If <c>logger_sasl_compatible = true</c>,
- then <c>logger_progress_reports</c> is ignored.</p>
- <p>The default value is <c>stop</c></p>
- <note><p>This configuration option only effects the <c>default</c>
- and <c>sasl</c> handler. Any other handlers are uneffected.</p></note>
+ <c>logger_sasl_compatible = true | false</c></tag>
+ <item>
+ <p>Specifies if Logger behaves backwards compatible with the
+ SASL error logging functionality from releases prior to
+ Erlang/OTP 21.0.</p>
+ <p>If this parameter is set to <c>true</c>, the default Logger
+ handler does not log any progress-, crash-, or supervisor
+ reports. If the SASL application is then started, it adds a
+ Logger handler named <c>sasl</c>, which logs these events
+ according to values of the SASL configuration
+ parameter <c>sasl_error_logger</c>
+ and <c>sasl_errlog_type</c>.</p>
+ <p>See section
+ <seealso marker="sasl:sasl_app#deprecated_error_logger_config">
+ Deprecated Error Logger Event Handlers and
+ Configuration</seealso> in the sasl(6) manual page for
+ information about the SASL configuration parameters.</p>
+ <p>See section <seealso marker="sasl:error_logging">SASL Error
+ Logging</seealso> in the SASL User's Guide, and
+ section <seealso marker="logger_chapter#compatibility">Backwards
+ Compatibility with error_logger</seealso> in the Kernel
+ User's Guide for information about the SASL error logging
+ functionality, and how Logger can be backwards compatible
+ with this.</p>
+ <p>Defaults to <c>false</c>.</p>
+ <note>
+ <p>If this parameter is set to <c>true</c>,
+ <c>sasl_errlog_type</c> indicates that progress reports
+ shall be logged, and the configured primary log level
+ is <c>notice</c> or more severe, then SASL automatically
+ sets the primary log level to <c>info</c>. That is, this
+ setting can potentially overwrite the value of the Kernel
+ configuration parameter <c>logger_level</c>. This is to
+ allow progress reports, which have log level <c>info</c>,
+ to be forwarded to the handlers.</p>
+ </note>
</item>
<tag><c>global_groups = [GroupTuple]</c></tag>
<item>
@@ -269,9 +283,8 @@
</item>
<tag><c>inet_parse_error_log = silent</c></tag>
<item>
- <p>If set, no
- <c>logger</c> messages are generated when erroneous
- lines are found and skipped in the various Inet configuration
+ <p>If set, no log events are issued when erroneous lines are
+ found and skipped in the various Inet configuration
files.</p>
</item>
<tag><c>inetrc = Filename</c></tag>
@@ -494,7 +507,7 @@ MaxT = TickTime + TickTime / 4</code>
<seealso marker="logger_std_h#type"><c>logger_std_h</c></seealso>
to the same value. Example:
<code type="none">
-erl -kernel logger '[{handler,default,logger_std_h,#{logger_std_h=>#{type=>{file,"/tmp/erlang.log"}}}}]'
+erl -kernel logger '[{handler,default,logger_std_h,#{config=>#{type=>{file,"/tmp/erlang.log"}}}}]'
</code>
</item>
<tag><c>error_logger_format_depth</c></tag>
diff --git a/lib/kernel/doc/src/logger.xml b/lib/kernel/doc/src/logger.xml
index 911eb158da..7f35a5d752 100644
--- a/lib/kernel/doc/src/logger.xml
+++ b/lib/kernel/doc/src/logger.xml
@@ -33,73 +33,150 @@
<file>logger.xml</file>
</header>
<module>logger</module>
- <modulesummary>API module for logging in Erlang/OTP.</modulesummary>
+ <modulesummary>API module for Logger, the standard logging facility
+ in Erlang/OTP.</modulesummary>
<description>
- <p>
- This module is the main API for logging in Erlang/OTP. It
- contains functions that allow applications to use a single log
- API and the system to manage those log events independently. Use
- the <seealso marker="#emergency-1">API functions</seealso> or the log
- <seealso marker="#macros">macros</seealso> to log events. For instance,
- to log a new error event:</p>
- <code>
-?LOG_ERROR("error happened because: ~p",[Reason]). %% With macro
-logger:error("error happened because: ~p",[Reason]). %% Without macro
- </code>
- <p>This log event is then sent to the configured log handlers which
- by default means that it is be printed to the console. If you want
- your systems logs to be printed to a file instead of the console you
- must configure the default handler to do so. The simplest way is
- to include the following in your <seealso marker="config"><c>sys.config</c></seealso>.</p>
+ <p>This module implements the main API for logging in
+ Erlang/OTP. To create a log event, use the
+ <seealso marker="#logging_API">API functions</seealso> or the
+ log
+ <seealso marker="#macros">macros</seealso>, for example:</p>
+ <code>
+?LOG_ERROR("error happened because: ~p", [Reason]). % With macro
+logger:error("error happened because: ~p", [Reason]). % Without macro
+ </code>
+ <p>To configure the Logger backend,
+ use <seealso marker="kernel_app#logger">Kernel configuration
+ parameters</seealso>
+ or <seealso marker="#configuration_API">configuration
+ functions</seealso> in the Logger API.</p>
+
+ <p>By default, the Kernel application installs one log handler at
+ system start. This handler is named <c>default</c>. It receives
+ and processes standard log events produced by the Erlang runtime
+ system, standard behaviours and different Erlang/OTP
+ applications. The log events are by default printed to the
+ terminal.</p>
+ <p>If you want your systems logs to be printed to a file instead,
+ you must configure the default handler to do so. The simplest
+ way is to include the following in
+ your <seealso marker="config"><c>sys.config</c></seealso>:</p>
<code>
[{kernel,
[{logger,
- [{handler,default,logger_std_h,
- #{logger_std_h=>#{type=>{file,"path/to/file.log"}}}}]}]}].
+ [{handler, default, logger_std_h,
+ #{config => #{type => {file, "path/to/file.log"}}}}]}]}].
</code>
<p>
For more information about:
</p>
<list type="bulleted">
- <item>how to use the API,
- see <seealso marker="logger_chapter">the User's Guide</seealso>.</item>
- <item>how to configure Logger,
- see the <seealso marker="logger_chapter#configuration">Configuration</seealso>
+ <item>the Logger facility in general, see
+ the <seealso marker="logger_chapter">User's
+ Guide</seealso>.</item>
+ <item>how to configure Logger, see
+ the <seealso marker="logger_chapter#configuration">Configuration</seealso>
section in the User's Guide.</item>
- <item>the convinience macros in logger.hrl,
- see <seealso marker="#macros">the macro section</seealso>.</item>
- <item>what the builtin formatter can do,
- see <seealso marker="logger_formatter">logger_formatter</seealso>.</item>
- <item>what the builtin handlers can do,
+ <item>the built-in handlers,
see <seealso marker="logger_std_h">logger_std_h</seealso> and
<seealso marker="logger_disk_log_h">logger_disk_log_h</seealso>.</item>
- <item>what builtin filters are available,
+ <item>the built-in formatter,
+ see <seealso marker="logger_formatter">logger_formatter</seealso>.</item>
+ <item>built-in filters,
see <seealso marker="logger_filters">logger_filters</seealso>.</item>
</list>
</description>
<datatypes>
<datatype>
- <name name="level"/>
+ <name name="primary_config"/>
<desc>
- <p>The severity level for the message to be logged.</p>
+ <p>Primary configuration data for Logger. The following
+ default values apply:</p>
+ <list>
+ <item><c>level => info</c></item>
+ <item><c>filter_default => log</c></item>
+ <item><c>filters => []</c></item>
+ </list>
</desc>
</datatype>
<datatype>
- <name name="log_event"/>
+ <name name="handler_config"/>
<desc>
- <p></p>
+ <p>Handler configuration data for Logger. The following
+ default values apply:</p>
+ <list>
+ <item><c>level => all</c></item>
+ <item><c>filter_default => log</c></item>
+ <item><c>filters => []</c></item>
+ <item><c>formatter => {logger_formatter, DefaultFormatterConfig</c>}</item>
+ </list>
+ <p>In addition to these, the following fields are
+ automatically inserted by Logger, values taken from the
+ two first parameters
+ to <seealso marker="#add_handler-3"><c>add_handler/3</c></seealso>:</p>
+ <list>
+ <item><c>id => HandlerId</c></item>
+ <item><c>module => Module</c></item>
+ </list>
+ <p>Handler specific configuration data is inserted by the
+ handler callback itself, in a sub structure associated with
+ the field named <c>config</c>.</p>
+ <p>See the <seealso marker="logger_formatter#type-config">
+ <c>logger_formatter(3)</c></seealso> manual page for
+ information about the default configuration for this
+ formatter.</p>
</desc>
</datatype>
<datatype>
- <name name="report"/>
+ <name name="filter"/>
<desc>
- <p></p>
+ <p>A filter which can be installed as a handler filter, or as
+ a primary filter in Logger.</p>
</desc>
</datatype>
<datatype>
- <name name="msg_fun"/>
+ <name name="filter_arg"/>
+ <desc>
+ <p>The second argument to the filter fun.</p>
+ </desc>
+ </datatype>
+ <datatype>
+ <name name="filter_id"/>
+ <desc>
+ <p>A unique identifier for a filter.</p>
+ </desc>
+ </datatype>
+ <datatype>
+ <name name="filter_return"/>
+ <desc>
+ <p>The return value from the filter fun.</p>
+ </desc>
+ </datatype>
+ <datatype>
+ <name name="formatter_config"/>
+ <desc>
+ <p>Configuration data for the
+ formatter. See <seealso marker="logger_formatter">
+ <c>logger_formatter(3)</c></seealso>
+ for an example of a formatter implementation.</p>
+ </desc>
+ </datatype>
+ <datatype>
+ <name name="handler_id"/>
+ <desc>
+ <p>A unique identifier for a handler instance.</p>
+ </desc>
+ </datatype>
+ <datatype>
+ <name name="level"/>
+ <desc>
+ <p>The severity level for the message to be logged.</p>
+ </desc>
+ </datatype>
+ <datatype>
+ <name name="log_event"/>
<desc>
<p></p>
</desc>
@@ -117,7 +194,7 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
<p>When a log macro is used, Logger also inserts location
information:</p>
<list>
- <item><c>mfa => {?MODULE,?FUNCTION_NAME,?FUNCTION_ARITY}</c></item>
+ <item><c>mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY}</c></item>
<item><c>file => ?FILE</c></item>
<item><c>line => ?LINE</c></item>
</list>
@@ -158,51 +235,15 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
</desc>
</datatype>
<datatype>
- <name name="config"/>
- <desc>
- <p>Configuration data for the logger part of Logger, or for a handler.</p>
- <p>The following default values apply:</p>
- <list>
- <item><c>level => info</c></item>
- <item><c>filter_default => log</c></item>
- <item><c>filters => []</c></item>
- <item><c>formatter => {logger_formatter,DefaultFormatterConfig</c>}</item>
- </list>
- <p>See the <seealso marker="logger_formatter#type-config">
- <c>logger_formatter(3)</c></seealso> manual page for
- information about the default configuration for this
- formatter.</p>
- </desc>
- </datatype>
- <datatype>
- <name name="handler_id"/>
- <desc>
- <p>A unique identifier for a handler instance.</p>
- </desc>
- </datatype>
- <datatype>
- <name name="filter_id"/>
- <desc>
- <p>A unique identifier for a filter.</p>
- </desc>
- </datatype>
- <datatype>
- <name name="filter"/>
- <desc>
- <p>A filter which can be installed for the logger part of
- Logger, or for a handler.</p>
- </desc>
- </datatype>
- <datatype>
- <name name="filter_arg"/>
+ <name name="msg_fun"/>
<desc>
- <p>The second argument to the filter fun.</p>
+ <p></p>
</desc>
</datatype>
<datatype>
- <name name="filter_return"/>
+ <name name="report"/>
<desc>
- <p>The return value from the filter fun.</p>
+ <p></p>
</desc>
</datatype>
<datatype>
@@ -213,15 +254,6 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
<c>erlang:system_time(microsecond)</c></seealso>.</p>
</desc>
</datatype>
- <datatype>
- <name name="formatter_config"/>
- <desc>
- <p>Configuration data for the
- formatter. See <seealso marker="logger_formatter">
- <c>logger_formatter(3)</c></seealso>
- for an example of a formatter implementation.</p>
- </desc>
- </datatype>
</datatypes>
<section>
@@ -258,6 +290,10 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
level.</p>
</section>
+ <section>
+ <marker id="logging_API"/>
+ <title>Logging API functions</title>
+ </section>
<funcs>
<func>
<name>emergency(StringOrReport[,Metadata])</name>
@@ -317,7 +353,7 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
<func>
<name>notice(StringOrReport[,Metadata])</name>
<name>notice(Format,Args[,Metadata])</name>
- <name>notice(Fun,FunArgs[,Metadata])</name>
+ <name>notice(Fun,FunArgs[,Metadata])</name>
<fsummary>Logs the given message as level <c>notice</c>.</fsummary>
<desc>
<p>Equivalent to
@@ -366,136 +402,21 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
<p>Log the given message.</p>
</desc>
</func>
+ </funcs>
+ <section>
+ <marker id="configuration_API"/>
+ <title>Configuration API functions</title>
+ </section>
+ <funcs>
<func>
- <name name="get_logger_config" arity="0"/>
- <fsummary>Look up the current configuration for the logger part
- of Logger.</fsummary>
- <desc>
- <p>Look up the current configuration for the logger part of
- Logger.</p>
- </desc>
- </func>
-
- <func>
- <name name="get_handler_config" arity="1"/>
- <fsummary>Look up the current configuration for the given
- handler.</fsummary>
- <desc>
- <p>Look up the current configuration for the given handler.</p>
- </desc>
- </func>
-
- <func>
- <name name="i" arity="0"/>
- <fsummary>Get all Logger configurations</fsummary>
- <desc>
- <p>Same as <seealso marker="#i/1"><c>logger:i(term)</c></seealso></p>
- </desc>
- </func>
-
- <func>
- <name name="i" arity="1" clause_i="1"/>
- <name name="i" arity="1" clause_i="2"/>
- <name name="i" arity="1" clause_i="3"/>
- <fsummary>Get all Logger configurations</fsummary>
- <desc>
- <p>Display or return all current Logger configurations.</p>
- <taglist>
- <tag><c><anno>Action</anno> = string</c></tag>
- <item>
- <p>Return the pretty printed current Logger configuration
- as iodata.</p>
- </item>
- <tag><c><anno>Action</anno> = term</c></tag>
- <item>
- <p>Return the current Logger configuration as a term. The
- format of this term may change between releases. For a
- stable format use <seealso marker="#get_handler_config/1">
- <c>logger:get_handler_config/1</c></seealso>
- and <seealso marker="#get_logger_config/0">
- <c>logger:get_logger_config/0</c></seealso>.</p>
- <p>The same as calling <c>logger:i()</c>.</p>
- </item>
- <tag><c><anno>Action</anno> = print</c></tag>
- <item>
- <p>Pretty print all the current Logger configuration to
- standard out. Example:</p>
- <code><![CDATA[1> logger:i(print).
-Current logger configuration:
- Level: info
- Filter Default: log
- Filters:
- Handlers:
- Id: default
- Module: logger_std_h
- Level: info
- Formatter:
- Module: logger_formatter
- Config: #{legacy_header => true,single_line => false,
- template => [{logger_formatter,header},"\n",msg,"\n"]}
- Filter Default: stop
- Filters:
- Id: stop_progress
- Fun: fun logger_filters:progress/2
- Config: stop
- Id: remote_gl
- Fun: fun logger_filters:remote_gl/2
- Config: stop
- Id: domain
- Fun: fun logger_filters:domain/2
- Config: {log,super,[beam,erlang,otp,sasl]}
- Id: no_domain
- Fun: fun logger_filters:domain/2
- Config: {log,undefined,[]}
- Handler Config:
- logger_std_h: #{type => standard_io}
- Level set per module:
- Module: my_module
- Level: debug]]></code>
- </item>
- </taglist>
- </desc>
- </func>
-
- <func>
- <name name="add_logger_filter" arity="2"/>
- <fsummary>Add a filter to the logger part of Logger.</fsummary>
+ <name name="add_handler" arity="3"/>
+ <fsummary>Add a handler with the given configuration.</fsummary>
<desc>
- <p>Add a filter to the logger part of Logger.</p>
- <p>The filter fun is called with the log event as the first
- parameter, and the specified <c>filter_args()</c> as the
- second parameter.</p>
- <p>The return value of the fun specifies if a log event is to
- be discarded or forwarded to the handlers:</p>
- <taglist>
- <tag><c>log_event()</c></tag>
- <item>
- <p>The filter <em>passed</em>. The next logger filter, if
- any, is applied. If no more logger filters exist, the
- log event is forwarded to the handler part of Logger,
- where handler filters are applied.</p>
- </item>
- <tag><c>stop</c></tag>
- <item>
- <p>The filter <em>did not pass</em>, and the log event is
- immediately discarded.</p>
- </item>
- <tag><c>ignore</c></tag>
- <item>
- <p>The filter has no knowledge of the log event. The next
- logger filter, if any, is applied. If no more logger
- filters exist, the value of the <c>filter_default</c>
- configuration parameter for the logger part specifies if
- the log event shall be discarded or forwarded to the
- handler part.</p>
- </item>
- </taglist>
- <p>See section <seealso marker="logger_chapter#filters">
- Filters</seealso> in the User's Guide for more information
- about filters.</p>
- <p>Some built-in filters exist. These are defined
- in <seealso marker="logger_filters"><c>logger_filters</c></seealso>.</p>
+ <p>Add a handler with the given configuration.</p>
+ <p><c><anno>HandlerId</anno></c> is a unique identifier which
+ must be used in all subsequent calls referring to this
+ handler.</p>
</desc>
</func>
@@ -541,98 +462,12 @@ Current logger configuration:
</func>
<func>
- <name name="remove_logger_filter" arity="1"/>
- <fsummary>Remove a filter from the logger part of Logger.</fsummary>
- <desc>
- <p>Remove the filter identified
- by <c><anno>FilterId</anno></c> from the logger part of Logger.</p>
- </desc>
- </func>
-
- <func>
- <name name="remove_handler_filter" arity="2"/>
- <fsummary>Remove a filter from the specified handler.</fsummary>
- <desc>
- <p>Remove the filter identified
- by <c><anno>FilterId</anno></c> from the handler identified
- by <c><anno>HandlerId</anno></c>.</p>
- </desc>
- </func>
-
- <func>
- <name name="add_handler" arity="3"/>
- <fsummary>Add a handler with the given configuration.</fsummary>
- <desc>
- <p>Add a handler with the given configuration.</p>
- <p><c><anno>HandlerId</anno></c> is a unique identifier which
- must be used in all subsequent calls referring to this
- handler.</p>
- </desc>
- </func>
-
- <func>
- <name name="remove_handler" arity="1"/>
- <fsummary>Remove the handler with the specified identity.</fsummary>
- <desc>
- <p>Remove the handler identified by <c><anno>HandlerId</anno></c>.</p>
- </desc>
- </func>
-
- <func>
- <name name="set_module_level" arity="2"/>
- <fsummary>Set the log level for the specified module.</fsummary>
- <desc>
- <p>Set the log level for the
- specified <c><anno>Module</anno></c>.</p>
- <p>The log level for a module overrides the global log level
- of Logger for log events originating from the module in
- question. Notice, however, that it does not override the
- level configuration for any handler.</p>
- <p>For example: Assume that the global log level for Logger
- is <c>info</c>, and there is one handler, <c>h1</c>, with
- level <c>info</c> and one handler, <c>h2</c>, with
- level <c>debug</c>.</p>
- <p>With this configuration, no debug messages will be logged,
- since they are all stopped by the global log level.</p>
- <p>If the level for <c>mymodule</c> is now set
- to <c>debug</c>, then debug events from this module will be
- logged by the handler <c>h2</c>, but not by
- handler <c>h1</c>.</p>
- <p>Debug events from other modules are still not logged.</p>
- <p>To change the global log level for Logger, use
- <seealso marker="#set_logger_config/2">
- <c>logger:set_logger_config(level,Level)</c></seealso>.</p>
- <p>To change the log level for a handler, use
- <seealso marker="#set_handler_config/3">
- <c>logger:set_handler_config(HandlerId,level,Level)</c></seealso>.</p>
- <note>
- <p>The originating module for a log event is only detected
- if <c>mfa=>{Module,Function,Arity}</c> exists in the
- metadata. When log macros are used, this association is
- automatically added to all log events. If an API function
- is called directly, without using a macro, the logging
- client must explicitly add this information if module
- levels shall have any effect.</p>
- </note>
- </desc>
- </func>
-
- <func>
- <name name="unset_module_level" arity="1"/>
- <fsummary>Remove a module specific log setting.</fsummary>
- <desc>
- <p>Remove a module specific log setting. After this, the
- global log level is used for the specified module.</p>
- </desc>
- </func>
-
- <func>
<name name="add_handlers" arity="1" clause_i="1"/>
<fsummary>Set up log handlers from the application's
configuration parameters.</fsummary>
<desc>
<p>Reads the application configuration parameter <c>logger</c> and
- calls <c>logger:add_handlers/1</c> with its contents.</p>
+ calls <c>add_handlers/1</c> with its contents.</p>
</desc>
</func>
@@ -670,61 +505,158 @@ start(_, []) ->
[{kernel,
[{logger,
%% Disable the default Kernel handler
- [{handler,default,undefined}]}]},
+ [{handler, default, undefined}]}]},
{my_app,
[{logger,
%% Enable this handler as the default
- [{handler,default,my_handler,#{}}]}]}].
+ [{handler, default, my_handler, #{}}]}]}].
</code>
</desc>
</func>
<func>
- <name name="set_logger_config" arity="1"/>
- <fsummary>Set configuration data for the logger part of Logger.</fsummary>
+ <name name="add_primary_filter" arity="2"/>
+ <fsummary>Add a primary filter to Logger.</fsummary>
<desc>
- <p>Set configuration data for the logger part of Logger. This
- overwrites the current logger configuration.</p>
- <p>To modify the existing configuration,
- use <seealso marker="#update_logger_config-1">
- <c>update_logger_config/1</c></seealso>, or, if a more
- complex merge is needed, read the current configuration
- with <seealso marker="#get_logger_config-0"><c>get_logger_config/0</c>
- </seealso>, then do the merge before writing the new
- configuration back with this function.</p>
- <p>If a key is removed compared to the current configuration,
- the default value is used.</p>
+ <p>Add a primary filter to Logger.</p>
+ <p>The filter fun is called with the log event as the first
+ parameter, and the specified <c>filter_args()</c> as the
+ second parameter.</p>
+ <p>The return value of the fun specifies if a log event is to
+ be discarded or forwarded to the handlers:</p>
+ <taglist>
+ <tag><c>log_event()</c></tag>
+ <item>
+ <p>The filter <em>passed</em>. The next primary filter, if
+ any, is applied. If no more primary filters exist, the
+ log event is forwarded to the handler part of Logger,
+ where handler filters are applied.</p>
+ </item>
+ <tag><c>stop</c></tag>
+ <item>
+ <p>The filter <em>did not pass</em>, and the log event is
+ immediately discarded.</p>
+ </item>
+ <tag><c>ignore</c></tag>
+ <item>
+ <p>The filter has no knowledge of the log event. The next
+ primary filter, if any, is applied. If no more primary
+ filters exist, the value of the
+ primary <c>filter_default</c> configuration parameter
+ specifies if the log event shall be discarded or
+ forwarded to the handler part.</p>
+ </item>
+ </taglist>
+ <p>See section <seealso marker="logger_chapter#filters">
+ Filters</seealso> in the User's Guide for more information
+ about filters.</p>
+ <p>Some built-in filters exist. These are defined
+ in <seealso marker="logger_filters"><c>logger_filters</c></seealso>.</p>
</desc>
</func>
<func>
- <name name="set_logger_config" arity="2"/>
- <fsummary>Add or update configuration data for the logger part
- of Logger.</fsummary>
+ <name name="get_config" arity="0"/>
+ <fsummary>Look up the current Logger configuration</fsummary>
<desc>
- <p>Add or update configuration data for the logger part of
- Logger. If the given <c><anno>Key</anno></c> already exists,
- its associated value will be changed
- to <c><anno>Value</anno></c>. If it does not exist, it will
- be added.</p>
+ <p>Look up all current Logger configuration, including primary
+ and handler configuration, and module level settings.</p>
</desc>
</func>
<func>
- <name name="update_logger_config" arity="1"/>
- <fsummary>Update configuration data for the logger part of
- Logger.</fsummary>
+ <name name="get_handler_config" arity="0"/>
+ <fsummary>Look up the current configuration for all handlers.</fsummary>
<desc>
- <p>Update configuration data for the logger part of
- Logger. This function behaves as if it was implemented as
- follows:</p>
- <code type="erl">
-{ok,Old} = logger:get_logger_config(),
-logger:set_logger_config(maps:merge(Old,Config)).
- </code>
- <p>To overwrite the existing configuration without any merge,
- use <seealso marker="#set_logger_config-1"><c>set_logger_config/1</c>
- </seealso>.</p>
+ <p>Look up the current configuration for all handlers.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="get_handler_config" arity="1"/>
+ <fsummary>Look up the current configuration for the given
+ handler.</fsummary>
+ <desc>
+ <p>Look up the current configuration for the given handler.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="get_handler_ids" arity="0"/>
+ <fsummary>Look up the identities for all installed handlers.</fsummary>
+ <desc>
+ <p>Look up the identities for all installed handlers.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="get_primary_config" arity="0"/>
+ <fsummary>Look up the current primary configuration for Logger.</fsummary>
+ <desc>
+ <p>Look up the current primary configuration for Logger.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="get_module_level" arity="0"/>
+ <fsummary>Look up all current module levels.</fsummary>
+ <desc>
+ <p>Look up all current module levels. Returns a list
+ containing one <c>{Module,Level}</c> element for each module
+ for which the module level was previously set
+ with <seealso marker="#set_module_level-2">
+ <c>set_module_level/2</c></seealso>.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="get_module_level" arity="1"/>
+ <fsummary>Look up the current level for the given modules.</fsummary>
+ <desc>
+ <p>Look up the current level for the given modules. Returns a
+ list containing one <c>{Module,Level}</c> element for each
+ of the given modules for which the module level was
+ previously set with <seealso marker="#set_module_level-2">
+ <c>set_module_level/2</c></seealso>.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="get_process_metadata" arity="0"/>
+ <fsummary>Retrieve data set with set_process_metadata/1.</fsummary>
+ <desc>
+ <p>Retrieve data set
+ with <seealso marker="#set_process_metadata-1">
+ <c>set_process_metadata/1</c></seealso> or
+ <seealso marker="#update_process_metadata-1">
+ <c>update_process_metadata/1</c></seealso>.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="remove_handler" arity="1"/>
+ <fsummary>Remove the handler with the specified identity.</fsummary>
+ <desc>
+ <p>Remove the handler identified by <c><anno>HandlerId</anno></c>.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="remove_handler_filter" arity="2"/>
+ <fsummary>Remove a filter from the specified handler.</fsummary>
+ <desc>
+ <p>Remove the filter identified
+ by <c><anno>FilterId</anno></c> from the handler identified
+ by <c><anno>HandlerId</anno></c>.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="remove_primary_filter" arity="1"/>
+ <fsummary>Remove a primary filter from Logger.</fsummary>
+ <desc>
+ <p>Remove the primary filter identified
+ by <c><anno>FilterId</anno></c> from Logger.</p>
</desc>
</func>
@@ -763,18 +695,122 @@ logger:set_logger_config(maps:merge(Old,Config)).
</func>
<func>
- <name name="update_handler_config" arity="2"/>
- <fsummary>Update configuration data for the specified handler.</fsummary>
+ <name name="set_primary_config" arity="1"/>
+ <fsummary>Set primary configuration data for Logger.</fsummary>
<desc>
- <p>Update configuration data for the specified handler. This function
- behaves as if it was implemented as follows:</p>
- <code type="erl">
-{ok,{_,Old}} = logger:get_handler_config(HandlerId),
-logger:set_handler_config(HandlerId,maps:merge(Old,Config)).
- </code>
- <p>To overwrite the existing configuration without any merge,
- use <seealso marker="#set_handler_config-2"><c>set_handler_config/2</c>
+ <p>Set primary configuration data for Logger. This
+ overwrites the current configuration.</p>
+ <p>To modify the existing configuration,
+ use <seealso marker="#update_primary_config-1">
+ <c>update_primary_config/1</c></seealso>, or, if a more
+ complex merge is needed, read the current configuration
+ with <seealso marker="#get_primary_config-0"><c>get_primary_config/0</c>
+ </seealso>, then do the merge before writing the new
+ configuration back with this function.</p>
+ <p>If a key is removed compared to the current configuration,
+ the default value is used.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="set_primary_config" arity="2"/>
+ <fsummary>Add or update primary configuration data for Logger.</fsummary>
+ <desc>
+ <p>Add or update primary configuration data for Logger. If the
+ given <c><anno>Key</anno></c> already exists, its associated
+ value will be changed to <c><anno>Value</anno></c>. If it
+ does not exist, it will be added.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="set_module_level" arity="2"/>
+ <fsummary>Set the log level for the specified modules.</fsummary>
+ <desc>
+ <p>Set the log level for the
+ specified modules.</p>
+ <p>The log level for a module overrides the primary log level
+ of Logger for log events originating from the module in
+ question. Notice, however, that it does not override the
+ level configuration for any handler.</p>
+ <p>For example: Assume that the primary log level for Logger
+ is <c>info</c>, and there is one handler, <c>h1</c>, with
+ level <c>info</c> and one handler, <c>h2</c>, with
+ level <c>debug</c>.</p>
+ <p>With this configuration, no debug messages will be logged,
+ since they are all stopped by the primary log level.</p>
+ <p>If the level for <c>mymodule</c> is now set
+ to <c>debug</c>, then debug events from this module will be
+ logged by the handler <c>h2</c>, but not by
+ handler <c>h1</c>.</p>
+ <p>Debug events from other modules are still not logged.</p>
+ <p>To change the primary log level for Logger, use
+ <seealso marker="#set_primary_config/2">
+ <c>set_primary_config(level, Level)</c></seealso>.</p>
+ <p>To change the log level for a handler, use
+ <seealso marker="#set_handler_config/3">
+ <c>set_handler_config(HandlerId, level, Level)</c>
</seealso>.</p>
+ <note>
+ <p>The originating module for a log event is only detected
+ if the key <c>mfa</c> exists in the metadata, and is
+ associated with <c>{Module, Function, Arity}</c>. When log
+ macros are used, this association is automatically added
+ to all log events. If an API function is called directly,
+ without using a macro, the logging client must explicitly
+ add this information if module levels shall have any
+ effect.</p>
+ </note>
+ </desc>
+ </func>
+
+ <func>
+ <name name="set_process_metadata" arity="1"/>
+ <fsummary>Set metadata to use when logging from current process.</fsummary>
+ <desc>
+ <p>Set metadata which Logger shall automatically insert in
+ all log events produced on the current process.</p>
+ <p>Location data produced by the log macros, and/or metadata
+ given as argument to the log call (API function or macro),
+ are merged with the process metadata. If the same keys
+ occur, values from the metadata argument to the log call
+ overwrite values from the process metadata, which in turn
+ overwrite values from the location data.</p>
+ <p>Subsequent calls to this function overwrites previous data
+ set. To update existing data instead of overwriting it,
+ see <seealso marker="#update_process_metadata-1">
+ <c>update_process_metadata/1</c></seealso>.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="unset_module_level" arity="0"/>
+ <fsummary>Remove module specific log settings for all modules.</fsummary>
+ <desc>
+ <p>Remove module specific log settings. After this, the
+ primary log level is used for all modules.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="unset_module_level" arity="1"/>
+ <fsummary>Remove module specific log settings for the given
+ modules.</fsummary>
+ <desc>
+ <p>Remove module specific log settings. After this, the
+ primary log level is used for the specified modules.</p>
+ </desc>
+ </func>
+
+ <func>
+ <name name="unset_process_metadata" arity="0"/>
+ <fsummary>Delete data set with set_process_metadata/1.</fsummary>
+ <desc>
+ <p>Delete data set
+ with <seealso marker="#set_process_metadata-1">
+ <c>set_process_metadata/1</c></seealso> or
+ <seealso marker="#update_process_metadata-1">
+ <c>update_process_metadata/1</c></seealso>.</p>
</desc>
</func>
@@ -786,9 +822,10 @@ logger:set_handler_config(HandlerId,maps:merge(Old,Config)).
<p>The new configuration is merged with the existing formatter
configuration.</p>
<p>To overwrite the existing configuration without any merge,
- use <seealso marker="#set_handler_config-3">
- <c>set_handler_config(HandlerId,formatter,
- {FormatterModule,FormatterConfig})</c></seealso>.</p>
+ use</p>
+ <pre>
+<seealso marker="#set_handler_config-3">set_handler_config(HandlerId, formatter,
+ {FormatterModule, FormatterConfig})</seealso>.</pre>
</desc>
</func>
@@ -797,39 +834,41 @@ logger:set_handler_config(HandlerId,maps:merge(Old,Config)).
<fsummary>Update the formatter configuration for the specified handler.</fsummary>
<desc>
<p>Update the formatter configuration for the specified handler.</p>
- <p>This is equivalent
- to <br/><seealso marker="#update_formatter_config-2">
- <c>update_formatter_config(<anno>HandlerId</anno>,#{<anno>Key</anno>=><anno>Value</anno>})</c></seealso></p>
+ <p>This is equivalent to</p>
+ <pre>
+<seealso marker="#update_formatter_config-2">update_formatter_config(<anno>HandlerId</anno>, #{<anno>Key</anno> => <anno>Value</anno>})</seealso></pre>
</desc>
</func>
<func>
- <name name="compare_levels" arity="2"/>
- <fsummary>Compare the severity of two log levels.</fsummary>
+ <name name="update_handler_config" arity="2"/>
+ <fsummary>Update configuration data for the specified handler.</fsummary>
<desc>
- <p>Compare the severity of two log levels. Returns <c>gt</c>
- if <c>Level1</c> is more severe than
- <c>Level2</c>, <c>lt</c> if <c>Level1</c> is less severe,
- and <c>eq</c> if the levels are equal.</p>
+ <p>Update configuration data for the specified handler. This function
+ behaves as if it was implemented as follows:</p>
+ <code type="erl">
+{ok, {_, Old}} = logger:get_handler_config(HandlerId),
+logger:set_handler_config(HandlerId, maps:merge(Old, Config)).
+ </code>
+ <p>To overwrite the existing configuration without any merge,
+ use <seealso marker="#set_handler_config-2"><c>set_handler_config/2</c>
+ </seealso>.</p>
</desc>
</func>
<func>
- <name name="set_process_metadata" arity="1"/>
- <fsummary>Set metadata to use when logging from current process.</fsummary>
+ <name name="update_primary_config" arity="1"/>
+ <fsummary>Update primary configuration data for Logger.</fsummary>
<desc>
- <p>Set metadata which Logger shall automatically insert in
- all log events produced on the current process.</p>
- <p>Location data produced by the log macros, and/or metadata
- given as argument to the log call (API function or macro),
- are merged with the process metadata. If the same keys
- occur, values from the metadata argument to the log call
- overwrite values from the process metadata, which in turn
- overwrite values from the location data.</p>
- <p>Subsequent calls to this function overwrites previous data
- set. To update existing data instead of overwriting it,
- see <seealso marker="#update_process_metadata-1">
- <c>update_process_metadata/1</c></seealso>.</p>
+ <p>Update primary configuration data for Logger. This function
+ behaves as if it was implemented as follows:</p>
+ <code type="erl">
+Old = logger:get_primary_config(),
+logger:set_primary_config(maps:merge(Old, Config)).
+ </code>
+ <p>To overwrite the existing configuration without any merge,
+ use <seealso marker="#set_primary_config-1"><c>set_primary_config/1</c>
+ </seealso>.</p>
</desc>
</func>
@@ -843,7 +882,7 @@ logger:set_handler_config(HandlerId,maps:merge(Old,Config)).
<p>If process metadata exists for the current process, this
function behaves as if it was implemented as follows:</p>
<code type="erl">
-logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
+logger:set_process_metadata(maps:merge(logger:get_process_metadata(), Meta)).
</code>
<p>If no process metadata exists, the function behaves as
<seealso marker="#set_process_metadata-1">
@@ -851,48 +890,44 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
</seealso>.</p>
</desc>
</func>
+ </funcs>
+ <section>
+ <marker id="misc_API"/>
+ <title>Miscellaneous API functions</title>
+ </section>
+ <funcs>
<func>
- <name name="get_process_metadata" arity="0"/>
- <fsummary>Retrieve data set with set_process_metadata/1.</fsummary>
- <desc>
- <p>Retrieve data set
- with <seealso marker="#set_process_metadata-1">
- <c>set_process_metadata/1</c></seealso> or
- <seealso marker="#update_process_metadata-1">
- <c>update_process_metadata/1</c></seealso>.</p>
- </desc>
- </func>
-
- <func>
- <name name="unset_process_metadata" arity="0"/>
- <fsummary>Delete data set with set_process_metadata/1.</fsummary>
+ <name name="compare_levels" arity="2"/>
+ <fsummary>Compare the severity of two log levels.</fsummary>
<desc>
- <p>Delete data set
- with <seealso marker="#set_process_metadata-1">
- <c>set_process_metadata/1</c></seealso> or
- <seealso marker="#update_process_metadata-1">
- <c>update_process_metadata/1</c></seealso>.</p>
+ <p>Compare the severity of two log levels. Returns <c>gt</c>
+ if <c>Level1</c> is more severe than
+ <c>Level2</c>, <c>lt</c> if <c>Level1</c> is less severe,
+ and <c>eq</c> if the levels are equal.</p>
</desc>
</func>
<func>
<name name="format_report" arity="1"/>
- <fsummary>Convert a log message on report form to {Format,Args}.</fsummary>
+ <fsummary>Convert a log message on report form to {Format, Args}.</fsummary>
<desc>
- <p>Convert a log message on report form to <c>{Format,Args}</c>.</p>
- <p>This is the default report callback used
+ <p>Convert a log message on report form to <c>{Format,
+ Args}</c>. This is the default report callback used
by <seealso marker="logger_formatter">
<c>logger_formatter</c></seealso> when no custom report
- callback is found.</p>
+ callback is found. See
+ section <seealso marker="logger_chapter#log_message">Log
+ Message</seealso> in the Kernel User's Guide for
+ information about report callbacks and valid forms of log
+ messages.</p>
<p>The function produces lines of <c>Key: Value</c> from
key-value lists. Strings are printed with <c>~ts</c> and
other terms with <c>~tp</c>.</p>
- <p>If the <c><anno>Report</anno></c> is a map, it is
- converted to a key-value list before formatting as such.</p>
+ <p>If <c><anno>Report</anno></c> is a map, it is converted to
+ a key-value list before formatting as such.</p>
</desc>
</func>
-
</funcs>
<section>
@@ -904,11 +939,11 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
<funcs>
<func>
- <name>HModule:adding_handler(Config1) -> {ok,Config2} | {error,Reason}</name>
+ <name>HModule:adding_handler(Config1) -> {ok, Config2} | {error, Reason}</name>
<fsummary>An instance of this handler is about to be added.</fsummary>
<type>
<v>Config1 = Config2 =
- <seealso marker="#type-config">config()</seealso></v>
+ <seealso marker="#type-handler_config">handler_config()</seealso></v>
<v>Reason = term()</v>
</type>
<desc>
@@ -928,11 +963,11 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
</func>
<func>
- <name>HModule:changing_config(Config1,Config2) -> {ok,Config3} | {error,Reason}</name>
+ <name>HModule:changing_config(Config1, Config2) -> {ok, Config3} | {error, Reason}</name>
<fsummary>The configuration for this handler is about to change.</fsummary>
<type>
<v>Config1 = Config2 = Config3 =
- <seealso marker="#type-config">config()</seealso></v>
+ <seealso marker="#type-handler_config">handler_config()</seealso></v>
<v>Reason = term()</v>
</type>
<desc>
@@ -952,17 +987,17 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
</func>
<func>
- <name>HModule:log(LogEvent,Config) -> void()</name>
+ <name>HModule:log(LogEvent, Config) -> void()</name>
<fsummary>Log the given log event.</fsummary>
<type>
<v>LogEvent =
<seealso marker="#type-log_event">log_event()</seealso></v>
<v>Config =
- <seealso marker="#type-config">config()</seealso></v>
+ <seealso marker="#type-handler_config">handler_config()</seealso></v>
</type>
<desc>
<p>This callback function is mandatory.</p>
- <p>The function is called when all global filters and all
+ <p>The function is called when all primary filters and all
handler filters for the handler in question have passed for
the given log event.</p>
<p>The handler identity is associated with the <c>id</c> key
@@ -978,7 +1013,7 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
<fsummary>The given handler is about to be removed.</fsummary>
<type>
<v>Config =
- <seealso marker="#type-config">config()</seealso></v>
+ <seealso marker="#type-handler_config">handler_config()</seealso></v>
</type>
<desc>
<p>This callback function is optional.</p>
@@ -1002,18 +1037,30 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
<funcs>
<func>
- <name>FModule:check_config(FConfig) -> ok | {error,term()}</name>
+ <name>FModule:check_config(FConfig) -> ok | {error, Reason}</name>
<fsummary>Validate the given formatter configuration.</fsummary>
<type>
<v>FConfig =
<seealso marker="#type-formatter_config">formatter_config()</seealso></v>
+ <v>Reason = term()</v>
</type>
<desc>
<p>This callback function is optional.</p>
<p>The function is called by a Logger when formatter
configuration is set or modified. The formatter must
validate the given configuration and return <c>ok</c> if it
- is correct, and <c>{error,term()}</c> if it is faulty.</p>
+ is correct, and <c>{error,Reason}</c> if it is faulty.</p>
+ <p>The following Logger API functions can trigger this callback:</p>
+ <list>
+ <item><seealso marker="logger#add_handler-3">
+ <c>logger:add_handler/3</c></seealso></item>
+ <item><seealso marker="logger#set_handler_config-2">
+ <c>logger:set_handler_config/2,3</c></seealso></item>
+ <item><seealso marker="logger#update_handler_config-2">
+ <c>logger:updata_handler_config/2</c></seealso></item>
+ <item><seealso marker="logger#update_formatter_config-2">
+ <c>logger:update_formatter_config/2</c></seealso></item>
+ </list>
<p>See <seealso marker="logger_formatter">
<c>logger_formatter(3)</c></seealso>
for an example implementation. <c>logger_formatter</c> is the
@@ -1021,7 +1068,7 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
</desc>
</func>
<func>
- <name>FModule:format(LogEvent,FConfig) -> FormattedLogEntry</name>
+ <name>FModule:format(LogEvent, FConfig) -> FormattedLogEntry</name>
<fsummary>Format the given log event.</fsummary>
<type>
<v>LogEvent =
@@ -1045,6 +1092,20 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)).
</desc>
</func>
</funcs>
+
+ <section>
+ <title>See Also</title>
+ <p>
+ <seealso marker="config"><c>config(4)</c></seealso>,
+ <seealso marker="erts:erlang"><c>erlang(3)</c></seealso>,
+ <seealso marker="stdlib:io"><c>io(3)</c></seealso>,
+ <seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c></seealso>,
+ <seealso marker="logger_filters"><c>logger_filters(3)</c></seealso>,
+ <seealso marker="logger_formatter"><c>logger_formatter(3)</c></seealso>,
+ <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>,
+ <seealso marker="stdlib:unicode"><c>unicode(3)</c></seealso>
+ </p>
+ </section>
</erlref>
diff --git a/lib/kernel/doc/src/logger_arch.png b/lib/kernel/doc/src/logger_arch.png
index 901122193a..a9b9a658b4 100644
--- a/lib/kernel/doc/src/logger_arch.png
+++ b/lib/kernel/doc/src/logger_arch.png
Binary files differ
diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml
index a3eec7bd4b..f7df0a3e6e 100644
--- a/lib/kernel/doc/src/logger_chapter.xml
+++ b/lib/kernel/doc/src/logger_chapter.xml
@@ -30,7 +30,7 @@
<file>logger_chapter.xml</file>
</header>
- <p>Erlang/OTP 21.0 provides a new standard API for logging
+ <p>Erlang/OTP 21.0 provides a standard API for logging
through <c>Logger</c>, which is part of the Kernel
application. Logger consists of the API for issuing log events,
and a customizable backend where log handlers, filters and
@@ -44,7 +44,7 @@
<p>You can also configure the system so that the default handler
prints log events to a single file, or to a set of wrap logs
via <seealso marker="disk_log"><c>disk_log</c></seealso>.</p>
- <p>By confiugration, you can aslo modify or disable the default
+ <p>By configuration, you can also modify or disable the default
handler, replace it by a custom handler, and install additional
handlers.</p>
@@ -53,11 +53,12 @@
<p>A <em>log event</em> consists of a <em>log level</em>, the
<em>message</em> to be logged, and <em>metadata</em>.</p>
<p>The Logger backend forwards log events from the API, first
- through a set of <em>global filters</em>, then through a set
- of <em>handler filters</em> for each log handler.</p>
+ through a set of <em>primary filters</em>, then through a set of
+ secondary filters attached to each log handler. The secondary
+ filters are in the following named <em>handler filters</em>.</p>
<p>Each filter set consists of a <em>log level check</em>,
followed by zero or more <em>filter functions</em>.</p>
- <p>The following figure show a conseptual overview of Logger. The
+ <p>The following figure shows a conceptual overview of Logger. The
figure shows two log handlers, but any number of handlers can be
installed.</p>
@@ -69,11 +70,11 @@
atoms are mapped to integer values, and a log event passes the
log level check if the integer value of its log level is less
than or equal to the currently configured log level. That is,
- the check pases if the event is equally or more severe than the
+ the check passes if the event is equally or more severe than the
configured level. See section <seealso marker="#log_level">Log
Level</seealso> for a listing and description of all log
levels.</p>
- <p>The global log level can be overridden by a log level
+ <p>The primary log level can be overridden by a log level
configured per module. This is to, for instance, allow more
verbose logging from a specific part of the system.</p>
<p>Filter functions can be used for more sophisticated filtering
@@ -82,7 +83,7 @@
also modify all parts of the log event. See see
section <seealso marker="#filters">Filters</seealso> for more
details.</p>
- <p>If a log event passes through all global filters and all
+ <p>If a log event passes through all primary filters and all
handler filters for a specific handler, Logger forwards the event
to the handler callback. The handler formats and prints the
event to its destination. See
@@ -107,7 +108,7 @@
functions is that macros add location (originator) information
to the metadata, and performs lazy evaluation by wrapping the
logger call in a case statement, so it is only evaluated if the
- log level of the event passes the global log level check.</p>
+ log level of the event passes the primary log level check.</p>
<section>
<marker id="log_level"/>
<title>Log Level</title>
@@ -136,7 +137,7 @@
<row>
<cell>critical</cell>
<cell align="center">2</cell>
- <cell>critical contidions</cell>
+ <cell>critical conditions</cell>
</row>
<row>
<cell>error</cell>
@@ -178,9 +179,9 @@
message can consist of a format string and arguments (given as
two separate parameters in the Logger API), a string or a
report. The latter, which is either a map or a key-value list,
- can be accompanied by a report callback specified in the log
- event's <seealso marker="#metadata">metadata</seealso>. The
- report callback is a convenience function that
+ can be accompanied by a <em>report callback</em> specified in
+ the log event's <seealso marker="#metadata">metadata</seealso>.
+ The report callback is a convenience function that
the <seealso marker="#formatters">formatter</seealso> can use
to convert the report to a format string and arguments. The
formatter can also use its own conversion function, if no
@@ -195,7 +196,7 @@
logger:debug(#{got => connection_request, id => Id, state => State},
#{report_cb => fun(R) -> {"~p",[R]} end})</code>
<p>The log message can also be provided through a fun for lazy
- evaluation. The fun is only evaluated if the global log level
+ evaluation. The fun is only evaluated if the primary log level
check passes, and is therefore recommended if it is expensive
to generate the message. The lazy fun must return a string, a
report, or a tuple with format string and arguments.</p>
@@ -217,9 +218,9 @@ logger:debug(#{got => connection_request, id => Id, state => State},
which these calls are made, and Logger adds the metadata
to all log events issued on that process.</p>
</item>
- <tag>Add metadata to a specifc log event</tag>
+ <tag>Add metadata to a specific log event</tag>
<item>
- <p>Metadata associated with one specifc log event is given
+ <p>Metadata associated with one specific log event is given
as the last parameter to the log macro or Logger API
function when the event is issued. For example:</p>
<code>?LOG_ERROR("Connection closed",#{context => server})</code>
@@ -235,8 +236,8 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<section>
<marker id="filter"/>
<title>Filters</title>
- <p>Filters can be global, or attached to a specific
- handler. Logger calls the global filters first, and if they all
+ <p>Filters can be primary, or attached to a specific
+ handler. Logger calls the primary filters first, and if they all
pass, it calls the handler filters for each handler. Logger
calls the handler callback only if all filters attached to the
handler in question also pass.</p>
@@ -251,7 +252,7 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<p>The filter function can return <c>stop</c>, <c>ignore</c> or
the (possibly modified) log event.</p>
<p>If <c>stop</c> is returned, the log event is immediately
- discarded. If the filter is global, no handler filters or
+ discarded. If the filter is primary, no handler filters or
callbacks are called. If it is a handler filter, the
corresponding handler callback is not called, but the log event
is forwarded to filters attached to the next handler, if
@@ -265,23 +266,21 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<p>If the filter function returns <c>ignore</c>, it means that it
did not recognize the log event, and thus leaves to other
filters to decide the event's destiny.</p>
- <p>The configuration
- option <seealso marker="#filter_default"><c>filter_default</c></seealso>
- specifies the behaviour if all filter functions
- return <c>ignore</c>, or if no filters
- exist. <c>filter_default</c> is by default set to <c>log</c>,
- meaning that if all existing filters ignore a log event, Logger
- forwards the event to the handler
+ <p>The configuration option <c>filter_default</c> specifies the
+ behaviour if all filter functions return <c>ignore</c>, or if no
+ filters exist. <c>filter_default</c> is by default set
+ to <c>log</c>, meaning that if all existing filters ignore a log
+ event, Logger forwards the event to the handler
callback. If <c>filter_default</c> is set to <c>stop</c>, Logger
discards such events.</p>
- <p>Global filters are added
- with <seealso marker="logger#add_logger_filter-2">
- <c>logger:add_logger_filter/2</c></seealso>
+ <p>Primary filters are added
+ with <seealso marker="logger#add_primary_filter-2">
+ <c>logger:add_primary_filter/2</c></seealso>
and removed
- with <seealso marker="logger#remove_logger_filter-1">
- <c>logger:remove_logger_filter/1</c></seealso>. They can also
+ with <seealso marker="logger#remove_primary_filter-1">
+ <c>logger:remove_primary_filter/1</c></seealso>. They can also
be added at system start via the Kernel configuration
- parameter <seealso marker="#logger"><c>logger</c></seealso>.</p>
+ parameter <seealso marker="#logger_parameter"><c>logger</c></seealso>.</p>
<p>Handler filters are added
with <seealso marker="logger#add_handler_filter-3">
<c>logger:add_handler_filter/3</c></seealso>
@@ -292,12 +291,13 @@ logger:debug(#{got => connection_request, id => Id, state => State},
with <seealso marker="logger#add_handler/3">
<c>logger:add_handler/3</c></seealso>
or via the Kernel configuration
- parameter <seealso marker="#logger"><c>logger</c></seealso>.</p>
+ parameter <seealso marker="#logger_parameter"><c>logger</c></seealso>.</p>
<p>To see which filters are currently installed in the system,
- use <seealso marker="logger#i-0"><c>logger:i/0</c></seealso>,
- or <seealso marker="logger#get_logger_config-0">
- <c>logger:get_logger_config/0</c></seealso>
+ use <seealso marker="logger#get_config-0">
+ <c>logger:get_config/0</c></seealso>,
+ or <seealso marker="logger#get_primary_config-0">
+ <c>logger:get_primary_config/0</c></seealso>
and <seealso marker="logger#get_handler_config-1">
<c>logger:get_handler_config/1</c></seealso>. Filters are
listed in the order they are applied, that is, the first
@@ -342,7 +342,7 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<pre><seealso marker="logger#HModule:log-2">log(LogEvent, Config) -> void()</seealso></pre>
<p>This function is called when a log event has passed through all
- global filters, and all handler filters attached to the handler
+ primary filters, and all handler filters attached to the handler
in question. The function call is executed on the client
process, and it is up to the handler implementation if other
processes are involved or not.</p>
@@ -358,8 +358,8 @@ logger:debug(#{got => connection_request, id => Id, state => State},
functions <c>adding_handler/1</c>, <c>changing_config/2</c>
and <c>removing_handler/1</c>. See
section <seealso marker="logger#handler_callback_functions">Handler
- Callback Functions</seealso> in the logger(3) manual for more
- information about these function.</p>
+ Callback Functions</seealso> in the logger(3) manual page for
+ more information about these function.</p>
<p>The following built-in handlers exist:</p>
@@ -404,7 +404,7 @@ logger:debug(#{got => connection_request, id => Id, state => State},
which is passed as the second argument
to <seealso marker="logger#HModule:log-2">
<c>HModule:log/2</c></seealso>.</p>
- <p>The formatter information consits of a formatter
+ <p>The formatter information consist of a formatter
module, <c>FModule</c> and its
configuration, <c>FConfig</c>. <c>FModule</c> must export the
following function, which can be called by the handler:</p>
@@ -425,152 +425,92 @@ logger:debug(#{got => connection_request, id => Id, state => State},
function when the formatter information is set or modified, to
verify the validity of the formatter configuration.</p>
<p>If no formatter information is specified for a handler, Logger
- uses <seealso marker="logger_formatter">
- <c>logger_formatter(3)</c></seealso> as default.</p>
+ uses <c>logger_formatter</c> as default. See
+ the <seealso marker="logger_formatter"><c>logger_formatter(3)</c></seealso>
+ manual page for more information about this module.</p>
</section>
<section>
<title>Configuration</title>
- <p>Logger can be configured either when the system starts through
- <seealso marker="config">configuration parameters</seealso>,
- or at run-time by using the <seealso marker="logger">logger(3)</seealso>
- API. The recommended approach is to do the initial configuration in
- the <c>sys.config</c> file and then use the API when some configuration
- has to be changed at runtime, such as the log level.</p>
+ <p>At system start, Logger is configured through Kernel
+ configuration parameters. The parameters that apply to Logger
+ are described in
+ section <seealso marker="#kernel_config_params">Kernel
+ Configuration Parameters</seealso>. Examples are found in
+ section <seealso marker="#config_examples">Configuration
+ Examples</seealso>.</p>
+ <p>During runtime, Logger configuration is changed via API
+ functions. See
+ section <seealso marker="logger#configuration_API">Configuration
+ API Functions</seealso> in the <c>logger(3)</c> manual page.</p>
<section>
- <title>Kernel Configuration Parameters</title>
- <p>Logger is best configured by using the configuration parameters
- of Kernel. There are four possible configuration parameters:
- <seealso marker="#logger"><c>logger</c></seealso>,
- <seealso marker="kernel_app#logger_level"><c>logger_level</c></seealso>,
- <seealso marker="kernel_app#logger_sasl_compatible"><c>logger_sasl_compatible</c></seealso> and
- <seealso marker="kernel_app#logger_progress_reports"><c>logger_progress_reports</c></seealso>.
- <c>logger_level</c>, <c>logger_sasl_compatible</c> and <c>logger_progress_reports</c> are described in the
- <seealso marker="kernel_app#configuration">Kernel Configuration</seealso>,
- while <c>logger</c> is described below.</p>
-
- <marker id="logger"/>
- <p><em>logger</em></p>
- <p>The application configuration parameter <c>logger</c> is used to configure
- three different Logger aspects; handlers, logger filters and module levels.
- The configuration is a list containing tagged tuples that look like this:</p>
- <taglist>
- <tag><c>DisableHandler = {handler,default,undefined}</c></tag>
- <item>
- <p>Disable the default handler. This allows another application
- to add its own default handler. See <seealso marker="logger#add_handlers/1">
- <c>logger:add_handlers/1</c></seealso> for more details.</p>
- <p>Only one entry of this option is allowed.</p></item>
- <tag><c>AddHandler = {handler,HandlerId,Module,HandlerConfig}</c></tag>
- <item>
- <p>Add a handler as if <seealso marker="logger:add_handler/3">
- <c>logger:add_handler(HandlerId,Module,HandlerConfig)</c></seealso> is
- called.</p>
- <p>It is allowed to have multiple entries of this option.</p></item>
- <tag><c>Filters = {filters, default, [Filter]}</c><br/>
- <c>FilterDefault = log | stop</c><br/>
- <c>Filter = {FilterId, {FilterFun, FilterConfig}}</c></tag>
- <item>
- <p>Add the specified <seealso marker="logger#add_logger_filter/2">
- logger filters</seealso>.</p>
- <p>Only one entry of this option is allowed.</p></item>
- <tag><c>ModuleLevel = {module_level, Level, [Module]}</c></tag>
- <item>
- <p>This option configures <seealso marker="logger#set_module_level/2">
- module log level</seealso>.</p>
- <p>It is allowed to have multiple entries of this option.</p></item>
- </taglist>
- <p>Examples:</p>
- <list>
- <item>
- <p>Output logs into the file &quot;logs/erlang.log&quot;</p>
- <code>
-[{kernel,
- [{logger,
- [{handler, default, logger_std_h,
- #{ logger_std_h => #{ type => {file,"log/erlang.log"}}}}]}]}].
- </code>
- </item>
- <item>
- <p>Output logs in single line format</p>
- <code>
-[{kernel,
- [{logger,
- [{handler, default, logger_std_h,
- #{ formatter => { logger_formatter,#{ single_line => true}}}}]}]}].
- </code>
- </item>
- <item>
- <p>Add the pid to each log event</p>
- <code>
-[{kernel,
- [{logger,
- [{handler, default, logger_std_h,
- #{ formatter => { logger_formatter,
- #{ template => [time," ",pid," ",msg,"\n"]}}
- }}]}]}].
- </code>
- </item>
- <item>
- <p>Use a different file for debug logging</p>
- <code>
-[{kernel,
- [{logger,
- [{handler, default, logger_std_h,
- #{ level => error,
- logger_std_h => #{ type => {file, "log/erlang.log"}}}},
- {handler, info, logger_std_h,
- #{ level => debug,
- logger_std_h => #{ type => {file, "log/debug.log"}}}}
- ]}]}].
- </code>
- </item>
- </list>
- </section>
-
- <section>
- <title>Global Logger Configuration</title>
-
+ <title>Primary Logger Configuration</title>
+ <p>Logger API functions that apply to the primary Logger
+ configuration are:</p>
+ <list>
+ <item><seealso marker="logger#get_primary_config-0">
+ <c>get_primary_config/0</c></seealso></item>
+ <item><seealso marker="logger#set_primary_config-1">
+ <c>set_primary_config/1,2</c></seealso></item>
+ <item><seealso marker="logger#update_primary_config-1">
+ <c>update_primary_config/1</c></seealso></item>
+ <item><seealso marker="logger#add_primary_filter-2">
+ <c>add_primary_filter/2</c></seealso></item>
+ <item><seealso marker="logger#remove_primary_filter-1">
+ <c>remove_primary_filter/1</c></seealso></item>
+ </list>
+ <p>The primary Logger configuration is a map with the following
+ keys:</p>
<taglist>
- <tag><c>level = </c><seealso marker="logger#type-level">
- <c>logger:level()</c></seealso></tag>
+ <tag><marker id="primary_level"/>
+ <c>level = </c><seealso marker="logger#type-level">
+ <c>logger:level()</c></seealso><c> | all | none</c></tag>
<item>
- <p>Specifies the global log level to log.</p>
+ <p>Specifies the primary log level, that is, log event that
+ are equally or more severe than this level, are forwarded
+ to the primary filters. Less severe log events are
+ immediately discarded.</p>
<p>See section <seealso marker="#log_level">Log
Level</seealso> for a listing and description of
possible log levels.</p>
<p>The initial value of this option is set by the Kernel
- configuration
- parameter <seealso marker="kernel_app#logger_level">
- <c>logger_level</c></seealso>. It can be changed during
- runtime
- with <seealso marker="logger#set_logger_config-2">
- <c>logger:set_logger_config(level,NewLevel)</c></seealso>.</p>
+ configuration parameter <seealso marker="#logger_level">
+ <c>logger_level</c></seealso>. It is changed during
+ runtime with <seealso marker="logger#set_primary_config-2">
+ <c>logger:set_primary_config(level,Level)</c></seealso>.</p>
+ <p>Defaults to <c>info</c>.</p>
</item>
- <tag><c>filters = [{</c><seealso marker="logger#type-filter_id">
- <c>logger:filter_id()</c></seealso><c>,</c>
- <seealso marker="logger#type-filter">
- <c>logger:filter()</c></seealso><c>}]</c></tag>
+ <tag><c>filters = [{FilterId,Filter}]</c></tag>
<item>
- <p>Global filters are added and removed with
- <seealso marker="logger#add_logger_filter-2">
- <c>logger:add_logger_filter/2</c></seealso> and
- <seealso marker="logger#remove_logger_filter-1">
- <c>logger:remove_logger_filter/1</c></seealso>,
+ <p>Specifies the primary filters.</p>
+ <list>
+ <item><c>FilterId = </c><seealso marker="logger#type-filter_id">
+ <c>logger:filter_id()</c></seealso></item>
+ <item><c>Filter = </c><seealso marker="logger#type-filter">
+ <c>logger:filter()</c></seealso></item>
+ </list>
+ <p>The initial value of this option is set by the Kernel
+ configuration
+ parameter <seealso marker="#logger_parameter"><c>logger</c></seealso>.
+ During runtime, primary filters are added and removed with
+ <seealso marker="logger#add_primary_filter-2">
+ <c>logger:add_primary_filter/2</c></seealso> and
+ <seealso marker="logger#remove_primary_filter-1">
+ <c>logger:remove_primary_filter/1</c></seealso>,
respectively.</p>
<p>See section <seealso marker="#filters">Filters</seealso>
- for more information.</p>
- <p>Default is <c>[]</c>, that is, no filters exist.</p>
+ for more detailed information.</p>
+ <p>Defaults to <c>[]</c>.</p>
</item>
- <tag><marker id="filter_default"/><c>filter_default = log | stop</c></tag>
+ <tag><c>filter_default = log | stop</c></tag>
<item>
- <p>Specifies what to do with an event if all filters
+ <p>Specifies what happens to a log event if all filters
return <c>ignore</c>, or if no filters exist.</p>
<p>See section <seealso marker="#filters">Filters</seealso>
for more information about how this option is used.</p>
- <p>Default is <c>log</c>.</p>
+ <p>Defaults to <c>log</c>.</p>
</item>
</taglist>
</section>
@@ -578,26 +518,64 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<section>
<marker id="handler_configuration"/>
<title>Handler Configuration</title>
+ <p>Logger API functions that apply to handler configuration
+ are:</p>
+ <list>
+ <item><seealso marker="logger#get_handler_config-0">
+ <c>get_handler_config/0,1</c></seealso></item>
+ <item><seealso marker="logger#set_handler_config-2">
+ <c>set_handler_config/2,3</c></seealso></item>
+ <item><seealso marker="logger#update_handler_config-2">
+ <c>update_handler_config/2</c></seealso></item>
+ <item><seealso marker="logger#add_handler_filter-3">
+ <c>add_handler_filter/3</c></seealso></item>
+ <item><seealso marker="logger#remove_handler_filter-2">
+ <c>remove_handler_filter/2</c></seealso></item>
+ <item><seealso marker="logger#update_formatter_config-2">
+ <c>update_formatter_config/2,3</c></seealso></item>
+ </list>
+ <p>The configuration for a handler is a map with the following keys:</p>
<taglist>
+ <tag><c>id = </c><seealso marker="logger#type-handler_id">
+ <c>logger:handler_id()</c></seealso></tag>
+ <item>
+ <p>Automatically inserted by Logger. The value is the same
+ as the <c>HandlerId</c> specified when adding the handler,
+ and it cannot be changed.</p>
+ </item>
+ <tag><c>module = module()</c></tag>
+ <item>
+ <p>Automatically inserted by Logger. The value is the same
+ as the <c>Module</c> specified when adding the handler,
+ and it cannot be changed.</p>
+ </item>
<tag><c>level = </c><seealso marker="logger#type-level">
- <c>logger:level()</c></seealso></tag>
+ <c>logger:level()</c></seealso><c> | all | none</c></tag>
<item>
- <p>Specifies the log level which the handler logs.</p>
+ <p>Specifies the log level for the handler, that is, log
+ events that are equally or more severe than this level,
+ are forwarded to the handler filters for this
+ handler.</p>
<p>See section <seealso marker="#log_level">Log
Level</seealso> for a listing and description of
possible log levels.</p>
- <p>The log level can be specified when adding the handler,
- or changed during runtime with, for
+ <p>The log level is specified when adding the handler, or
+ changed during runtime with, for
instance, <seealso marker="logger#set_handler_config/3">
- <c>logger:set_handler_config/3</c></seealso>.</p>
- <p>Default is <c>info</c>.</p>
+ <c>logger:set_handler_config(HandlerId,level,Level)</c></seealso>.
+ </p>
+ <p>Defaults to <c>all</c>.</p>
</item>
- <tag><c>filters = [{</c><seealso marker="logger#type-filter_id">
- <c>logger:filter_id()</c></seealso><c>,</c>
- <seealso marker="logger#type-filter">
- <c>logger:filter()</c></seealso><c>}]</c></tag>
+ <tag><c>filters = [{FilterId,Filter}]</c></tag>
<item>
- <p>Handler filters can be specified when adding the handler,
+ <p>Specifies the handler filters.</p>
+ <list>
+ <item><c>FilterId = </c><seealso marker="logger#type-filter_id">
+ <c>logger:filter_id()</c></seealso></item>
+ <item><c>Filter = </c><seealso marker="logger#type-filter">
+ <c>logger:filter()</c></seealso></item>
+ </list>
+ <p>Handler filters are specified when adding the handler,
or added or removed during runtime with
<seealso marker="logger#add_handler_filter-3">
<c>logger:add_handler_filter/3</c></seealso> and
@@ -605,49 +583,214 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<c>logger:remove_handler_filter/2</c></seealso>,
respectively.</p>
<p>See <seealso marker="#filters">Filters</seealso> for more
- information.</p>
- <p>Default is <c>[]</c>, that is, no filters exist.</p>
+ detailed information.</p>
+ <p>Defaults to <c>[]</c>.</p>
</item>
- <tag><marker id="filter_default"/><c>filter_default = log | stop</c></tag>
+ <tag><c>filter_default = log | stop</c></tag>
<item>
- <p>Specifies what to do with an event if all filters
+ <p>Specifies what happens to a log event if all filters
return <c>ignore</c>, or if no filters exist.</p>
<p>See section <seealso marker="#filters">Filters</seealso>
for more information about how this option is used.</p>
- <p>Default is <c>log</c>.</p>
+ <p>Defaults to <c>log</c>.</p>
</item>
- <tag><c>formatter = {module(),</c><seealso marker="logger#type-formatter_config">
- <c>logger:formatter_config()</c></seealso><c>}</c></tag>
+ <tag><c>formatter = {FormatterModule,FormatterConfig}</c></tag>
<item>
- <p>The formatter which the handler can use for converting
- the log event term to a printable string.</p>
- <p>See <seealso marker="#formatters">Formatters</seealso> for more
- information.</p>
- <p>Default
- is <c>{logger_formatter,DefaultFormatterConfig}</c>, see
+ <p>Specifies a formatter that the handler can use for
+ converting the log event term to a printable string.</p>
+ <list>
+ <item><c>FormatterModule = module()</c></item>
+ <item><c>FormatterConfig = </c>
+ <seealso marker="logger#type-formatter_config">
+ <c>logger:formatter_config()</c></seealso></item>
+ </list>
+ <p>The formatter information is specified when adding the
+ handler. The formatter configuration can be changed during
+ runtime
+ with <seealso marker="logger#update_formatter_config-2">
+ <c>logger:update_formatter_config/2,3</c></seealso>,
+ or the complete formatter information can be overwritten
+ with, for
+ instance, <seealso marker="logger#set_handler_config-3">
+ <c>logger:set_handler_config/3</c></seealso>.</p>
+ <p>See
+ section <seealso marker="#formatters">Formatters</seealso>
+ for more detailed information.</p>
+ <p>Defaults
+ to <c>{logger_formatter,DefaultFormatterConfig}</c>. See
the <seealso marker="logger_formatter">
- <c>logger_formatter(3)</c></seealso>
- manual for information about this formatter and its
- default configuration.</p>
+ <c>logger_formatter(3)</c></seealso> manual page for
+ information about this formatter and its default
+ configuration.</p>
</item>
- <tag><c>HandlerConfig, atom() = term()</c></tag>
- <item>
- <p>Any keys not listed above are considered to be handler
- specific configuration. The configuration of the Kernel
- handlers can be found in
+ <tag><c>config = term()</c></tag>
+ <item>
+ <p>Handler specific configuration, that is, configuration
+ data related to a specific handler implementation.</p>
+ <p>The configuration for the built-in handlers is described
+ in
the <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>
and
<seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c>
</seealso> manual pages.</p>
- </item>
+ </item>
</taglist>
<p>Notice that <c>level</c> and <c>filters</c> are obeyed by
Logger itself before forwarding the log events to each
- handler, while <c>formatter</c> and all handle specific
+ handler, while <c>formatter</c> and all handler specific
options are left to the handler implementation.</p>
- <p>All Logger's built-in handlers will call the given formatter
- before printing.</p>
+ </section>
+
+ <section>
+ <marker id="kernel_config_params"/>
+ <title>Kernel Configuration Parameters</title>
+
+ <p>The following Kernel configuration parameters apply to
+ Logger:</p>
+ <taglist>
+ <tag><marker id="logger_parameter"/><c>logger = [Config]</c></tag>
+ <item>
+ <p>Specifies the configuration
+ for <seealso marker="logger">Logger</seealso>, except the
+ primary log level, which is specified
+ with <seealso marker="#logger_level"><c>logger_level</c></seealso>,
+ and the compatibility
+ with <seealso marker="sasl:error_logging">SASL Error
+ Logging</seealso>, which is specified
+ with <seealso marker="#logger_sasl_compatible">
+ <c>logger_sasl_compatible</c></seealso>.</p>
+ <p>With this parameter, you can modify or disable the default
+ handler, add custom handlers and primary logger filters, and
+ set log levels per module.</p>
+ <p><c>Config</c> is any (zero or more) of the following:</p>
+ <taglist>
+ <tag><c>{handler, default, undefined}</c></tag>
+ <item>
+ <p>Disables the default handler. This allows another
+ application to add its own default handler.</p>
+ <p>Only one entry of this type is allowed.</p>
+ </item>
+ <tag><c>{handler, HandlerId, Module, HandlerConfig}</c></tag>
+ <item>
+ <p>If <c>HandlerId</c> is <c>default</c>, then this entry
+ modifies the default handler, equivalent to calling</p>
+ <pre><seealso marker="logger#set_handler_config-2">
+ logger:set_handler_config(default, Module, HandlerConfig)
+ </seealso></pre>
+ <p>For all other values of <c>HandlerId</c>, this entry
+ adds a new handler, equivalent to calling</p>
+ <pre><seealso marker="logger:add_handler/3">
+ logger:add_handler(HandlerId, Module, HandlerConfig)
+ </seealso></pre>
+ <p>Multiple entries of this type are allowed.</p></item>
+ <tag><c>{filters, FilterDefault, [Filter]}</c></tag>
+ <item>
+ <p>Adds the specified primary filters.</p>
+ <list>
+ <item><c>FilterDefault = log | stop</c></item>
+ <item><c>Filter = {FilterId, {FilterFun, FilterConfig}}</c></item>
+ </list>
+ <p>Equivalent to calling</p>
+ <pre><seealso marker="logger#add_primary_filter/2">
+ logger:add_primary_filter(FilterId, {FilterFun, FilterConfig})
+ </seealso></pre>
+ <p>for each <c>Filter</c>.</p>
+ <p><c>FilterDefault</c> specifies the behaviour if all
+ primary filters return <c>ignore</c>, see
+ section <seealso marker="#filters">Filters</seealso>.</p>
+ <p>Only one entry of this type is allowed.</p>
+ </item>
+ <tag><c>{module_level, Level, [Module]}</c></tag>
+ <item>
+ <p>Sets module log level for the given modules. Equivalent
+ to calling</p>
+ <pre><seealso marker="logger#set_module_level/2">
+ logger:set_module_level(Module, Level)</seealso></pre>
+ <p>for each <c>Module</c>.</p>
+ <p>Multiple entries of this type are allowed.</p>
+ </item>
+ </taglist>
+ <p>See
+ section <seealso marker="#config_examples">Configuration
+ Examples</seealso> for examples using the <c>logger</c>
+ parameter for system configuration.</p>
+ </item>
+ <tag><marker id="logger_level"/>
+ <c>logger_level = Level</c></tag>
+ <item>
+ <p>Specifies the primary log level. See
+ the <seealso marker="kernel_app#logger_level"><c>kernel(6)</c></seealso>
+ manual page for more information about this parameter.</p>
+ </item>
+ <tag><marker id="logger_sasl_compatible"/>
+ <c>logger_sasl_compatible = true | false</c></tag>
+ <item>
+ <p>Specifies Logger's compatibility
+ with <seealso marker="sasl:error_logging">SASL Error
+ Logging</seealso>. See
+ the <seealso marker="kernel_app#logger_sasl_compatible">
+ <c>kernel(6)</c></seealso> manual page for more
+ information about this parameter.</p>
+ </item>
+ </taglist>
+ </section>
+
+ <section>
+ <marker id="config_examples"/>
+ <title>Configuration Examples</title>
+ <p>The value of the Kernel configuration parameter <c>logger</c>
+ is a list of tuples. It is possible to write the term on the
+ command line when starting an erlang node, but as the term
+ grows, a better approach is to use the system configuration
+ file. See
+ the <seealso marker="config"><c>config(4)</c></seealso> manual
+ page for more information about this file.</p>
+ <p>Each of the following examples shows a simple system
+ configuration file that configures Logger according to the
+ description.</p>
+ <p>Modify the default handler to print to a file instead of
+ <c>standard_io</c>:</p>
+ <code>
+[{kernel,
+ [{logger,
+ [{handler, default, logger_std_h, % {handler, HandlerId, Module,
+ #{config => #{type => {file,"log/erlang.log"}}}} % Config}
+ ]}]}].
+ </code>
+ <p>Modify the default handler to print each log event as a
+ single line:</p>
+ <code>
+[{kernel,
+ [{logger,
+ [{handler, default, logger_std_h,
+ #{formatter => {logger_formatter, #{single_line => true}}}}
+ ]}]}].
+ </code>
+ <p>Modify the default handler to print the pid of the logging
+ process for each log event:</p>
+ <code>
+[{kernel,
+ [{logger,
+ [{handler, default, logger_std_h,
+ #{formatter => {logger_formatter,
+ #{template => [time," ",pid," ",msg,"\n"]}}}}
+ ]}]}].
+ </code>
+ <p>Modify the default handler to only print errors and more
+ severe log events to "log/erlang.log", and add another handler
+ to print all log events to "log/debug.log".</p>
+ <code>
+[{kernel,
+ [{logger,
+ [{handler, default, logger_std_h,
+ #{level => error,
+ config => #{type => {file, "log/erlang.log"}}}},
+ {handler, info, logger_std_h,
+ #{level => debug,
+ config => #{type => {file, "log/debug.log"}}}}
+ ]}]}].
+ </code>
</section>
</section>
@@ -687,8 +830,9 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<p>To get log events on the same format as produced
by <c>error_logger_tty_h</c> and <c>error_logger_file_h</c>,
use the default formatter, <c>logger_formatter</c>, with
- configuration parameter <c>legacy_header => true</c>. This is
- also the default.</p>
+ configuration parameter <c>legacy_header</c> set
+ to <c>true</c>. This is the default configuration of
+ the <c>default</c> handler started by Kernel.</p>
</item>
<tag>Default Format of Log Events from OTP</tag>
<item>
@@ -700,12 +844,11 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<item>
<p>By SASL reports we mean supervisor reports, crash reports
and progress reports.</p>
- <p>In earlier releases, these reports were only logged when
- the SASL application was running, and they were printed
- trough specific event handlers
- named <c>sasl_report_tty_h</c>
+ <p>Prior to Erlang/OTP 21.0, these reports were only logged
+ when the SASL application was running, and they were printed
+ trough SASL's own event handlers <c>sasl_report_tty_h</c>
and <c>sasl_report_file_h</c>.</p>
- <p>The destination of these log events were configured by
+ <p>The destination of these log events was configured by
<seealso marker="sasl:sasl_app#deprecated_error_logger_config">SASL
configuration parameters</seealso>.</p>
<p>Due to the specific event handlers, the output format
@@ -716,17 +859,20 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<list>
<item>Supervisor reports, crash reports, and progress reports
are no longer connected to the SASL application.</item>
- <item>Supervisor reports and crash reports are logged by
- default.</item>
- <item>Progress reports are not logged by default, but can be
- enabled with the Kernel configuration
- parameter <seealso marker="kernel_app#logger_progress_reports">
- <c>logger_progress_reports</c></seealso>.</item>
+ <item>Supervisor reports and crash reports are issued
+ as <c>error</c> level log events, and are logged through
+ the default handler started by Kernel.</item>
+ <item>Progress reports are issued as <c>info</c> level log
+ events, and since the default primary log level
+ is <c>notice</c>, these are not logged by default. To
+ enable printing of progress reports, set
+ the <seealso marker="#primary_level">primary log
+ level</seealso> to <c>info</c>.</item>
<item>The output format is the same for all log
events.</item>
</list>
- <p>If the old behaviour is preferred, the Kernel configuation
- parameter <seealso marker="kernel_app:logger_sasl_compatible">
+ <p>If the old behaviour is preferred, the Kernel configuration
+ parameter <seealso marker="kernel_app#logger_sasl_compatible">
<c>logger_sasl_compatible</c></seealso> can be set
to <c>true</c>. The
<seealso marker="sasl:sasl_app#deprecated_error_logger_config">SASL
@@ -734,11 +880,10 @@ logger:debug(#{got => connection_request, id => Id, state => State},
before, and the SASL reports will only be printed if the
SASL application is running, through a second log handler
named <c>sasl</c>.</p>
- <p>All SASL reports have a metadata
- field <c>domain => [beam,erlang,otp,sasl]</c>, which can be
- used, for example, by filters to stop or allow the
- log events.</p>
- <p>See the <seealso marker="sasl:error_logging">SASL User's
+ <p>All SASL reports have a metadata field <c>domain</c> which
+ is set to <c>[otp,sasl]</c>. This field can be
+ used by filters to stop or allow the log events.</p>
+ <p>See section <seealso marker="sasl:error_logging">SASL User's
Guide</seealso> for more information about the old SASL
error logging functionality.</p>
</item>
@@ -749,21 +894,22 @@ logger:debug(#{got => connection_request, id => Id, state => State},
<code>
error_logger:add_report_handler/1,2.
</code>
- <p>This will automatically start the <c>error_logger</c>
- event manager, and add <c>error_logger</c> as a
- handler to <c>logger</c>, with configuration</p>
+ <p>This automatically starts the error logger event manager,
+ and adds <c>error_logger</c> as a handler to Logger, with
+ the following configuration:</p>
<code>
#{level => info,
filter_default => log,
filters => []}.
</code>
- <p>Notice that this handler will ignore events that do not
- originate from the <c>error_logger</c> API, or from within
- OTP. This means that if your code uses the Logger API for
- logging, then your log events will be discarded by this
- handler.</p>
- <p>Also notice that <c>error_logger</c> is not overload
- protected.</p>
+ <note>
+ <p>This handler ignores events that do not originate from
+ the <c>error_logger</c> API, or from within OTP. This
+ means that if your code uses the Logger API for logging,
+ then your log events will be discarded by this
+ handler.</p>
+ <p>The handler is not overload protected.</p>
+ </note>
</item>
</taglist>
</section>
@@ -771,100 +917,108 @@ error_logger:add_report_handler/1,2.
<section>
<title>Error Handling</title>
- <p>Log data is expected to be either a format string and
- arguments, a string
- (<seealso marker="stdlib:unicode#type-chardata">
- <c>unicode:chardata()</c></seealso>), or a report (map or
- key-value list) which can be converted to a format string and
- arguments by the handler. If a report is given, a default report
- callback can be included in the log event's metadata. The
- handler can use this callback for converting the report to a
- format string and arguments. If the format obtained by the
- provided callback is not desired, or if there is no provided
- callback, the handler must do a custom conversion.</p>
- <p>Logger does, to a certain extent, check its input data
- before forwarding a log event to the handlers, but it does not
- evaluate conversion funs or check the validity of format strings
- and arguments. This means that any filter or handler must be
- careful when formatting the data of a log event, making sure
- that it does not crash due to bad input data or faulty
- callbacks.</p>
+ <p>Logger does, to a certain extent, check its input data before
+ forwarding a log event to filters and handlers. It does,
+ however, not evaluate report callbacks, or check the validity of
+ format strings and arguments. This means that all filters and
+ handlers must be careful when formatting the data of a log
+ event, making sure that it does not crash due to bad input data
+ or faulty callbacks.</p>
<p>If a filter or handler still crashes, Logger will remove the
filter or handler in question from the configuration, and print
a short error message to the terminal. A debug event containing
- the crash reason and other details is also issued, and can be
- seen if a handler logging debug events is installed.</p>
+ the crash reason and other details is also issued.</p>
+ <p>See section <seealso marker="#log_message">Log
+ Message</seealso> for more information about report callbacks
+ and valid forms of log messages.</p>
</section>
<section>
- <title>Example: add a handler to log debug events to file</title>
+ <title>Example: Add a handler to log debug events to file</title>
<p>When starting an Erlang node, the default behaviour is that all
- log events with level info and above are logged to the
- terminal. In order to also log debug events, you can either
- change the global log level to <c>debug</c> or add a separate
- handler to take care of this. In this example we will add a new
- handler which prints the debug events to a separate file.</p>
- <p>First, we add an instance of <c>logger_std_h</c> with
- type <c>{file,File}</c>, and we set the handler's level
- to <c>debug</c>:</p>
+ log events on level info or more severe, are logged to the
+ terminal via the default handler. To also log debug events, you
+ can either change the primary log level to <c>debug</c>:</p>
<pre>
-1> <input>Config = #{level => debug, logger_std_h => #{type => {file,"./debug.log"}}}.</input>
-#{logger_std_h => #{type => {file,"./debug.log"}},
- level => debug}
-2> <input>logger:add_handler(debug_handler,logger_std_h,Config).</input>
+1> <input>logger:set_primary_config(level, debug).</input>
ok</pre>
- <p>By default, the handler receives all events
- (<c>filter_default=log</c>, see
- section <seealso marker="#filters">Filters</seealso> for more
- details), so we need to add a filter to stop all non-debug
- events. The built-in
- filter <seealso marker="logger_filters#level-2">
- <c>logger_filters:level/2</c></seealso>
- is used for this:</p>
+ <p>or set the level for one or a few modules only:</p>
<pre>
-3> <input>logger:add_handler_filter(debug_handler,stop_non_debug,
- {fun logger_filters:level/2,{stop,neq,debug}}).</input>
+2> <input>logger:set_module_level(mymodule, debug).</input>
ok</pre>
- <p>And finally, we need to make sure that Logger itself allows
- debug events. This can either be done by setting the global
- log level:</p>
+ <p>This allows debug events to pass through to the default handler,
+ and be printed to the terminal as well. If there are many debug
+ events, it can be useful to print these to a file instead.</p>
+ <p>First, set the log level of the default handler to <c>info</c>,
+ preventing it from printing debug events to the terminal:</p>
<pre>
-4> <input>logger:set_logger_config(level,debug).</input>
+3> <input>logger:set_handler_config(default, level, info).</input>
ok</pre>
- <p>Or by allowing debug events from one or a few modules only:</p>
+ <p>Then, add a new handler which prints to file. You can use the
+ handler
+ module <seealso marker="logger_std_h"><c>logger_std_h</c></seealso>,
+ and specify type <c>{file,File}</c>. The default handler level
+ is <c>all</c>, so you don't need to specify that:</p>
+ <pre>
+4> <input>Config = #{config => #{type => {file,"./debug.log"}}}.</input>
+#{config => #{type => {file,"./debug.log"}}}
+5> <input>logger:add_handler(debugger, logger_std_h, Config).</input>
+ok</pre>
+ <p>Since <c>filter_default</c> defaults to <c>log</c>, this
+ handler now receives all log events. If you want debug events
+ only in the file, you must add a filter to stop all non-debug
+ events. The built-in
+ filter <seealso marker="logger_filters#level-2">
+ <c>logger_filters:level/2</c></seealso>
+ can do this:</p>
<pre>
-5> <input>logger:set_module_level(mymodule,debug).</input>
+6> <input>logger:add_handler_filter(debugger, stop_non_debug,
+ {fun logger_filters:level/2, {stop, neq, debug}}).</input>
ok</pre>
+ <p>See section <seealso marker="#filters">Filters</seealso> for
+ more information about the filters and the <c>filter_default</c>
+ configuration parameter.</p>
</section>
<section>
- <title>Example: implement a handler</title>
- <p>The only requirement that a handler MUST fulfill is to export
- the following function:</p>
- <code>log(logger:log_event(),logger:config()) -> ok</code>
- <p>It can optionally also implement the following callbacks:</p>
- <code>
-adding_handler(logger:config()) -> {ok,logger:config()} | {error,term()}
-removing_handler(logger:config()) -> ok
-changing_config(logger:config(),logger:config()) -> {ok,logger:config()} | {error,term()}
- </code>
- <p>When <c>logger:add_handler(Id,Module,Config)</c> is called,
+ <title>Example: Implement a handler</title>
+ <p>Section <seealso marker="logger#handler_callback_functions">Handler
+ Callback Functions</seealso> in the logger(3) manual page
+ describes the callback functions that can be implemented for a
+ Logger handler.</p>
+ <p>A handler callback module must export:</p>
+ <list>
+ <item><c>log(Log, Config)</c></item>
+ </list>
+ <p>It can optionally also export some, or all, of the following:</p>
+ <list>
+ <item><c>adding_handler(Config)</c></item>
+ <item><c>removing_handler(Config)</c></item>
+ <item><c>changing_config(OldConfig, NewConfig)</c></item>
+ </list>
+ <p>When a handler is added, by for example a call
+ to <seealso marker="logger#add_handler-3">
+ <c>logger:add_handler(Id, HModule, Config)</c></seealso>,
Logger first calls <c>HModule:adding_handler(Config)</c>. If
- this function returns <c>{ok,NewConfig}</c>, Logger
- writes <c>NewConfig</c> to the configuration database, and
+ this function returns <c>{ok,Config1}</c>, Logger
+ writes <c>Config1</c> to the configuration database, and
the <c>logger:add_handler/3</c> call returns. After this, the
handler is installed and must be ready to receive log events as
calls to <c>HModule:log/2</c>.</p>
<p>A handler can be removed by calling
- <c>logger:remove_handler(Id)</c>. Logger calls
+ <seealso marker="logger#remove_handler-1">
+ <c>logger:remove_handler(Id)</c></seealso>. Logger calls
<c>HModule:removing_handler(Config)</c>, and removes the
handler's configuration from the configuration database.</p>
- <p>When <c>logger:set_handler_config/2,3</c>
- or <c>logger:update_handler_config/2</c> is called, Logger
- calls <c>HModule:changing_config(OldConfig,NewConfig)</c>. If
- this function returns <c>{ok,NewConfig}</c>, Logger
- writes <c>NewConfig</c> to the configuration database.</p>
+ <p>When <seealso marker="logger#set_handler_config-2">
+ <c>logger:set_handler_config/2,3</c></seealso>
+ or <seealso marker="logger#update_handler_config/2">
+ <c>logger:update_handler_config/2</c></seealso> is called,
+ Logger
+ calls <c>HModule:changing_config(OldConfig, NewConfig)</c>. If
+ this function returns <c>{ok,NewConfig1}</c>, Logger
+ writes <c>NewConfig1</c> to the configuration database.</p>
<p>A simple handler that prints to the terminal can be implemented
as follows:</p>
@@ -872,11 +1026,11 @@ changing_config(logger:config(),logger:config()) -> {ok,logger:config()} | {erro
-module(myhandler).
-export([log/2]).
-log(LogEvent,#{formatter:={FModule,FConfig}) ->
- io:put_chars(FModule:format(LogEvent,FConfig)).
+log(LogEvent, #{formatter := {FModule, FConfig}) ->
+ io:put_chars(FModule:format(LogEvent, FConfig)).
</code>
- <p>A simple handler which prints to file could be implemented like
+ <p>A simple handler which prints to file can be implemented like
this:</p>
<code>
-module(myhandler).
@@ -884,28 +1038,29 @@ log(LogEvent,#{formatter:={FModule,FConfig}) ->
-export([init/1, handle_call/3, handle_cast/2, terminate/2]).
adding_handler(Config) ->
- {ok,Fd} = file:open(File,[append,{encoding,utf8}]),
- {ok,Config#{myhandler_fd => Fd}}.
+ {ok, Fd} = file:open(File, [append, {encoding, utf8}]),
+ {ok, Config#{myhandler_fd => Fd}}.
-removing_handler(#{myhandler_fd:=Fd}) ->
+removing_handler(#{myhandler_fd := Fd}) ->
_ = file:close(Fd),
ok.
-log(LogEvent,#{myhandler_fd:=Fd,formatter:={FModule,FConfig}}) ->
- io:put_chars(Fd,FModule:format(LogEvent,FConfig)).
+log(LogEvent,#{myhandler_fd := Fd, formatter := {FModule, FConfig}}) ->
+ io:put_chars(Fd, FModule:format(LogEvent, FConfig)).
</code>
- <note><p>The above handlers do not have any overload
- protection, and all log events are printed directly from the
- client process.</p></note>
-
- <p>For information and examples of overload protection, please
- refer to
- section <seealso marker="#overload_protection">Protecting the
- Handler from Overload</seealso>, and the implementation
- of <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>
- and <seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c>
- </seealso>.</p>
+ <note>
+ <p>The above handlers do not have any overload
+ protection, and all log events are printed directly from the
+ client process.</p>
+ <p>For information and examples of overload protection, please
+ refer to
+ section <seealso marker="#overload_protection">Protecting the
+ Handler from Overload</seealso>, and the implementation
+ of <seealso marker="logger_std_h"><c>logger_std_h</c></seealso>
+ and <seealso marker="logger_disk_log_h"><c>logger_disk_log_h</c>
+ </seealso>.</p>
+ </note>
<p>Below is a simpler example of a handler which logs through one
single process.</p>
@@ -915,33 +1070,33 @@ log(LogEvent,#{myhandler_fd:=Fd,formatter:={FModule,FConfig}}) ->
-export([init/1, handle_call/3, handle_cast/2, terminate/2]).
adding_handler(Config) ->
- {ok,Pid} = gen_server:start(?MODULE,Config),
- {ok,Config#{myhandler_pid => Pid}}.
+ {ok, Pid} = gen_server:start(?MODULE, Config),
+ {ok, Config#{myhandler_pid => Pid}}.
-removing_handler(#{myhandler_pid:=Pid}) ->
+removing_handler(#{myhandler_pid := Pid}) ->
gen_server:stop(Pid).
-log(LogEvent,#{myhandler_pid:=Pid} = Config) ->
- gen_server:cast(Pid,{log,LogEvent,Config}).
+log(LogEvent,#{myhandler_pid := Pid} = Config) ->
+ gen_server:cast(Pid, {log, LogEvent, Config}).
-init(#{myhandler_file:=File}) ->
- {ok,Fd} = file:open(File,[append,{encoding,utf8}]),
- {ok,#{file => File, fd => Fd}}.
+init(#{myhandler_file := File}) ->
+ {ok, Fd} = file:open(File, [append, {encoding, utf8}]),
+ {ok, #{file => File, fd => Fd}}.
-handle_call(_,_,State) ->
- {reply,{error,bad_request},State}.
+handle_call(_, _, State) ->
+ {reply, {error, bad_request}, State}.
-handle_cast({log,LogEvent,Config},#{fd:=Fd} = State) ->
- do_log(Fd,LogEvent,Config),
- {noreply,State}.
+handle_cast({log, LogEvent, Config}, #{fd := Fd} = State) ->
+ do_log(Fd, LogEvent, Config),
+ {noreply, State}.
-terminate(Reason,#{fd:=Fd}) ->
+terminate(Reason, #{fd := Fd}) ->
_ = file:close(Fd),
ok.
-do_log(Fd,LogEvent,#{formatter:={FModule,FConfig}}) ->
- String = FModule:format(LogEvent,FConfig),
- io:put_chars(Fd,String).
+do_log(Fd, LogEvent, #{formatter := {FModule, FConfig}}) ->
+ String = FModule:format(LogEvent, FConfig),
+ io:put_chars(Fd, String).
</code>
</section>
@@ -985,7 +1140,7 @@ do_log(Fd,LogEvent,#{formatter:={FModule,FConfig}}) ->
level below the <c>toggle_sync_qlen</c> threshold, asynchronous
operation is resumed. The switch from asynchronous to synchronous
mode will force the logging tempo of few busy senders to slow down,
- but can not protect the handler sufficiently in situations of many
+ but cannot protect the handler sufficiently in situations of many
concurrent senders.</p>
</item>
<tag><c>drop_new_reqs_qlen</c></tag>
@@ -1044,11 +1199,11 @@ do_log(Fd,LogEvent,#{formatter:={FModule,FConfig}}) ->
<p>A configuration example:</p>
<code type="none">
logger:add_handler(my_standard_h, logger_std_h,
- #{logger_std_h =>
- #{type => {file,"./system_info.log"},
- toggle_sync_qlen => 100,
- drop_new_reqs_qlen => 1000,
- flush_reqs_qlen => 2000}}).
+ #{config =>
+ #{type => {file,"./system_info.log"},
+ toggle_sync_qlen => 100,
+ drop_new_reqs_qlen => 1000,
+ flush_reqs_qlen => 2000}}).
</code>
</section>
@@ -1086,10 +1241,10 @@ logger:add_handler(my_standard_h, logger_std_h,
<code type="none">
logger:add_handler(my_disk_log_h, logger_disk_log_h,
#{disk_log_opts =>
- #{file => "./my_disk_log"},
- logger_disk_log_h =>
- #{burst_limit_size => 10,
- burst_window_time => 500}}).
+ #{file => "./my_disk_log"},
+ config =>
+ #{burst_limit_size => 10,
+ burst_window_time => 500}}).
</code>
</section>
diff --git a/lib/kernel/doc/src/logger_disk_log_h.xml b/lib/kernel/doc/src/logger_disk_log_h.xml
index 20b49b8ca0..63c29cb010 100644
--- a/lib/kernel/doc/src/logger_disk_log_h.xml
+++ b/lib/kernel/doc/src/logger_disk_log_h.xml
@@ -44,7 +44,7 @@
the handler configuration.</p>
<p>The default standard handler,
<seealso marker="logger_std_h"><c>logger_std_h</c></seealso>, can be
- replaced by a disk_log handler at startup of the Kernel application.
+ replaced by a disk_log handler at start up of the Kernel application.
See an example of this below.</p>
<p>The handler has an overload protection mechanism that will keep the handler
process and the Kernel application alive during a high load of log
@@ -60,7 +60,7 @@
</seealso>, as well as handler specific parameters.</p>
<p>The settings for the disk_log log file should be specified with the
key <c>disk_log_opts</c>. These settings are a subset of the disk_log
- datatype
+ data type
<seealso marker="disk_log#open-1"><c>dlog_option()</c></seealso>.</p>
<p>Parameters in the <c>disk_log_opts</c> map:</p>
<taglist>
@@ -81,7 +81,7 @@
log.</item>
</taglist>
<p>Specific configuration for the handler (represented as a sub map)
- is specified with the key <c>logger_disk_log_h</c>. It may contain the
+ is specified with the key <c>config</c>. It may contain the
following parameter:</p>
<taglist>
<tag><c>filesync_repeat_interval</c></tag>
@@ -93,7 +93,7 @@
since the last sync. The default value is <c>5000</c> milliseconds.
If <c>no_repeat</c> is set as value, the repeated sync operation is
disabled. The user can also call the
- <seealso marker="logger_disk_log_h#disk_log_sync-1"><c>disk_log_sync/1</c>
+ <seealso marker="logger_disk_log_h#sync-1"><c>sync/1</c>
</seealso> function to perform a disk_log sync.</p></item>
</taglist>
<p>There are a number of other configuration parameters available, that are
@@ -117,7 +117,7 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h,
type => wrap,
max_no_files => 4,
max_no_bytes => 10000},
- logger_disk_log_h =>
+ config =>
#{filesync_repeat_interval => 1000}}).
</code>
<p>In order to use the disk_log handler instead of the default standard
@@ -125,14 +125,14 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h,
use disk_log. Example:</p>
<code type="none">
erl -kernel logger '[{handler,default,logger_disk_log_h,
- #{ disk_log_opts => #{ file => "./system_disk_log"}}}]'
+ #{disk_log_opts => #{file => "./system_disk_log"}}}]'
</code>
</description>
<funcs>
<func>
- <name name="disk_log_sync" arity="1" clause_i="1"/>
+ <name name="sync" arity="1" clause_i="1"/>
<fsummary>Writes buffered data to disk.</fsummary>
<desc>
<p>Write buffered data to disk.</p>
@@ -143,9 +143,9 @@ erl -kernel logger '[{handler,default,logger_disk_log_h,
<section>
<title>See Also</title>
- <p><seealso marker="logger"><c>logger(3)</c></seealso></p>
- <p><seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso></p>
- <p><seealso marker="disk_log"><c>disk_log(3)</c></seealso></p>
+ <p><seealso marker="logger"><c>logger(3)</c></seealso>,
+ <seealso marker="logger_std_h"><c>logger_std_h(3)</c></seealso>,
+ <seealso marker="disk_log"><c>disk_log(3)</c></seealso></p>
</section>
</erlref>
diff --git a/lib/kernel/doc/src/logger_filters.xml b/lib/kernel/doc/src/logger_filters.xml
index f92181ea3f..90f1fcc270 100644
--- a/lib/kernel/doc/src/logger_filters.xml
+++ b/lib/kernel/doc/src/logger_filters.xml
@@ -36,15 +36,15 @@
<modulesummary>Filters to use with Logger.</modulesummary>
<description>
- <p>All functions exported from this module can be used as logger
+ <p>All functions exported from this module can be used as primary
or handler
- filters. See <seealso marker="logger#add_logger_filter-2">
- <c>logger:add_logger_filter/2</c></seealso>
+ filters. See <seealso marker="logger#add_primary_filter-2">
+ <c>logger:add_primary_filter/2</c></seealso>
and <seealso marker="logger#add_handler_filter-3">
<c>logger:add_handler_filter/3</c></seealso> for more information
about how filters are added.</p>
- <p>Filters are removed with <seealso marker="logger#remove_logger_filter-1">
- <c>logger:remove_logger_filter/1</c></seealso>
+ <p>Filters are removed with <seealso marker="logger#remove_primary_filter-1">
+ <c>logger:remove_primary_filter/1</c></seealso>
and <seealso marker="logger#remove_handler_filter-2">
<c>logger:remove_handler_filter/2</c></seealso>.</p>
</description>
@@ -64,18 +64,18 @@
<p>A domain field must be a list of atoms, creating smaller
and more specialized domains as the list grows longer. The
- biggest domain is <c>[]</c>, which comprices all
- possible domains.</p>
+ greatest domain is <c>[]</c>, which comprises all possible
+ domains.</p>
<p>For example, consider the following domains:</p>
<pre>
-D1 = [beam,erlang,otp]
-D2 = [beam,erlang,otp,sasl]</pre>
+D1 = [otp]
+D2 = [otp, sasl]</pre>
- <p><c>D1</c> is the biggest of the two, and is said to be a
+ <p><c>D1</c> is the greatest of the two, and is said to be a
super-domain of <c>D2</c>. <c>D2</c> is a
sub-domain <c>D1</c>. Both <c>D1</c> and <c>D2</c> are
- sub-domains of <c>[]</c></p>
+ sub-domains of <c>[]</c>.</p>
<p>The above domains are used for logs originating from
Erlang/OTP. D1 specifies that the log event comes from
@@ -86,50 +86,50 @@ D2 = [beam,erlang,otp,sasl]</pre>
<p>The <c><anno>Extra</anno></c> parameter to
the <c>domain/2</c> function is specified when adding the
- filter via <seealso marker="logger#add_logger_filter-2">
- <c>logger:add_logger_filter/2</c></seealso>
+ filter via <seealso marker="logger#add_primary_filter-2">
+ <c>logger:add_primary_filter/2</c></seealso>
or <seealso marker="logger#add_handler_filter-3">
<c>logger:add_handler_filter/3</c></seealso>.</p>
- <p>The filter compares the value of the <c>domain</c> field
- in the log event's metadata (<c>Domain</c>)
- to <c><anno>MatchDomain</anno></c> as follows:</p>
+ <p>The filter compares the value of the <c>domain</c> field in
+ the log event's metadata (<c>Domain</c>) against
+ <c><anno>MatchDomain</anno></c>. The filter matches if the
+ value of <c>Compare</c> is:</p>
<taglist>
- <tag><c><anno>Compare</anno> = sub</c></tag>
+ <tag><c>sub</c></tag>
<item>
- <p>The filter matches if <c>Domain</c> is equal to or
- a sub-domain of <c>MatchDomain</c>, that is,
- if <c>MatchDomain</c> is a prefix of <c>Domain</c>.</p>
+ <p>and <c>Domain</c> is equal to or a sub-domain
+ of <c>MatchDomain</c>, that is, if <c>MatchDomain</c> is
+ a prefix of <c>Domain</c>.</p>
</item>
- <tag><c><anno>Compare</anno> = super</c></tag>
+ <tag><c>super</c></tag>
<item>
- <p>The filter matches if <c>Domain</c> is equal to or a
- super-domain of <c>MatchDomain</c>, that is,
- if <c>Domain</c> is a prefix of <c>MatchDomain</c>.</p>
+ <p>and <c>Domain</c> is equal to or a super-domain
+ of <c>MatchDomain</c>, that is, if <c>Domain</c> is a
+ prefix of <c>MatchDomain</c>.</p>
</item>
- <tag><c><anno>Compare</anno> = equal</c></tag>
+ <tag><c>equal</c></tag>
<item>
- <p>The filter matches if <c>Domain</c> is equal
- to <c>MatchDomain</c>.</p>
+ <p>and <c>Domain</c> is equal to <c>MatchDomain</c>.</p>
</item>
- <tag><c><anno>Compare</anno> = not_equal</c></tag>
+ <tag><c>not_equal</c></tag>
<item>
- <p>The filter matches if <c>Domain</c> is not equal
- to <c>MatchDomain</c>, or if there is no domain field in
- metadata.</p>
+ <p>and <c>Domain</c> differs from <c>MatchDomain</c>, or
+ if there is no domain field in metadata.</p>
</item>
- <tag><c><anno>Compare</anno> = undefined</c></tag>
- <item><p>The filter matches if there is no domain field in
- metadata. In this case <c><anno>MatchDomain</anno></c>
- must be set to <c>[]</c>.</p>
+ <tag><c>undefined</c></tag>
+ <item>
+ <p>and there is no domain field in metadata. In this
+ case <c><anno>MatchDomain</anno></c> must be set
+ to <c>[]</c>.</p>
</item>
</taglist>
- <p>If the filter matches and <c><anno>Action</anno> = log</c>,
- the log event is allowed. If the filter matches
- and <c><anno>Action</anno> = stop</c>, the log event is
- stopped.</p>
+ <p>If the filter matches and <c><anno>Action</anno></c> is
+ <c>log</c>, the log event is allowed. If the filter matches
+ and <c><anno>Action</anno></c> is <c>stop</c>, the log event
+ is stopped.</p>
<p>If the filter does not match, it returns <c>ignore</c>,
meaning that other filters, or the value of the
@@ -137,16 +137,16 @@ D2 = [beam,erlang,otp,sasl]</pre>
event is allowed or not.</p>
<p>Log events that do not contain any domain field, match only
- when <c><anno>Compare</anno> = undefined</c>
- or <c><anno>Compare</anno> = not_equal</c>.</p>
+ when <c><anno>Compare</anno></c> is equal
+ to <c>undefined</c> or <c>not_equal</c>.</p>
- <p>Example: stop all events with
- domain <c>[beam,erlang,otp,sasl|_]</c></p>
+ <p>Example: stop all events with domain <c>[otp,
+ sasl | _]</c></p>
<code>
-logger:set_handler_config(h1,filter_default,log). % this is the default
-Filter = {fun logger_filters:domain/2,{stop,sub,[beam,erlang,otp,sasl]}}.
-logger:add_handler_filter(h1,no_sasl,Filter).
+logger:set_handler_config(h1, filter_default, log). % this is the default
+Filter = {fun logger_filters:domain/2, {stop, sub, [otp, sasl]}}.
+logger:add_handler_filter(h1, no_sasl, Filter).
ok</code>
</desc>
</func>
@@ -157,34 +157,44 @@ ok</code>
<desc>
<p>This filter provides a way of filtering log events based
on the log level. It matches log events by comparing the
- log level with a predefined <c>MatchLevel</c></p>
+ log level with a specified <c>MatchLevel</c></p>
<p>The <c><anno>Extra</anno></c> parameter is specified when
adding the filter
- via <seealso marker="logger#add_logger_filter-2">
- <c>logger:add_logger_filter/2</c></seealso>
+ via <seealso marker="logger#add_primary_filter-2">
+ <c>logger:add_primary_filter/2</c></seealso>
or <seealso marker="logger#add_handler_filter-3">
<c>logger:add_handler_filter/3</c></seealso>.</p>
<p>The filter compares the value of the event's log level
(<c>Level</c>) to <c><anno>MatchLevel</anno></c> by
calling <seealso marker="logger#compare_levels-2">
- <c>logger:compare_levels(Level,MatchLevel) -> CmpRet</c></seealso>. It
- matches the event if:</p>
-
- <list>
- <item><c>CmpRet = eq</c> and <c><anno>Operator</anno> =
- eq | lteq | gteq</c></item>
- <item><c>CmpRet = lt</c> and <c><anno>Operator</anno> =
- lt | lteq | neq</c></item>
- <item><c>CmpRet = gt</c> and <c><anno>Operator</anno> =
- gt | gteq | neq</c></item>
- </list>
-
- <p>If the filter matches and <c><anno>Action</anno> =
- log</c>, the log event is allowed. If the filter matches
- and <c><anno>Action</anno> = stop</c>, the log event is
- stopped.</p>
+ <c>logger:compare_levels(Level, MatchLevel)</c></seealso>.
+ The filter matches if the value
+ of <c><anno>Operator</anno></c> is:</p>
+
+ <taglist>
+ <tag><c>neq</c></tag>
+ <item><p>and the compare function returns <c>lt</c>
+ or <c>gt</c>.</p></item>
+ <tag><c>eq</c></tag>
+ <item><p>and the compare function returns <c>eq</c>.</p></item>
+ <tag><c>lt</c></tag>
+ <item><p>and the compare function returns <c>lt</c>.</p></item>
+ <tag><c>gt</c></tag>
+ <item><p>and the compare function returns <c>gt</c>.</p></item>
+ <tag><c>lteq</c></tag>
+ <item><p>and the compare function returns <c>lt</c>
+ or <c>eq</c>.</p></item>
+ <tag><c>gteq</c></tag>
+ <item><p>and the compare function returns <c>gt</c>
+ or <c>eq</c>.</p></item>
+ </taglist>
+
+ <p>If the filter matches and <c><anno>Action</anno></c> is
+ <c>log</c>, the log event is allowed. If the filter
+ matches and <c><anno>Action</anno></c> is <c>stop</c>, the
+ log event is stopped.</p>
<p>If the filter does not match, it returns <c>ignore</c>,
meaning that other filters, or the value of the
@@ -194,9 +204,9 @@ ok</code>
<p>Example: only allow debug level log events</p>
<code>
-logger:set_handler_config(h1,filter_default,stop).
-Filter = {fun logger_filters:level/2,{log,eq,debug}}.
-logger:add_handler_filter(h1,debug_only,Filter).
+logger:set_handler_config(h1, filter_default, stop).
+Filter = {fun logger_filters:level/2, {log, eq, debug}}.
+logger:add_handler_filter(h1, debug_only, Filter).
ok</code>
</desc>
</func>
@@ -208,9 +218,9 @@ ok</code>
<p>This filter matches all progress reports
from <c>supervisor</c> and <c>application_controller</c>.</p>
- <p>If <c><anno>Extra</anno> = log</c>, the progress reports
- are allowed. If <c><anno>Extra</anno> = stop</c>, the
- progress reports are stopped.</p>
+ <p>If <c><anno>Extra</anno></c> is <c>log</c>, the progress
+ reports are allowed. If <c><anno>Extra</anno></c>
+ is <c>stop</c>, the progress reports are stopped.</p>
<p>The filter returns <c>ignore</c> for all other log events.</p>
</desc>
@@ -223,9 +233,9 @@ ok</code>
<p>This filter matches all events originating from a process
that has its group leader on a remote node.</p>
- <p>If <c><anno>Extra</anno> = log</c>, the matching events
- are allowed. If <c><anno>Extra</anno> = stop</c>, the
- matching events are stopped.</p>
+ <p>If <c><anno>Extra</anno></c> is <c>log</c>, the matching
+ events are allowed. If <c><anno>Extra</anno></c>
+ is <c>stop</c>, the matching events are stopped.</p>
<p>The filter returns <c>ignore</c> for all other log events.</p>
</desc>
@@ -233,6 +243,12 @@ ok</code>
</funcs>
+ <section>
+ <title>See Also</title>
+ <p>
+ <seealso marker="logger"><c>logger(3)</c></seealso>
+ </p>
+ </section>
</erlref>
diff --git a/lib/kernel/doc/src/logger_formatter.xml b/lib/kernel/doc/src/logger_formatter.xml
index 02f89b26be..59f5dbe367 100644
--- a/lib/kernel/doc/src/logger_formatter.xml
+++ b/lib/kernel/doc/src/logger_formatter.xml
@@ -36,12 +36,15 @@
<modulesummary>Default formatter for Logger.</modulesummary>
<description>
- <p>Each log handler has a configured formatter specified as a
+ <p>Each Logger handler has a configured formatter specified as a
module and a configuration term. The purpose of the formatter is
to translate the log events to a final printable string
(<seealso marker="stdlib:unicode#type-chardata"><c>unicode:chardata()</c>
- </seealso>) which can be written to the output
- device of the handler.</p>
+ </seealso>) which can be written to the output device of the
+ handler. See
+ sections <seealso marker="logger_chapter#handlers">Handlers</seealso>
+ and <seealso marker="logger_chapter#formatters">Formatters</seealso>
+ in the Kernel User's Guide for more information.</p>
<p><c>logger_formatter</c> is the default formatter used by
Logger.</p>
</description>
@@ -55,7 +58,8 @@
<seealso marker="stdlib:maps">map</seealso>, and the
following keys can be set as configuration parameters:</p>
<taglist>
- <tag><c>chars_limit = pos_integer() | unlimited</c></tag>
+ <tag><marker id="chars_limit"/>
+ <c>chars_limit = integer() > 0 | unlimited</c></tag>
<item>
<p>A positive integer representing the value of the option
with the same name to be used when calling
@@ -65,14 +69,8 @@
for each log event. Notice that this is a soft limit. For a
hard truncation limit, see option <c>max_size</c>.</p>
<p>Defaults to <c>unlimited</c>.</p>
- <note>
- <p><c>chars_limit</c> has no effect on log messages on
- string form. These are expected to be short, but can
- still be truncated by the <c>max_size</c>
- parameter.</p>
- </note>
</item>
- <tag><marker id="depth"/><c>depth = pos_integer() | unlimited</c></tag>
+ <tag><marker id="depth"/><c>depth = integer() > 0 | unlimited</c></tag>
<item>
<p>A positive integer representing the maximum depth to
which terms shall be printed by this formatter. Format
@@ -83,26 +81,23 @@
<seealso marker="stdlib:io#format-2">io:format/2,3</seealso>
in STDLIB.</p>
<p>Defaults to <c>unlimited</c>.</p>
- <note>
- <p><c>depth</c> has no effect on log messages on string
- form. These are expected to be short, but can still be
- truncated by the <c>max_size</c> parameter.</p>
- </note>
</item>
<tag><c>legacy_header = boolean()</c></tag>
<item>
<p>If set to <c>true</c> a header field is added to
logger_formatter's part of <c>Metadata</c>. The value of
this field is a string similar to the header created by
- the old <c>error_logger</c> event handlers. It can be
- included in the log event by adding the
- tuple <c>{logger_formatter,header}</c> to the
+ the
+ old <seealso marker="error_logger"><c>error_logger</c></seealso>
+ event handlers. It can be included in the log event by
+ adding the list <c>[logger_formatter,header]</c> to the
template. See the description of
the <seealso marker="#type-template"><c>template()</c></seealso>
type for more information.</p>
<p>Defaults to <c>false</c>.</p>
</item>
- <tag><c>max_size = pos_integer() | unlimited</c></tag>
+ <tag><marker id="max_size"/>
+ <c>max_size = integer() > 0 | unlimited</c></tag>
<item>
<p>A positive integer representing the absolute maximum size a
string returned from this formatter can have. If the
@@ -110,12 +105,12 @@
by <c>chars_limit</c> or <c>depth</c>, it is truncated.</p>
<p>Defaults to <c>unlimited</c>.</p>
</item>
- <tag><c>report_cb = fun((</c><seealso marker="logger#type-report"><c>logger:report()</c></seealso><c>) -> {</c><seealso marker="stdlib:io#type-format"><c>io:format()</c></seealso><c>,[term()]})</c></tag>
+ <tag><c>report_cb = fun((</c><seealso marker="logger#type-report"><c>logger:report()</c></seealso><c>) -> {</c><seealso marker="stdlib:io#type-format"><c>io:format()</c></seealso><c>, [term()]})</c></tag>
<item>
<p>A report callback is used by the formatter to transform
log messages on report form to a format string and
arguments. The report callback can be specified in the
- metadata for the log event. If no report callback exist
+ metadata for the log event. If no report callback exists
in metadata, <c>logger_formatter</c> will
use <seealso marker="logger#format_report-1">
<c>logger:format_report/1</c></seealso> as default
@@ -131,12 +126,14 @@
<tag><c>single_line = boolean()</c></tag>
<item>
<p>If set to <c>true</c>, all newlines in the message are
- replaced with <c>", "</c>, and whitespaces following
- directly after newlines are removed. Note that newlines
+ replaced with <c>", "</c>, and white spaces following
+ directly after newlines are removed. Notice that newlines
added by the <c>template</c> parameter are not replaced.</p>
<p>Defaults to <c>true</c>.</p>
</item>
- <tag><c>template = </c><seealso marker="#type-template"><c>template()</c></seealso></tag>
+ <tag><marker id="template"/>
+ <c>template = </c><seealso marker="#type-template"><c>template()</c>
+ </seealso></tag>
<item>
<p>The template describes how the formatted string is
composed by combining different data values from the log
@@ -184,31 +181,42 @@
</desc>
</datatype>
<datatype>
+ <name name="metakey"/>
+ <desc>
+ <p></p>
+ </desc>
+ </datatype>
+ <datatype>
<name name="template"/>
<desc>
- <p>The template is a list of atoms, tuples and strings. The
+ <p>The template is a list of atoms, atom lists, tuples and strings. The
atoms <c>level</c> or <c>msg</c>, are treated as
placeholders for the severity level and the log message,
- respectively. Other atoms or tuples are interpreted as
+ respectively. Other atoms or atom lists are interpreted as
placeholders for metadata, where atoms are expected to match
- top level keys, and tuples represent paths to sub keys when
+ top level keys, and atom lists represent paths to sub keys when
the metadata is a nested map. For example the
- tuple <c>{key1,key2}</c> is replaced by the value of
+ list <c>[key1,key2]</c> is replaced by the value of
the <c>key2</c> field in the nested map below. The
atom <c>key1</c> on its own is replaced by the complete
value of the <c>key1</c> field. The values are converted to
strings.</p>
-<code>
-#{key1=>#{key2=>my_value,
- ...}
+ <code>
+#{key1 => #{key2 => my_value,
+ ...}
...}</code>
- <p>Strings in the template are printed literally.</p>
- <p>The default template differs depending on the values
- of <c>legacy_header</c>
- and <c>single_line</c>:</p>
+ <p>Tuples in the template express if-exist tests for metadata
+ keys. For example, the following tuple says that
+ if <c>key1</c> exists in the metadata map,
+ print <c>"key1=Value"</c>, where <c>Value</c> is the value
+ that <c>key1</c> is associated with in the metadata map. If
+ <c>key1</c> does not exist, print nothing.</p>
+ <code>
+{key1, ["key1=",key1], []}</code>
+ <p>Strings in the template are printed literally.</p>
<p>The default value for the <c>template</c> configuration
parameter depends on the value of the <c>single_line</c>
and <c>legacy_header</c> configuration parameters as
@@ -216,13 +224,13 @@
<p>The log event used in the examples is:</p>
<code>
-?LOG_ERROR("name: ~p~nexit_reason: ~p",[my_name,"It crashed"])</code>
+?LOG_ERROR("name: ~p~nexit_reason: ~p", [my_name, "It crashed"])</code>
<taglist>
- <tag><c>legacy_header=true, single_line=false</c></tag>
+ <tag><c>legacy_header = true, single_line = false</c></tag>
<item>
<p>Default
- template: <c>[{logger_formatter,header},"\n",msg,"\n"]</c></p>
+ template: <c>[[logger_formatter,header],"\n",msg,"\n"]</c></p>
<p>Example log entry:</p>
<code type="none">
@@ -231,15 +239,16 @@ name: my_name
exit_reason: "It crashed"</code>
<p>Notice that all eight levels can occur in the heading,
- not only <c>ERROR</c>, <c>WARNING</c> or <c>INFO</c> as the
- old <c>error_logger</c> produced. And microseconds are
- added at the end of the timestamp.</p>
+ not only <c>ERROR</c>, <c>WARNING</c> or <c>INFO</c> as
+ <seealso marker="error_logger"><c>error_logger</c></seealso>
+ produces. And microseconds are added at the end of the
+ timestamp.</p>
</item>
- <tag><c>legacy_header=true, single_line=true</c></tag>
+ <tag><c>legacy_header = true, single_line = true</c></tag>
<item>
<p>Default
- template: <c>[{logger_formatter,header},"\n",msg,"\n"]</c></p>
+ template: <c>[[logger_formatter,header],"\n",msg,"\n"]</c></p>
<p>Notice that the template is here the same as
for <c>single_line=false</c>, but the resulting log entry
@@ -250,7 +259,7 @@ exit_reason: "It crashed"</code>
name: my_name, exit_reason: "It crashed"</code>
</item>
- <tag><c>legacy_header=false, single_line=true</c></tag>
+ <tag><c>legacy_header = false, single_line = true</c></tag>
<item>
<p>Default template: <c>[time," ",level,": ",msg,"\n"]</c></p>
@@ -259,7 +268,7 @@ name: my_name, exit_reason: "It crashed"</code>
2018-05-17T18:31:31.152864+02:00 error: name: my_name, exit_reason: "It crashed"</code>
</item>
- <tag><c>legacy_header=false, single_line=false</c></tag>
+ <tag><c>legacy_header = false, single_line = false</c></tag>
<item>
<p>Default template: <c>[time," ",level,":\n",msg,"\n"]</c></p>
@@ -279,10 +288,21 @@ exit_reason: "It crashed"</code>
<name name="check_config" arity="1"/>
<fsummary>Validates the given formatter configuration.</fsummary>
<desc>
- <p>This callback function is called by Logger when the
- formatter configuration for a handler is set or modified. It
+ <p>The function is called by Logger when the formatter
+ configuration for a handler is set or modified. It
returns <c>ok</c> if the configuration is valid,
and <c>{error,term()}</c> if it is faulty.</p>
+ <p>The following Logger API functions can trigger this callback:</p>
+ <list>
+ <item><seealso marker="logger#add_handler-3">
+ <c>logger:add_handler/3</c></seealso></item>
+ <item><seealso marker="logger#set_handler_config-2">
+ <c>logger:set_handler_config/2,3</c></seealso></item>
+ <item><seealso marker="logger#update_handler_config-2">
+ <c>logger:updata_handler_config/2</c></seealso></item>
+ <item><seealso marker="logger#update_formatter_config-2">
+ <c>logger:update_formatter_config/2</c></seealso></item>
+ </list>
</desc>
</func>
<func>
@@ -293,22 +313,38 @@ exit_reason: "It crashed"</code>
handlers. The log event is processed as follows:</p>
<list>
<item>If the message is on report form, it is converted to
- <c>{Format,Args}</c> by calling the report
- callback.</item>
- <item>The size is limited according to the values of
- configuration parameters <c>chars_limit</c>
- and <c>depth</c>. Notice that this does not apply to
- messages on string form.</item>
+ <c>{Format,Args}</c> by calling the report callback. See
+ section <seealso marker="logger_chapter#log_message">Log
+ Message</seealso> in the Kernel User's Guide for more
+ information about report callbacks and valid forms of log
+ messages.</item>
+ <item>The message size is limited according to the values of
+ configuration parameters <seealso marker="#chars_limit">
+ <c>chars_limit</c></seealso>
+ and <seealso marker="#depth"><c>depth</c></seealso>.</item>
<item>The full log entry is composed according to
- the <c>template</c>.</item>
+ the <seealso marker="#template"><c>template</c></seealso>.</item>
<item>If the final string is too long, it is truncated
according to the value of configuration
- parameter <c>max_size</c>.</item>
+ parameter <seealso marker="#max_size"><c>max_size</c></seealso>.</item>
</list>
</desc>
</func>
</funcs>
+ <section>
+ <title>See Also</title>
+ <p>
+ <seealso marker="stdlib:calendar"><c>calendar(3)</c></seealso>,
+ <seealso marker="error_logger"><c>error_logger(3)</c></seealso>,
+ <seealso marker="stdlib:io"><c>io(3)</c></seealso>,
+ <seealso marker="stdlib:io_lib"><c>io_lib(3)</c></seealso>,
+ <seealso marker="logger"><c>logger(3)</c></seealso>,
+ <seealso marker="stdlib:maps"><c>maps(3)</c></seealso>,
+ <seealso marker="sasl:sasl_app"><c>sasl(6)</c></seealso>,
+ <seealso marker="stdlib:unicode"><c>unicode(3)</c></seealso>
+ </p>
+ </section>
</erlref>
diff --git a/lib/kernel/doc/src/logger_std_h.xml b/lib/kernel/doc/src/logger_std_h.xml
index a4f2848037..89e11389c5 100644
--- a/lib/kernel/doc/src/logger_std_h.xml
+++ b/lib/kernel/doc/src/logger_std_h.xml
@@ -54,7 +54,7 @@
general configuration parameters, as documented in the
<seealso marker="logger_chapter#handler_configuration"><c>User's Guide</c>
</seealso>, as well as handler specific parameters. The specific parameters
- are stored in a sub map with the key <c>logger_std_h</c>. The following
+ are stored in a sub map with the key <c>config</c>. The following
keys and values may be specified:</p>
<taglist>
<tag><marker id="type"/><c>type</c></tag>
@@ -78,7 +78,7 @@
If <c>no_repeat</c> is set as value, the repeated file sync operation
is disabled, and it will be the operating system settings that determine
how quickly or slowly data gets written to disk. The user can also call
- the <seealso marker="logger_std_h#filesync-1"><c>filesync/1</c></seealso>
+ the <seealso marker="logger_std_h#sync-1"><c>sync/1</c></seealso>
function to perform a file sync.</p></item>
</taglist>
<p>There are a number of other configuration parameters available, that are
@@ -99,26 +99,26 @@
logger:add_handler(my_standard_h, logger_std_h,
#{level => info,
filter_default => log,
- logger_std_h =>
- #{type => {file,"./system_info.log"},
- filesync_repeat_interval => 1000}}).
+ config =>
+ #{type => {file,"./system_info.log"},
+ filesync_repeat_interval => 1000}}).
</code>
<p>In order to configure the default handler (that starts initially with
the Kernel application) to log to file instead of <c>standard_io</c>,
change the Kernel default logger to use a file. Example:</p>
<code type="none">
erl -kernel logger '[{handler,default,logger_std_h,
- #{ logger_std_h => #{ type => {file,"./log.log"}}}}]'
+ #{config => #{type => {file,"./log.log"}}}}]'
</code>
<p>An example of how to replace the standard handler with a disk_log handler
- at startup can be found in the manual of
+ at start up can be found in the manual of
<seealso marker="logger_disk_log_h"><c>logger_disk_log_h</c></seealso>.</p>
</description>
<funcs>
<func>
- <name name="filesync" arity="1" clause_i="1"/>
+ <name name="sync" arity="1" clause_i="1"/>
<fsummary>Writes buffered data to disk.</fsummary>
<desc>
<p>Write buffered data to disk.</p>
@@ -129,8 +129,9 @@ erl -kernel logger '[{handler,default,logger_std_h,
<section>
<title>See Also</title>
- <p><seealso marker="logger"><c>logger(3)</c></seealso></p>
- <p><seealso marker="logger_disk_log_h"><c>logger_disk_log_h(3)</c></seealso></p>
+ <p><seealso marker="logger"><c>logger(3)</c></seealso>,
+ <seealso marker="logger_disk_log_h">
+ <c>logger_disk_log_h(3)</c></seealso></p>
</section>
</erlref>
diff --git a/lib/kernel/doc/src/part.xml b/lib/kernel/doc/src/part.xml
index 68eb4530e2..fa7e92835f 100644
--- a/lib/kernel/doc/src/part.xml
+++ b/lib/kernel/doc/src/part.xml
@@ -4,7 +4,7 @@
<part xmlns:xi="http://www.w3.org/2001/XInclude">
<header>
<copyright>
- <year>1996</year><year>2017</year>
+ <year>2018</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -22,17 +22,14 @@
</legalnotice>
- <title>Logger User's Guide</title>
+ <title>Kernel User's Guide</title>
<prepared>OTP Team</prepared>
<docno></docno>
- <date>2017-12-01</date>
- <rev>0.1</rev>
+ <date>2018-06-06</date>
<file>part.xml</file>
</header>
<description>
- <p>The System Architecture Support Libraries SASL application
- provides support for alarm handling, release handling, and
- related functions.</p>
+ <p></p>
</description>
<xi:include href="introduction_chapter.xml"/>
<xi:include href="logger_chapter.xml"/>
diff --git a/lib/kernel/src/application_controller.erl b/lib/kernel/src/application_controller.erl
index ff5df667b5..0dad6ae935 100644
--- a/lib/kernel/src/application_controller.erl
+++ b/lib/kernel/src/application_controller.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -1914,19 +1914,19 @@ info_started(Name, Node) ->
?LOG_INFO(#{label=>{application_controller,progress},
report=>[{application, Name},
{started_at, Node}]},
- #{domain=>[beam,erlang,otp,sasl],
+ #{domain=>[otp,sasl],
report_cb=>fun logger:format_otp_report/1,
logger_formatter=>#{title=>"PROGRESS REPORT"},
error_logger=>#{tag=>info_report,type=>progress}}).
info_exited(Name, Reason, Type) ->
- ?LOG_INFO(#{label=>{application_controller,exit},
- report=>[{application, Name},
- {exited, Reason},
- {type, Type}]},
- #{domain=>[beam,erlang,otp],
- report_cb=>fun logger:format_otp_report/1,
- error_logger=>#{tag=>info_report,type=>std_info}}).
+ ?LOG_NOTICE(#{label=>{application_controller,exit},
+ report=>[{application, Name},
+ {exited, Reason},
+ {type, Type}]},
+ #{domain=>[otp],
+ report_cb=>fun logger:format_otp_report/1,
+ error_logger=>#{tag=>info_report,type=>std_info}}).
%%-----------------------------------------------------------------
%% Reply to all processes waiting this application to be started.
@@ -2013,5 +2013,5 @@ to_string(Term) ->
true ->
Term;
false ->
- lists:flatten(io_lib:format("~134217728p", [Term]))
+ lists:flatten(io_lib:format("~0p", [Term]))
end.
diff --git a/lib/kernel/src/error_logger.erl b/lib/kernel/src/error_logger.erl
index b3957d0c7e..918a915729 100644
--- a/lib/kernel/src/error_logger.erl
+++ b/lib/kernel/src/error_logger.erl
@@ -101,8 +101,8 @@ stop() ->
%%%-----------------------------------------------------------------
%%% Callbacks for logger
--spec adding_handler(logger:config()) ->
- {ok,logger:config()} | {error,term()}.
+-spec adding_handler(logger:handler_config()) ->
+ {ok,logger:handler_config()} | {error,term()}.
adding_handler(#{id:=?MODULE}=Config) ->
case start() of
ok ->
@@ -111,12 +111,12 @@ adding_handler(#{id:=?MODULE}=Config) ->
Error
end.
--spec removing_handler(logger:config()) -> ok.
+-spec removing_handler(logger:handler_config()) -> ok.
removing_handler(#{id:=?MODULE}) ->
stop(),
ok.
--spec log(logger:log_event(),logger:config()) -> ok.
+-spec log(logger:log_event(),logger:handler_config()) -> ok.
log(#{level:=Level,msg:=Msg,meta:=Meta},_Config) ->
do_log(Level,Msg,Meta).
@@ -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
@@ -336,7 +317,7 @@ info_report(Report) ->
Report :: report().
info_report(Type, Report) ->
- logger:log(info,
+ logger:log(notice,
#{label=>{?MODULE,info_report},
report=>Report},
meta(info_report,Type)).
@@ -357,7 +338,7 @@ info_msg(Format) ->
Data :: list().
info_msg(Format, Args) ->
- logger:log(info,
+ logger:log(notice,
#{label=>{?MODULE,info_msg},
format=>Format,
args=>Args},
@@ -377,7 +358,7 @@ error_info(Error) ->
false -> {"~p",[Error]}
end,
MyMeta = #{tag=>info,type=>Error},
- logger:log(info, Format, Args, #{?MODULE=>MyMeta,domain=>[Error]}).
+ logger:log(notice, Format, Args, #{?MODULE=>MyMeta,domain=>[Error]}).
%%-----------------------------------------------------------------
%% Create metadata
@@ -532,17 +513,17 @@ tty(true) ->
_ = 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}}}} ->
+ {ok,#{module:=logger_std_h,config:=#{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]),
+ [otp]),
formatter=>{?DEFAULT_FORMATTER,
?DEFAULT_FORMAT_CONFIG},
- logger_std_h=>#{type=>standard_io}})
+ config=>#{type=>standard_io}})
end;
true ->
ok
@@ -552,7 +533,7 @@ tty(false) ->
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}}}} ->
+ {ok,#{module:=logger_std_h,config:=#{type:=standard_io}}} ->
logger:add_handler_filter(default,error_logger_tty_false,
{fun(_,_) -> stop end, ok});
_ ->
@@ -575,6 +556,8 @@ get_format_depth() ->
case application:get_env(kernel, error_logger_format_depth) of
{ok, Depth} when is_integer(Depth) ->
max(10, Depth);
+ {ok, unlimited} ->
+ unlimited;
undefined ->
unlimited
end.
diff --git a/lib/kernel/src/kernel.app.src b/lib/kernel/src/kernel.app.src
index d873178f55..390f1fa42a 100644
--- a/lib/kernel/src/kernel.app.src
+++ b/lib/kernel/src/kernel.app.src
@@ -140,9 +140,8 @@
inet_db,
pg2]},
{applications, []},
- {env, [{logger_level, info},
- {logger_sasl_compatible, false},
- {logger_progress_reports, stop}
+ {env, [{logger_level, notice},
+ {logger_sasl_compatible, false}
]},
{mod, {kernel, []}},
{runtime_dependencies, ["erts-10.0", "stdlib-3.5", "sasl-3.0"]}
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 3beb3102fa..7d121f22fe 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -35,14 +35,17 @@
%% Configuration
-export([add_handler/3, remove_handler/1,
- add_logger_filter/2, add_handler_filter/3,
- remove_logger_filter/1, remove_handler_filter/2,
- set_module_level/2, unset_module_level/1,
- set_logger_config/1, set_logger_config/2,
+ add_primary_filter/2, add_handler_filter/3,
+ remove_primary_filter/1, remove_handler_filter/2,
+ set_module_level/2,
+ unset_module_level/1, unset_module_level/0,
+ get_module_level/0, get_module_level/1,
+ set_primary_config/1, set_primary_config/2,
set_handler_config/2, set_handler_config/3,
- update_logger_config/1, update_handler_config/2,
+ update_primary_config/1, update_handler_config/2,
update_formatter_config/2, update_formatter_config/3,
- get_logger_config/0, get_handler_config/1,
+ get_primary_config/0, get_handler_config/1,
+ get_handler_config/0, get_handler_ids/0, get_config/0,
add_handlers/1]).
%% Private configuration
@@ -52,7 +55,6 @@
-export([compare_levels/2]).
-export([set_process_metadata/1, update_process_metadata/1,
unset_process_metadata/0, get_process_metadata/0]).
--export([i/0, i/1]).
%% Basic report formatting
-export([format_report/1, format_otp_report/1]).
@@ -93,19 +95,24 @@
filter_return()),filter_arg()}.
-type filter_arg() :: term().
-type filter_return() :: stop | ignore | log_event().
--type config() :: #{id => handler_id(),
- level => level(),
- filter_default => log | stop,
- filters => [{filter_id(),filter()}],
- formatter => {module(),formatter_config()},
- atom() => term()}.
+-type primary_config() :: #{level => level() | all | none,
+ filter_default => log | stop,
+ filters => [{filter_id(),filter()}]}.
+-type handler_config() :: #{id => handler_id(),
+ config => term(),
+ level => level() | all | none,
+ module => module(),
+ filter_default => log | stop,
+ filters => [{filter_id(),filter()}],
+ formatter => {module(),formatter_config()}}.
-type timestamp() :: integer().
-type formatter_config() :: #{atom() => term()}.
--type config_handler() :: {handler, handler_id(), module(), config()}.
+-type config_handler() :: {handler, handler_id(), module(), handler_config()}.
--export_type([log_event/0,level/0,report/0,msg_fun/0,metadata/0,config/0,
- handler_id/0,filter_id/0,filter/0,filter_arg/0,filter_return/0,
+-export_type([log_event/0,level/0,report/0,msg_fun/0,metadata/0,
+ primary_config/0,handler_config/0,handler_id/0,
+ filter_id/0,filter/0,filter_arg/0,filter_return/0,
config_handler/0,formatter_config/0]).
%%%-----------------------------------------------------------------
@@ -308,11 +315,11 @@ internal_log(Level,Term) when is_atom(Level) ->
%%%-----------------------------------------------------------------
%%% Configuration
--spec add_logger_filter(FilterId,Filter) -> ok | {error,term()} when
+-spec add_primary_filter(FilterId,Filter) -> ok | {error,term()} when
FilterId :: filter_id(),
Filter :: filter().
-add_logger_filter(FilterId,Filter) ->
- logger_server:add_filter(logger,{FilterId,Filter}).
+add_primary_filter(FilterId,Filter) ->
+ logger_server:add_filter(primary,{FilterId,Filter}).
-spec add_handler_filter(HandlerId,FilterId,Filter) -> ok | {error,term()} when
HandlerId :: handler_id(),
@@ -322,10 +329,10 @@ add_handler_filter(HandlerId,FilterId,Filter) ->
logger_server:add_filter(HandlerId,{FilterId,Filter}).
--spec remove_logger_filter(FilterId) -> ok | {error,term()} when
+-spec remove_primary_filter(FilterId) -> ok | {error,term()} when
FilterId :: filter_id().
-remove_logger_filter(FilterId) ->
- logger_server:remove_filter(logger,FilterId).
+remove_primary_filter(FilterId) ->
+ logger_server:remove_filter(primary,FilterId).
-spec remove_handler_filter(HandlerId,FilterId) -> ok | {error,term()} when
HandlerId :: handler_id(),
@@ -336,7 +343,7 @@ remove_handler_filter(HandlerId,FilterId) ->
-spec add_handler(HandlerId,Module,Config) -> ok | {error,term()} when
HandlerId :: handler_id(),
Module :: module(),
- Config :: config().
+ Config :: handler_config().
add_handler(HandlerId,Module,Config) ->
logger_server:add_handler(HandlerId,Module,Config).
@@ -345,16 +352,16 @@ add_handler(HandlerId,Module,Config) ->
remove_handler(HandlerId) ->
logger_server:remove_handler(HandlerId).
--spec set_logger_config(Key,Value) -> ok | {error,term()} when
+-spec set_primary_config(Key,Value) -> ok | {error,term()} when
Key :: atom(),
Value :: term().
-set_logger_config(Key,Value) ->
- logger_server:set_config(logger,Key,Value).
+set_primary_config(Key,Value) ->
+ logger_server:set_config(primary,Key,Value).
--spec set_logger_config(Config) -> ok | {error,term()} when
- Config :: config().
-set_logger_config(Config) ->
- logger_server:set_config(logger,Config).
+-spec set_primary_config(Config) -> ok | {error,term()} when
+ Config :: primary_config().
+set_primary_config(Config) ->
+ logger_server:set_config(primary,Config).
-spec set_handler_config(HandlerId,Key,Value) -> ok | {error,term()} when
HandlerId :: handler_id(),
@@ -365,59 +372,101 @@ set_handler_config(HandlerId,Key,Value) ->
-spec set_handler_config(HandlerId,Config) -> ok | {error,term()} when
HandlerId :: handler_id(),
- Config :: config().
+ Config :: handler_config().
set_handler_config(HandlerId,Config) ->
logger_server:set_config(HandlerId,Config).
--spec update_logger_config(Config) -> ok | {error,term()} when
- Config :: config().
-update_logger_config(Config) ->
- logger_server:update_config(logger,Config).
+-spec update_primary_config(Config) -> ok | {error,term()} when
+ Config :: primary_config().
+update_primary_config(Config) ->
+ logger_server:update_config(primary,Config).
-spec update_handler_config(HandlerId,Config) -> ok | {error,term()} when
HandlerId :: handler_id(),
- Config :: config().
+ Config :: handler_config().
update_handler_config(HandlerId,Config) ->
logger_server:update_config(HandlerId,Config).
--spec get_logger_config() -> {ok,Config} when
- Config :: config().
-get_logger_config() ->
- {ok,Config} = logger_config:get(?LOGGER_TABLE,logger),
- {ok,maps:remove(handlers,Config)}.
+-spec get_primary_config() -> Config when
+ Config :: primary_config().
+get_primary_config() ->
+ {ok,Config} = logger_config:get(?LOGGER_TABLE,primary),
+ maps:remove(handlers,Config).
--spec get_handler_config(HandlerId) -> {ok,{Module,Config}} | {error,term()} when
+-spec get_handler_config(HandlerId) -> {ok,Config} | {error,term()} when
HandlerId :: handler_id(),
- Module :: module(),
- Config :: config().
+ Config :: handler_config().
get_handler_config(HandlerId) ->
- logger_config:get(?LOGGER_TABLE,HandlerId).
+ case logger_config:get(?LOGGER_TABLE,HandlerId) of
+ {ok,{_,Config}} ->
+ {ok,Config};
+ Error ->
+ Error
+ end.
+
+-spec get_handler_config() -> [Config] when
+ Config :: handler_config().
+get_handler_config() ->
+ [begin
+ {ok,Config} = get_handler_config(HandlerId),
+ Config
+ end || HandlerId <- get_handler_ids()].
+
+-spec get_handler_ids() -> [HandlerId] when
+ HandlerId :: handler_id().
+get_handler_ids() ->
+ {ok,#{handlers:=HandlerIds}} = logger_config:get(?LOGGER_TABLE,primary),
+ HandlerIds.
-spec update_formatter_config(HandlerId,FormatterConfig) ->
ok | {error,term()} when
- HandlerId :: config(),
+ HandlerId :: handler_id(),
FormatterConfig :: formatter_config().
update_formatter_config(HandlerId,FormatterConfig) ->
logger_server:update_formatter_config(HandlerId,FormatterConfig).
-spec update_formatter_config(HandlerId,Key,Value) ->
ok | {error,term()} when
- HandlerId :: config(),
+ HandlerId :: handler_id(),
Key :: atom(),
Value :: term().
update_formatter_config(HandlerId,Key,Value) ->
logger_server:update_formatter_config(HandlerId,#{Key=>Value}).
--spec set_module_level(Module,Level) -> ok | {error,term()} when
+-spec set_module_level(Modules,Level) -> ok | {error,term()} when
+ Modules :: [module()] | module(),
+ Level :: level() | all | none.
+set_module_level(Module,Level) when is_atom(Module) ->
+ set_module_level([Module],Level);
+set_module_level(Modules,Level) ->
+ logger_server:set_module_level(Modules,Level).
+
+-spec unset_module_level(Modules) -> ok when
+ Modules :: [module()] | module().
+unset_module_level(Module) when is_atom(Module) ->
+ unset_module_level([Module]);
+unset_module_level(Modules) ->
+ logger_server:unset_module_level(Modules).
+
+-spec unset_module_level() -> ok.
+unset_module_level() ->
+ logger_server:unset_module_level().
+
+-spec get_module_level(Modules) -> [{Module,Level}] when
+ Modules :: [Module] | Module,
Module :: module(),
- Level :: level().
-set_module_level(Module,Level) ->
- logger_server:set_module_level(Module,Level).
-
--spec unset_module_level(Module) -> ok | {error,term()} when
- Module :: module().
-unset_module_level(Module) ->
- logger_server:unset_module_level(Module).
+ Level :: level() | all | none.
+get_module_level(Module) when is_atom(Module) ->
+ get_module_level([Module]);
+get_module_level(Modules) when is_list(Modules) ->
+ [{M,L} || {M,L} <- get_module_level(),
+ lists:member(M,Modules)].
+
+-spec get_module_level() -> [{Module,Level}] when
+ Module :: module(),
+ Level :: level() | all | none.
+get_module_level() ->
+ logger_config:get_module_level(?LOGGER_TABLE).
%%%-----------------------------------------------------------------
%%% Misc
@@ -466,82 +515,13 @@ unset_process_metadata() ->
_ = erase(?LOGGER_META_KEY),
ok.
--spec i() -> #{logger=>config(),
- handlers=>[{handler_id(),module(),config()}],
- module_levels=>[{module(),level()}]}.
-i() ->
- i(term).
-
--spec i(term) -> #{logger=>config(),
- handlers=>[{handler_id(),module(),config()}],
- module_levels=>[{module(),level()}]};
- (print) -> ok;
- (string) -> iolist().
-i(_Action = print) ->
- io:put_chars(i(string));
-i(_Action = string) ->
- #{logger := #{level := Level,
- filters := Filters,
- filter_default := FilterDefault},
- handlers := HandlerConfigs,
- module_levels := Modules} = i(term),
- [io_lib:format("Current logger configuration:~n", []),
- io_lib:format(" Level: ~p~n",[Level]),
- io_lib:format(" Filter Default: ~p~n", [FilterDefault]),
- io_lib:format(" Filters: ~n", []),
- print_filters(4, Filters),
- io_lib:format(" Handlers: ~n", []),
- print_handlers(HandlerConfigs),
- io_lib:format(" Level set per module: ~n", []),
- print_module_levels(Modules)
- ];
-i(_Action = term) ->
- {Logger, Handlers, Modules} = logger_config:get(tid()),
- #{logger=>maps:remove(handlers,Logger),
- handlers=>lists:keysort(1,Handlers),
- module_levels=>lists:keysort(1,Modules)}.
-
-print_filters(Indent, {Id, {Fun, Config}}) ->
- io_lib:format("~sId: ~p~n"
- "~s Fun: ~p~n"
- "~s Config: ~p~n",[Indent, Id, Indent, Fun, Indent, Config]);
-print_filters(Indent, Filters) ->
- IndentStr = io_lib:format("~.*s",[Indent, ""]),
- lists:map(fun(Filter) ->print_filters(IndentStr, Filter) end, Filters).
-
-
-print_handlers({Id,Module,
- #{level := Level,
- filters := Filters, filter_default := FilterDefault,
- formatter := {FormatterModule,FormatterConfig}} = Config}) ->
- MyKeys = [filter_default, filters, formatter, level, id],
- UnhandledConfig = maps:filter(fun(Key, _) ->
- not lists:member(Key, MyKeys)
- end, Config),
- Unhandled = lists:map(fun({Key, Value}) ->
- io_lib:format(" ~p: ~p~n",[Key, Value])
- end, maps:to_list(UnhandledConfig)),
- io_lib:format(" Id: ~p~n"
- " Module: ~p~n"
- " Level: ~p~n"
- " Formatter:~n"
- " Module: ~p~n"
- " Config: ~p~n"
- " Filter Default: ~p~n"
- " Filters:~n~s"
- " Handler Config:~n"
- "~s"
- "",[Id, Module, Level, FormatterModule, FormatterConfig,
- FilterDefault, print_filters(8, Filters), Unhandled]);
-print_handlers(Handlers) ->
- lists:map(fun print_handlers/1, Handlers).
-
-print_module_levels({Module,Level}) ->
- io_lib:format(" Module: ~p~n"
- " Level: ~p~n",
- [Module,Level]);
-print_module_levels(ModuleLevels) ->
- lists:map(fun print_module_levels/1, ModuleLevels).
+-spec get_config() -> #{primary=>primary_config(),
+ handlers=>[handler_config()],
+ module_levels=>[{module(),level() | all | none}]}.
+get_config() ->
+ #{primary=>get_primary_config(),
+ handlers=>get_handler_config(),
+ module_levels=>lists:keysort(1,get_module_level())}.
-spec internal_init_logger() -> ok | {error,term()}.
%% This function is responsible for config of the logger
@@ -550,13 +530,13 @@ print_module_levels(ModuleLevels) ->
%% tree is started.
internal_init_logger() ->
try
- ok = logger:set_logger_config(level, get_logger_level()),
- ok = logger:set_logger_config(filter_default, get_logger_filter_default()),
+ ok = logger:set_primary_config(level, get_logger_level()),
+ ok = logger:set_primary_config(filter_default, get_primary_filter_default()),
- [case logger:add_logger_filter(Id, Filter) of
+ [case logger:add_primary_filter(Id, Filter) of
ok -> ok;
{error, Reason} -> throw(Reason)
- end || {Id, Filter} <- get_logger_filters()],
+ end || {Id, Filter} <- get_primary_filters()],
_ = [[case logger:set_module_level(Module, Level) of
ok -> ok;
@@ -677,7 +657,7 @@ get_logger_level() ->
throw({logger_level, Level})
end.
-get_logger_filter_default() ->
+get_primary_filter_default() ->
case lists:keyfind(filters,1,get_logger_env()) of
{filters,Default,_} ->
Default;
@@ -685,7 +665,7 @@ get_logger_filter_default() ->
log
end.
-get_logger_filters() ->
+get_primary_filters() ->
lists:foldl(
fun({filters, _, Filters}, _Acc) ->
Filters;
@@ -700,7 +680,7 @@ init_default_config(Type) when Type==standard_io;
element(1,Type)==file ->
Env = get_logger_env(),
DefaultFormatter = #{formatter=>{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}},
- DefaultConfig = DefaultFormatter#{logger_std_h=>#{type=>Type}},
+ DefaultConfig = DefaultFormatter#{config=>#{type=>Type}},
NewLoggerEnv =
case lists:keyfind(default, 2, Env) of
{handler, default, Module, Config} ->
@@ -731,17 +711,9 @@ init_default_config(Type) ->
get_default_handler_filters() ->
case application:get_env(kernel, logger_sasl_compatible, false) of
true ->
- ?DEFAULT_HANDLER_FILTERS([beam,erlang,otp]);
+ ?DEFAULT_HANDLER_FILTERS([otp]);
false ->
- Extra =
- case application:get_env(kernel, logger_progress_reports, stop) of
- log ->
- [];
- stop ->
- [{stop_progress,
- {fun logger_filters:progress/2,stop}}]
- end,
- Extra ++ ?DEFAULT_HANDLER_FILTERS([beam,erlang,otp,sasl])
+ ?DEFAULT_HANDLER_FILTERS([otp,sasl])
end.
get_logger_env() ->
@@ -749,19 +721,14 @@ 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).
-
-do_log_1(Level,Msg,#{mfa:={Module,_,_}}=Meta) ->
+do_log(Level,Msg,#{mfa:={Module,_,_}}=Meta) ->
case logger_config:allow(?LOGGER_TABLE,Level,Module) of
true ->
log_allowed(#{},Level,Msg,Meta);
false ->
ok
end;
-do_log_1(Level,Msg,Meta) ->
+do_log(Level,Msg,Meta) ->
case logger_config:allow(?LOGGER_TABLE,Level) of
true ->
log_allowed(#{},Level,Msg,Meta);
diff --git a/lib/kernel/src/logger_backend.erl b/lib/kernel/src/logger_backend.erl
index b3cf7d67dd..a73b681e0d 100644
--- a/lib/kernel/src/logger_backend.erl
+++ b/lib/kernel/src/logger_backend.erl
@@ -28,9 +28,9 @@
%%%-----------------------------------------------------------------
%%% The default logger backend
log_allowed(Log, Tid) ->
- {ok,Config} = logger_config:get(Tid,logger),
+ {ok,Config} = logger_config:get(Tid,primary),
Filters = maps:get(filters,Config,[]),
- case apply_filters(logger,Log,Filters,Config) of
+ case apply_filters(primary,Log,Filters,Config) of
stop ->
ok;
Log1 ->
diff --git a/lib/kernel/src/logger_config.erl b/lib/kernel/src/logger_config.erl
index 1d35c2e068..7b2148d034 100644
--- a/lib/kernel/src/logger_config.erl
+++ b/lib/kernel/src/logger_config.erl
@@ -25,7 +25,7 @@
get/2, get/3, get/1,
create/3, create/4, set/3,
set_module_level/3,unset_module_level/2,
- cache_module_level/2,
+ get_module_level/1,cache_module_level/2,
level_to_int/1]).
-include("logger_internal.hrl").
@@ -54,7 +54,7 @@ allow(Tid,Level,Module) ->
end.
allow(Tid,Level) ->
- GlobalLevelInt = ets:lookup_element(Tid,?LOGGER_KEY,2),
+ GlobalLevelInt = ets:lookup_element(Tid,?PRIMARY_KEY,2),
level_to_int(Level) =< GlobalLevelInt.
exist(Tid,What) ->
@@ -71,7 +71,7 @@ get(Tid,What) ->
end.
get(Tid,What,Level) ->
- MS = [{{table_key(What),'$1','$2'}, % logger config
+ MS = [{{table_key(What),'$1','$2'}, % primary config
[{'>=','$1',level_to_int(Level)}],
['$2']},
{{table_key(What),'$1','$2','$3'}, % handler config
@@ -94,7 +94,7 @@ set(Tid,What,Config) ->
%% Should do this only if the level has actually changed. Possibly
%% overwrite instead of delete?
case What of
- logger ->
+ primary ->
_ = ets:select_delete(Tid,[{{'_',{'$1',cached}},
[{'=/=','$1',LevelInt}],
[true]}]),
@@ -105,27 +105,38 @@ set(Tid,What,Config) ->
ets:update_element(Tid,table_key(What),[{2,LevelInt},{3,Config}]),
ok.
-set_module_level(Tid,Module,Level) ->
- ets:insert(Tid,{Module,level_to_int(Level)}),
+set_module_level(Tid,Modules,Level) ->
+ LevelInt = level_to_int(Level),
+ [ets:insert(Tid,{Module,LevelInt}) || Module <- Modules],
ok.
-unset_module_level(Tid,Module) ->
- ets:delete(Tid,Module), % should possibley overwrite instead of delete?
+%% should possibly overwrite instead of delete?
+unset_module_level(Tid,all) ->
+ MS = [{{'$1','$2'},[{is_atom,'$1'},{is_integer,'$2'}],[true]}],
+ _ = ets:select_delete(Tid,MS),
+ ok;
+unset_module_level(Tid,Modules) ->
+ [ets:delete(Tid,Module) || Module <- Modules],
ok.
+get_module_level(Tid) ->
+ MS = [{{'$1','$2'},[{is_atom,'$1'},{is_integer,'$2'}],[{{'$1','$2'}}]}],
+ Modules = ets:select(Tid,MS),
+ lists:sort([{M,int_to_level(L)} || {M,L} <- Modules]).
+
cache_module_level(Tid,Module) ->
- GlobalLevelInt = ets:lookup_element(Tid,?LOGGER_KEY,2),
+ GlobalLevelInt = ets:lookup_element(Tid,?PRIMARY_KEY,2),
ets:insert_new(Tid,{Module,{GlobalLevelInt,cached}}),
ok.
get(Tid) ->
- {ok,Logger} = get(Tid,logger),
+ {ok,Primary} = get(Tid,primary),
HMS = [{{table_key('$1'),'_','$2','$3'},[],[{{'$1','$3','$2'}}]}],
Handlers = ets:select(Tid,HMS),
- MMS = [{{'$1','$2'},[{is_atom,'$1'},{is_integer,'$2'}],[{{'$1','$2'}}]}],
- Modules = ets:select(Tid,MMS),
- {Logger,Handlers,[{M,int_to_level(L)} || {M,L} <- Modules]}.
+ Modules = get_module_level(Tid),
+ {Primary,Handlers,Modules}.
+level_to_int(none) -> ?LOG_NONE;
level_to_int(emergency) -> ?EMERGENCY;
level_to_int(alert) -> ?ALERT;
level_to_int(critical) -> ?CRITICAL;
@@ -133,8 +144,10 @@ level_to_int(error) -> ?ERROR;
level_to_int(warning) -> ?WARNING;
level_to_int(notice) -> ?NOTICE;
level_to_int(info) -> ?INFO;
-level_to_int(debug) -> ?DEBUG.
+level_to_int(debug) -> ?DEBUG;
+level_to_int(all) -> ?LOG_ALL.
+int_to_level(?LOG_NONE) -> none;
int_to_level(?EMERGENCY) -> emergency;
int_to_level(?ALERT) -> alert;
int_to_level(?CRITICAL) -> critical;
@@ -142,10 +155,11 @@ int_to_level(?ERROR) -> error;
int_to_level(?WARNING) -> warning;
int_to_level(?NOTICE) -> notice;
int_to_level(?INFO) -> info;
-int_to_level(?DEBUG) -> debug.
+int_to_level(?DEBUG) -> debug;
+int_to_level(?LOG_ALL) -> all.
%%%-----------------------------------------------------------------
%%% Internal
-table_key(logger) -> ?LOGGER_KEY;
+table_key(primary) -> ?PRIMARY_KEY;
table_key(HandlerId) -> {?HANDLER_KEY,HandlerId}.
diff --git a/lib/kernel/src/logger_disk_log_h.erl b/lib/kernel/src/logger_disk_log_h.erl
index 773aa75bc6..a074d0210e 100644
--- a/lib/kernel/src/logger_disk_log_h.erl
+++ b/lib/kernel/src/logger_disk_log_h.erl
@@ -26,16 +26,17 @@
-include("logger_h_common.hrl").
%%% API
--export([start_link/3, info/1, disk_log_sync/1, reset/1]).
+-export([start_link/3, info/1, sync/1, reset/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
%% logger callbacks
--export([log/2,
- adding_handler/1, removing_handler/1,
- changing_config/2, swap_buffer/2]).
+-export([log/2, adding_handler/1, removing_handler/1, changing_config/2]).
+
+%% handler internal
+-export([log_handler_info/4]).
%%%===================================================================
%%% API
@@ -47,7 +48,7 @@
%%% handler process gets added (as a result of calling add/3).
-spec start_link(Name, Config, HandlerState) -> {ok,Pid} | {error,Reason} when
Name :: atom(),
- Config :: logger:config(),
+ Config :: logger:handler_config(),
HandlerState :: map(),
Pid :: pid(),
Reason :: term().
@@ -57,18 +58,19 @@ start_link(Name, Config, HandlerState) ->
%%%-----------------------------------------------------------------
%%%
--spec disk_log_sync(Name) -> ok | {error,Reason} when
+-spec sync(Name) -> ok | {error,Reason} when
Name :: atom(),
Reason :: handler_busy | {badarg,term()}.
-disk_log_sync(Name) when is_atom(Name) ->
+sync(Name) when is_atom(Name) ->
try
- gen_server:call(Name, disk_log_sync, ?DEFAULT_CALL_TIMEOUT)
+ gen_server:call(?name_to_reg_name(?MODULE,Name),
+ disk_log_sync, ?DEFAULT_CALL_TIMEOUT)
catch
_:{timeout,_} -> {error,handler_busy}
end;
-disk_log_sync(Name) ->
- {error,{badarg,{disk_log_sync,[Name]}}}.
+sync(Name) ->
+ {error,{badarg,{sync,[Name]}}}.
%%%-----------------------------------------------------------------
%%%
@@ -79,7 +81,8 @@ disk_log_sync(Name) ->
info(Name) when is_atom(Name) ->
try
- gen_server:call(Name, info, ?DEFAULT_CALL_TIMEOUT)
+ gen_server:call(?name_to_reg_name(?MODULE,Name),
+ info, ?DEFAULT_CALL_TIMEOUT)
catch
_:{timeout,_} -> {error,handler_busy}
end;
@@ -94,7 +97,8 @@ info(Name) ->
reset(Name) when is_atom(Name) ->
try
- gen_server:call(Name, reset, ?DEFAULT_CALL_TIMEOUT)
+ gen_server:call(?name_to_reg_name(?MODULE,Name),
+ reset, ?DEFAULT_CALL_TIMEOUT)
catch
_:{timeout,_} -> {error,handler_busy}
end;
@@ -112,23 +116,16 @@ adding_handler(#{id:=Name}=Config) ->
case check_config(adding, Config) of
{ok, Config1} ->
%% create initial handler state by merging defaults with config
- HConfig = maps:get(?MODULE, Config1, #{}),
+ HConfig = maps:get(config, Config1, #{}),
HState = maps:merge(get_init_state(), HConfig),
case logger_h_common:overload_levels_ok(HState) of
true ->
- case start(Name, Config1, HState) of
- ok ->
- %% Make sure wait_for_buffer is not stored, so we
- %% won't hang and wait for buffer on a restart
- {ok, maps:remove(wait_for_buffer,Config1)};
- Error ->
- Error
- end;
+ start(Name, Config1, HState);
false ->
- #{toggle_sync_qlen := TSQL,
- drop_new_reqs_qlen := DNRQL,
- flush_reqs_qlen := FRQL} = HState,
- {error,{invalid_levels,{TSQL,DNRQL,FRQL}}}
+ #{sync_mode_qlen := SMQL,
+ drop_mode_qlen := DMQL,
+ flush_qlen := FQL} = HState,
+ {error,{invalid_levels,{SMQL,DMQL,FQL}}}
end;
Error ->
Error
@@ -136,86 +133,89 @@ adding_handler(#{id:=Name}=Config) ->
%%%-----------------------------------------------------------------
%%% Updating handler config
-changing_config(OldConfig=#{id:=Name, disk_log_opts:=DLOpts},
- NewConfig=#{id:=Name, disk_log_opts:=DLOpts}) ->
+changing_config(OldConfig = #{id:=Name, config:=OldHConfig},
+ NewConfig = #{id:=Name, config:=NewHConfig}) ->
+ #{type:=Type, file:=File, max_no_files:=MaxFs,
+ max_no_bytes:=MaxBytes} = OldHConfig,
+ case NewHConfig of
+ #{type:=Type, file:=File, max_no_files:=MaxFs,
+ max_no_bytes:=MaxBytes} ->
+ changing_config1(OldConfig, NewConfig);
+ _ ->
+ {error,{illegal_config_change,OldConfig,NewConfig}}
+ end;
+changing_config(OldConfig, NewConfig) ->
+ {error,{illegal_config_change,OldConfig,NewConfig}}.
+
+changing_config1(OldConfig=#{config:=OldHConfig}, NewConfig) ->
case check_config(changing, NewConfig) of
- Result = {ok,NewConfig1} ->
- try gen_server:call(Name, {change_config,OldConfig,NewConfig1},
+ {ok,NewConfig1 = #{config:=NewHConfig}} ->
+ #{handler_pid:=HPid,
+ mode_tab:=ModeTab} = OldHConfig,
+ NewHConfig1 = NewHConfig#{handler_pid=>HPid,
+ mode_tab=>ModeTab},
+ NewConfig2 = NewConfig1#{config=>NewHConfig1},
+ try gen_server:call(HPid, {change_config,OldConfig,NewConfig2},
?DEFAULT_CALL_TIMEOUT) of
- ok -> Result;
+ ok -> {ok,NewConfig2};
HError -> HError
catch
_:{timeout,_} -> {error,handler_busy}
end;
Error ->
Error
- end;
-changing_config(OldConfig, NewConfig) ->
- {error,{illegal_config_change,OldConfig,NewConfig}}.
+ end.
check_config(adding, #{id:=Name}=Config) ->
- %% Merge in defaults on handler level
- LogOpts0 = maps:get(disk_log_opts, Config, #{}),
- LogOpts = merge_default_logopts(Name, LogOpts0),
- case check_log_opts(maps:to_list(LogOpts)) of
+ %% merge handler specific config data
+ HConfig = merge_default_logopts(Name, maps:get(config, Config, #{})),
+ case check_h_config(maps:to_list(HConfig)) of
ok ->
- MyConfig = maps:get(?MODULE, Config, #{}),
- case check_my_config(maps:to_list(MyConfig)) of
- ok ->
- {ok,Config#{disk_log_opts=>LogOpts,
- ?MODULE=>MyConfig}};
- Error ->
- Error
- end;
+ {ok,Config#{config=>HConfig}};
Error ->
Error
end;
check_config(changing, Config) ->
- MyConfig = maps:get(?MODULE, Config, #{}),
- case check_my_config(maps:to_list(MyConfig)) of
+ HConfig = maps:get(config, Config, #{}),
+ case check_h_config(maps:to_list(HConfig)) of
ok -> {ok,Config};
Error -> Error
end.
-merge_default_logopts(Name, LogOpts) ->
- Type = maps:get(type, LogOpts, wrap),
+merge_default_logopts(Name, HConfig) ->
+ Type = maps:get(type, HConfig, wrap),
{DefaultNoFiles,DefaultNoBytes} =
case Type of
halt -> {undefined,infinity};
_wrap -> {10,1048576}
end,
{ok,Dir} = file:get_cwd(),
- Default = #{file => filename:join(Dir,Name),
- max_no_files => DefaultNoFiles,
- max_no_bytes => DefaultNoBytes,
- type => Type},
- maps:merge(Default,LogOpts).
-
-check_log_opts([{file,File}|Opts]) when is_list(File) ->
- check_log_opts(Opts);
-check_log_opts([{max_no_files,undefined}|Opts]) ->
- check_log_opts(Opts);
-check_log_opts([{max_no_files,N}|Opts]) when is_integer(N), N>0 ->
- check_log_opts(Opts);
-check_log_opts([{max_no_bytes,infinity}|Opts]) ->
- check_log_opts(Opts);
-check_log_opts([{max_no_bytes,N}|Opts]) when is_integer(N), N>0 ->
- check_log_opts(Opts);
-check_log_opts([{type,Type}|Opts]) when Type==wrap; Type==halt ->
- check_log_opts(Opts);
-check_log_opts([Invalid|_]) ->
- {error,{invalid_config,disk_log_opt,Invalid}};
-check_log_opts([]) ->
- ok.
-
-check_my_config([Other | Config]) ->
+ Defaults = #{file => filename:join(Dir,Name),
+ max_no_files => DefaultNoFiles,
+ max_no_bytes => DefaultNoBytes,
+ type => Type},
+ maps:merge(Defaults, HConfig).
+
+check_h_config([{file,File}|Config]) when is_list(File) ->
+ check_h_config(Config);
+check_h_config([{max_no_files,undefined}|Config]) ->
+ check_h_config(Config);
+check_h_config([{max_no_files,N}|Config]) when is_integer(N), N>0 ->
+ check_h_config(Config);
+check_h_config([{max_no_bytes,infinity}|Config]) ->
+ check_h_config(Config);
+check_h_config([{max_no_bytes,N}|Config]) when is_integer(N), N>0 ->
+ check_h_config(Config);
+check_h_config([{type,Type}|Config]) when Type==wrap; Type==halt ->
+ check_h_config(Config);
+check_h_config([Other | Config]) ->
case logger_h_common:check_common_config(Other) of
valid ->
- check_my_config(Config);
+ check_h_config(Config);
invalid ->
{error,{invalid_config,?MODULE,Other}}
end;
-check_my_config([]) ->
+check_h_config([]) ->
ok.
%%%-----------------------------------------------------------------
@@ -224,86 +224,90 @@ removing_handler(#{id:=Name}) ->
stop(Name).
%%%-----------------------------------------------------------------
-%%% Get buffer when swapping from simple handler
-swap_buffer(Name,Buffer) ->
- case whereis(Name) of
- undefined ->
- ok;
- _ ->
- Name ! {buffer,Buffer}
- end.
-
-%%%-----------------------------------------------------------------
%%% Log a string or report
-spec log(LogEvent, Config) -> ok | dropped when
LogEvent :: logger:log_event(),
- Config :: logger:config().
+ Config :: logger:handler_config().
-log(LogEvent,Config=#{id:=Name}) ->
- %% if the handler has crashed, we must drop this request
+log(LogEvent, Config = #{id := Name,
+ config := #{handler_pid := HPid,
+ mode_tab := ModeTab}}) ->
+ %% if the handler has crashed, we must drop this event
%% and hope the handler restarts so we can try again
- true = is_pid(whereis(Name)),
- Bin = logger_h_common:log_to_binary(LogEvent,Config),
- logger_h_common:call_cast_or_drop(Name, Bin).
-
+ true = is_process_alive(HPid),
+ Bin = logger_h_common:log_to_binary(LogEvent, Config),
+ logger_h_common:call_cast_or_drop(Name, HPid, ModeTab, Bin).
%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
-init([Name, Config = #{disk_log_opts := LogOpts},
+init([Name,
+ Config = #{config := HConfig = #{file:=File,
+ type:=Type,
+ max_no_bytes:=MNB,
+ max_no_files:=MNF}},
State = #{dl_sync_int := DLSyncInt}]) ->
- register(Name, self()),
+
+ register(?name_to_reg_name(?MODULE,Name), self()),
process_flag(trap_exit, true),
process_flag(message_queue_data, off_heap),
?init_test_hooks(),
?start_observation(Name),
-
- case open_disk_log(Name, LogOpts) of
+
+ LogOpts = #{file=>File, type=>Type, max_no_bytes=>MNB, max_no_files=>MNF},
+ case open_disk_log(Name, File, Type, MNB, MNF) of
ok ->
- catch ets:new(Name, [public, named_table]),
- ?set_mode(Name, async),
- proc_lib:init_ack({ok,self()}),
- T0 = ?timestamp(),
- State1 =
- ?merge_with_stats(State#{id => Name,
- mode => async,
- dl_sync => DLSyncInt,
- log_opts => LogOpts,
- last_qlen => 0,
- last_log_ts => T0,
- burst_win_ts => T0,
- burst_msg_count => 0,
- last_op => sync,
- prev_log_result => ok,
- prev_sync_result => ok,
- prev_disk_log_info => undefined}),
- gen_server:cast(self(), repeated_disk_log_sync),
- enter_loop(Config, State1);
+ try ets:new(Name, [public]) of
+ ModeTab ->
+ ?set_mode(ModeTab, async),
+ T0 = ?timestamp(),
+ State1 =
+ ?merge_with_stats(State#{
+ id => Name,
+ mode_tab => ModeTab,
+ mode => async,
+ dl_sync => DLSyncInt,
+ log_opts => LogOpts,
+ last_qlen => 0,
+ last_log_ts => T0,
+ burst_win_ts => T0,
+ burst_msg_count => 0,
+ last_op => sync,
+ prev_log_result => ok,
+ prev_sync_result => ok,
+ prev_disk_log_info => undefined}),
+ Config1 =
+ Config#{config => HConfig#{handler_pid => self(),
+ mode_tab => ModeTab}},
+ proc_lib:init_ack({ok,self(),Config1}),
+ gen_server:cast(self(), repeated_disk_log_sync),
+ case logger_h_common:unset_restart_flag(Name, ?MODULE) of
+ true ->
+ %% inform about restart
+ gen_server:cast(self(), {log_handler_info,
+ "Handler ~p restarted",
+ [Name]});
+ false ->
+ %% initial start
+ ok
+ end,
+ enter_loop(Config1, State1)
+ catch
+ _:Error ->
+ logger_h_common:error_notify({open_disk_log,Name,Error}),
+ proc_lib:init_ack(Error)
+ end;
Error ->
logger_h_common:error_notify({open_disk_log,Name,Error}),
proc_lib:init_ack(Error)
end.
-enter_loop(#{wait_for_buffer:=true}=Config,State) ->
- State1 =
- receive
- {buffer,Buffer} ->
- lists:foldl(
- fun(Log,S) ->
- Bin = logger_h_common:log_to_binary(Log,Config),
- {_,S1} = do_log(Bin,cast,S),
- S1
- end,
- State,
- Buffer)
- end,
- gen_server:enter_loop(?MODULE,[],State1);
enter_loop(_Config,State) ->
gen_server:enter_loop(?MODULE,[],State).
-%% This is the synchronous log request.
+%% This is the synchronous log event.
handle_call({log, Bin}, _From, State) ->
{Result,State1} = do_log(Bin, call, State),
%% Result == ok | dropped
@@ -315,10 +319,10 @@ handle_call(disk_log_sync, _From, State = #{id := Name}) ->
handle_call({change_config,_OldConfig,NewConfig}, _From,
State = #{filesync_repeat_interval := FSyncInt0}) ->
- HConfig = maps:get(?MODULE, NewConfig, #{}),
- State1 = #{toggle_sync_qlen := TSQL,
- drop_new_reqs_qlen := DNRQL,
- flush_reqs_qlen := FRQL} = maps:merge(State, HConfig),
+ HConfig = maps:get(config, NewConfig, #{}),
+ State1 = #{sync_mode_qlen := SMQL,
+ drop_mode_qlen := DMQL,
+ flush_qlen := FQL} = maps:merge(State, HConfig),
case logger_h_common:overload_levels_ok(State1) of
true ->
_ =
@@ -339,7 +343,7 @@ handle_call({change_config,_OldConfig,NewConfig}, _From,
end,
{reply, ok, State1};
false ->
- {reply, {error,{invalid_levels,{TSQL,DNRQL,FRQL}}}, State}
+ {reply, {error,{invalid_levels,{SMQL,DMQL,FQL}}}, State}
end;
handle_call(info, _From, State) ->
@@ -357,15 +361,19 @@ handle_call(stop, _From, State) ->
{stop, {shutdown,stopped}, ok, State}.
-%% This is the asynchronous log request.
+%% This is the asynchronous log event.
handle_cast({log, Bin}, State) ->
{_,State1} = do_log(Bin, cast, State),
{noreply, State1};
+handle_cast({log_handler_info, Format, Args}, State = #{id:=Name}) ->
+ log_handler_info(Name, Format, Args, State),
+ {noreply, State};
+
%% If FILESYNC_REPEAT_INTERVAL is set to a millisec value, this
%% clause gets called repeatedly by the handler. In order to
%% guarantee that a filesync *always* happens after the last log
-%% request, the repeat operation must be active!
+%% event, the repeat operation must be active!
handle_cast(repeated_disk_log_sync,
State = #{id := Name,
filesync_repeat_interval := FSyncInt,
@@ -429,19 +437,19 @@ code_change(_OldVsn, State, _Extra) ->
%%%-----------------------------------------------------------------
%%%
get_init_state() ->
- #{toggle_sync_qlen => ?TOGGLE_SYNC_QLEN,
- drop_new_reqs_qlen => ?DROP_NEW_REQS_QLEN,
- flush_reqs_qlen => ?FLUSH_REQS_QLEN,
- enable_burst_limit => ?ENABLE_BURST_LIMIT,
- burst_limit_size => ?BURST_LIMIT_SIZE,
- burst_window_time => ?BURST_WINDOW_TIME,
- enable_kill_overloaded => ?ENABLE_KILL_OVERLOADED,
- handler_overloaded_qlen => ?HANDLER_OVERLOADED_QLEN,
- handler_overloaded_mem => ?HANDLER_OVERLOADED_MEM,
- handler_restart_after => ?HANDLER_RESTART_AFTER,
- dl_sync_int => ?CONTROLLER_SYNC_INTERVAL,
- filesync_ok_qlen => ?FILESYNC_OK_QLEN,
- filesync_repeat_interval => ?FILESYNC_REPEAT_INTERVAL}.
+ #{sync_mode_qlen => ?SYNC_MODE_QLEN,
+ drop_mode_qlen => ?DROP_MODE_QLEN,
+ flush_qlen => ?FLUSH_QLEN,
+ burst_limit_enable => ?BURST_LIMIT_ENABLE,
+ burst_limit_max_count => ?BURST_LIMIT_MAX_COUNT,
+ burst_limit_window_time => ?BURST_LIMIT_WINDOW_TIME,
+ overload_kill_enable => ?OVERLOAD_KILL_ENABLE,
+ overload_kill_qlen => ?OVERLOAD_KILL_QLEN,
+ overload_kill_mem_size => ?OVERLOAD_KILL_MEM_SIZE,
+ overload_kill_restart_after => ?OVERLOAD_KILL_RESTART_AFTER,
+ dl_sync_int => ?CONTROLLER_SYNC_INTERVAL,
+ filesync_ok_qlen => ?FILESYNC_OK_QLEN,
+ filesync_repeat_interval => ?FILESYNC_REPEAT_INTERVAL}.
%%%-----------------------------------------------------------------
%%% Add a disk_log handler to the logger.
@@ -449,22 +457,21 @@ get_init_state() ->
%%% exist if the handler is registered with logger (and should not
%%% exist if the handler is not registered).
%%%
-%%% Config is the logger:config() map containing a sub map with any of
-%%% the following associations:
+%%% Config is the logger:handler_config() map. Handler specific parameters
+%%% should be provided with a sub map associated with a key named
+%%% 'config', e.g:
%%%
-%%% Config = #{disk_log_opts => #{file => file:filename(),
-%%% max_no_bytes => integer(),
-%%% max_no_files => integer(),
-%%% type => wrap | halt}}.
+%%% Config = #{config => #{sync_mode_qlen => 50}
%%%
-%%% This map will be merged with the logger configuration data for
-%%% the disk_log LogName. If type == halt, then max_no_files is
-%%% ignored.
+%%% The 'config' sub map will also contain parameters for configuring
+%%% the disk_log:
%%%
-%%% Handler specific config should be provided with a sub map associated
-%%% with a key named the same as this module, e.g:
+%%% Config = #{config => #{file => file:filename(),
+%%% max_no_bytes => integer(),
+%%% max_no_files => integer(),
+%%% type => wrap | halt}}.
%%%
-%%% Config = #{logger_disk_log_h => #{toggle_sync_qlen => 50}
+%%% If type == halt, then max_no_files is ignored.
%%%
%%% The disk_log handler process is linked to logger_sup, which is
%%% part of the kernel application's supervision tree.
@@ -477,8 +484,8 @@ start(Name, Config, HandlerState) ->
type => worker,
modules => [?MODULE]},
case supervisor:start_child(logger_sup, LoggerDLH) of
- {ok,_} ->
- ok;
+ {ok,_Pid,Config1} ->
+ {ok,Config1};
Error ->
Error
end.
@@ -486,16 +493,16 @@ start(Name, Config, HandlerState) ->
%%%-----------------------------------------------------------------
%%% Stop and remove the handler.
stop(Name) ->
- case whereis(Name) of
+ case whereis(?name_to_reg_name(?MODULE,Name)) of
undefined ->
ok;
- _ ->
+ Pid ->
%% We don't want to do supervisor:terminate_child here
%% since we need to distinguish this explicit stop from a
%% system termination in order to avoid circular attempts
%% at removing the handler (implying deadlocks and
%% timeouts).
- _ = gen_server:call(Name,stop),
+ _ = gen_server:call(Pid, stop),
_ = supervisor:delete_child(logger_sup, Name),
ok
end.
@@ -506,21 +513,31 @@ stop(Name) ->
if C == 0 -> Interval;
true -> C-1 end).
-%% check for overload between every request (and set Mode to async,
+%% check for overload between every event (and set Mode to async,
%% sync or drop accordingly), but never flush the whole mailbox
-%% before LogWindowSize requests have been handled
-do_log(Bin, CallOrCast, State = #{id:=Name, mode := _Mode0}) ->
+%% before LogWindowSize events have been handled
+do_log(Bin, CallOrCast, State = #{id:=Name, mode := Mode0}) ->
T1 = ?timestamp(),
%% check if the handler is getting overloaded, or if it's
%% recovering from overload (the check must be done for each
- %% request to react quickly to large bursts of requests and
+ %% event to react quickly to large bursts of events and
%% to ensure that the handler can never end up in drop mode
%% with an empty mailbox, which would stop operation)
{Mode1,QLen,Mem,State1} = logger_h_common:check_load(State),
+ if (Mode1 == drop) andalso (Mode0 =/= drop) ->
+ log_handler_info(Name, "Handler ~p switched to drop mode",
+ [Name], State);
+ (Mode0 == drop) andalso ((Mode1 == async) orelse (Mode1 == sync)) ->
+ log_handler_info(Name, "Handler ~p switched to ~w mode",
+ [Name,Mode1], State);
+ true ->
+ ok
+ end,
+
%% kill the handler if it can't keep up with the load
- logger_h_common:kill_if_choked(Name, QLen, Mem, State),
+ logger_h_common:kill_if_choked(Name, QLen, Mem, ?MODULE, State),
if Mode1 == flush ->
flush(Name, QLen, T1, State1);
@@ -530,10 +547,14 @@ do_log(Bin, CallOrCast, State = #{id:=Name, mode := _Mode0}) ->
%% this function is called by do_log/3 after an overload check
%% has been performed, where QLen > FlushQLen
-flush(Name, _QLen0, T1, State=#{last_log_ts := _T0}) ->
+flush(Name, _QLen0, T1, State=#{last_log_ts := _T0, mode_tab := ModeTab}) ->
%% flush messages in the mailbox (a limited number in
%% order to not cause long delays)
- _NewFlushed = logger_h_common:flush_log_requests(?FLUSH_MAX_N),
+ NewFlushed = logger_h_common:flush_log_events(?FLUSH_MAX_N),
+
+ %% write info in log about flushed messages
+ log_handler_info(Name, "Handler ~p flushed ~w log events",
+ [Name,NewFlushed], State),
%% because of the receive loop when flushing messages, the
%% handler will be scheduled out often and the mailbox could
@@ -541,26 +562,27 @@ flush(Name, _QLen0, T1, State=#{last_log_ts := _T0}) ->
{_,_QLen1} = process_info(self(), message_queue_len),
?observe(Name,{max_qlen,_QLen1}),
- %% Add 1 for the current log request
- ?observe(Name,{flushed,_NewFlushed+1}),
+ %% Add 1 for the current log event
+ ?observe(Name,{flushed,NewFlushed+1}),
State1 = ?update_max_time(?diff_time(T1,_T0),State),
- {dropped,?update_other(flushed,FLUSHED,_NewFlushed,
- State1#{mode => ?set_mode(Name,async),
+ {dropped,?update_other(flushed,FLUSHED,NewFlushed,
+ State1#{mode => ?set_mode(ModeTab,async),
last_qlen => 0,
last_log_ts => T1})}.
%% this function is called to write to disk_log
write(Name, Mode, T1, Bin, _CallOrCast,
- State = #{dl_sync := DLSync,
+ State = #{mode_tab := ModeTab,
+ dl_sync := DLSync,
dl_sync_int := DLSyncInt,
last_qlen := LastQLen,
last_log_ts := T0}) ->
%% check if we need to limit the number of writes
- %% during a burst of log requests
+ %% during a burst of log events
{DoWrite,BurstWinT,BurstMsgCount} = logger_h_common:limit_burst(State),
- %% only send a synhrounous request to the disk_log process
+ %% only send a synhrounous event to the disk_log process
%% every DLSyncInt time, to give the handler time between
%% writes so it can keep up with incoming messages
{Status,LastQLen1,State1} =
@@ -578,18 +600,18 @@ write(Name, Mode, T1, Bin, _CallOrCast,
{dropped, LastQLen, State}
end,
- %% Check if the time since the previous log request is long enough -
+ %% Check if the time since the previous log event is long enough -
%% and the queue length small enough - to assume the mailbox has
%% been emptied, and if so, do filesync operation and reset mode to
%% async. Note that this is the best we can do to detect an idle
%% handler without setting a timer after each log call/cast. If the
- %% time between two consecutive log requests is fast and no new
- %% request comes in after the last one, idle state won't be detected!
+ %% time between two consecutive log events is fast and no new
+ %% event comes in after the last one, idle state won't be detected!
Time = ?diff_time(T1,T0),
{Mode1,BurstMsgCount1,State2} =
if (LastQLen1 < ?FILESYNC_OK_QLEN) andalso
(Time > ?IDLE_DETECT_TIME_USEC) ->
- {?change_mode(Name,Mode,async), 0, disk_log_sync(Name,State1)};
+ {?change_mode(ModeTab,Mode,async), 0, disk_log_sync(Name,State1)};
true ->
{Mode, BurstMsgCount,State1}
end,
@@ -607,11 +629,21 @@ write(Name, Mode, T1, Bin, _CallOrCast,
{Status,State4}.
-open_disk_log(Name, LogOpts) ->
- #{file := File,
- max_no_bytes := MaxNoBytes,
- max_no_files := MaxNoFiles,
- type := Type} = LogOpts,
+log_handler_info(Name, Format, Args, State) ->
+ Config =
+ case logger:get_handler_config(Name) of
+ {ok,Conf} -> Conf;
+ _ -> #{formatter=>{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}
+ end,
+ Meta = #{time=>erlang:system_time(microsecond)},
+ Bin = logger_h_common:log_to_binary(#{level => notice,
+ msg => {Format,Args},
+ meta => Meta}, Config),
+ _ = disk_log_write(Name, Bin, State),
+ ok.
+
+
+open_disk_log(Name, File, Type, MaxNoBytes, MaxNoFiles) ->
case filelib:ensure_dir(File) of
ok ->
Size =
diff --git a/lib/kernel/src/logger_formatter.erl b/lib/kernel/src/logger_formatter.erl
index 4d727b3da0..33b250eef6 100644
--- a/lib/kernel/src/logger_formatter.erl
+++ b/lib/kernel/src/logger_formatter.erl
@@ -35,7 +35,8 @@
template=>template(),
time_designator=>byte(),
time_offset=>integer()|[byte()]}.
--type template() :: [atom()|tuple()|string()].
+-type template() :: [metakey()|{metakey(),template(),template()}|string()].
+-type metakey() :: atom() | [atom()].
%%%-----------------------------------------------------------------
%%% API
@@ -53,8 +54,8 @@ format(#{level:=Level,msg:=Msg0,meta:=Meta},Config0)
[msg|Rest] -> {true,Rest};
_ ->{false,AT0}
end,
- B = do_format(Level,"",Meta1,BT,Config),
- A = do_format(Level,"",Meta1,AT,Config),
+ B = do_format(Level,Meta1,BT,Config),
+ A = do_format(Level,Meta1,AT,Config),
MsgStr =
if DoMsg ->
Config1 =
@@ -84,26 +85,37 @@ format(#{level:=Level,msg:=Msg0,meta:=Meta},Config0)
end,
truncate(B ++ MsgStr ++ A,maps:get(max_size,Config)).
-do_format(Level,Msg,Data,[level|Format],Config) ->
- [to_string(level,Level,Config)|do_format(Level,Msg,Data,Format,Config)];
-do_format(Level,Msg,Data,[Key|Format],Config) when is_atom(Key); is_tuple(Key) ->
- Value = value(Key,Data),
- [to_string(Key,Value,Config)|do_format(Level,Msg,Data,Format,Config)];
-do_format(Level,Msg,Data,[Str|Format],Config) ->
- [Str|do_format(Level,Msg,Data,Format,Config)];
-do_format(_Level,_Msg,_Data,[],_Config) ->
+do_format(Level,Data,[level|Format],Config) ->
+ [to_string(level,Level,Config)|do_format(Level,Data,Format,Config)];
+do_format(Level,Data,[{Key,IfExist,Else}|Format],Config) ->
+ String =
+ case value(Key,Data) of
+ {ok,Value} -> do_format(Level,Data#{Key=>Value},IfExist,Config);
+ error -> do_format(Level,Data,Else,Config)
+ end,
+ [String|do_format(Level,Data,Format,Config)];
+do_format(Level,Data,[Key|Format],Config)
+ when is_atom(Key) orelse
+ (is_list(Key) andalso is_atom(hd(Key))) ->
+ String =
+ case value(Key,Data) of
+ {ok,Value} -> to_string(Key,Value,Config);
+ error -> ""
+ end,
+ [String|do_format(Level,Data,Format,Config)];
+do_format(Level,Data,[Str|Format],Config) ->
+ [Str|do_format(Level,Data,Format,Config)];
+do_format(_Level,_Data,[],_Config) ->
[].
-value(Key,Meta) when is_atom(Key), is_map(Meta) ->
- maps:get(Key,Meta,"");
-value(Key,_) when is_atom(Key) ->
- "";
-value(Keys,Meta) when is_tuple(Keys) ->
- value(tuple_to_list(Keys),Meta);
-value([Key|Keys],Meta) ->
- value(Keys,value(Key,Meta));
+value(Key,Meta) when is_map_key(Key,Meta) ->
+ {ok,maps:get(Key,Meta)};
+value([Key|Keys],Meta) when is_map_key(Key,Meta) ->
+ value(Keys,maps:get(Key,Meta));
value([],Value) ->
- Value.
+ {ok,Value};
+value(_,_) ->
+ error.
to_string(time,Time,Config) ->
format_time(Time,Config);
@@ -223,7 +235,7 @@ format_mfa(MFA) ->
maybe_add_legacy_header(Level,
#{time:=Timestamp}=Meta,
#{legacy_header:=true}=Config) ->
- #{title:=Title}=MyMeta = add_legacy_title(Level,maps:get(?MODULE,Meta,#{})),
+ #{title:=Title}=MyMeta = add_legacy_title(Level,Meta,Config),
{{Y,Mo,D},{H,Mi,S},Micro,UtcStr} =
timestamp_to_datetimemicro(Timestamp,Config),
Header =
@@ -233,11 +245,23 @@ maybe_add_legacy_header(Level,
maybe_add_legacy_header(_,Meta,_) ->
Meta.
-add_legacy_title(_Level,#{title:=_}=MyMeta) ->
+add_legacy_title(_Level,#{?MODULE:=#{title:=_}=MyMeta},_) ->
MyMeta;
-add_legacy_title(Level,MyMeta) ->
- Title = string:uppercase(atom_to_list(Level)) ++ " REPORT",
- MyMeta#{title=>Title}.
+add_legacy_title(Level,Meta,Config) ->
+ case maps:get(?MODULE,Meta,#{}) of
+ #{title:=_}=MyMeta ->
+ MyMeta;
+ MyMeta ->
+ TitleLevel =
+ case (Level=:=notice andalso maps:find(error_logger,Meta)) of
+ {ok,_} ->
+ maps:get(error_logger_notice_header,Config);
+ _ ->
+ Level
+ end,
+ Title = string:uppercase(atom_to_list(TitleLevel)) ++ " REPORT",
+ MyMeta#{title=>Title}
+ end.
month(1) -> "Jan";
month(2) -> "Feb";
@@ -257,6 +281,7 @@ month(12) -> "Dec".
add_default_config(Config0) ->
Default =
#{legacy_header=>false,
+ error_logger_notice_header=>info,
single_line=>true,
chars_limit=>unlimited,
time_designator=>$T},
@@ -341,19 +366,15 @@ do_check_config([{single_line,SL}|Config]) when is_boolean(SL) ->
do_check_config(Config);
do_check_config([{legacy_header,LH}|Config]) when is_boolean(LH) ->
do_check_config(Config);
+do_check_config([{error_logger_notice_header,ELNH}|Config]) when ELNH == info;
+ ELNH == notice ->
+ do_check_config(Config);
do_check_config([{report_cb,RCB}|Config]) when is_function(RCB,1) ->
do_check_config(Config);
-do_check_config([{template,T}|Config]) when is_list(T) ->
- case lists:all(fun(X) when is_atom(X) -> true;
- (X) when is_tuple(X), is_atom(element(1,X)) -> true;
- (X) when is_list(X) -> io_lib:printable_unicode_list(X);
- (_) -> false
- end,
- T) of
- true ->
- do_check_config(Config);
- false ->
- {error,{invalid_formatter_template,?MODULE,T}}
+do_check_config([{template,T}|Config]) ->
+ case check_template(T) of
+ ok -> do_check_config(Config);
+ error -> {error,{invalid_formatter_template,?MODULE,T}}
end;
do_check_config([{time_offset,Offset}|Config]) ->
case check_offset(Offset) of
@@ -381,6 +402,42 @@ check_limit(unlimited) ->
check_limit(_) ->
error.
+check_template([Key|T]) when is_atom(Key) ->
+ check_template(T);
+check_template([Key|T]) when is_list(Key), is_atom(hd(Key)) ->
+ case lists:all(fun(X) when is_atom(X) -> true;
+ (_) -> false
+ end,
+ Key) of
+ true ->
+ check_template(T);
+ false ->
+ error
+ end;
+check_template([{Key,IfExist,Else}|T])
+ when is_atom(Key) orelse
+ (is_list(Key) andalso is_atom(hd(Key))) ->
+ case check_template(IfExist) of
+ ok ->
+ case check_template(Else) of
+ ok ->
+ check_template(T);
+ error ->
+ error
+ end;
+ error ->
+ error
+ end;
+check_template([Str|T]) when is_list(Str) ->
+ case io_lib:printable_unicode_list(Str) of
+ true -> check_template(T);
+ false -> error
+ end;
+check_template([]) ->
+ ok;
+check_template(_) ->
+ error.
+
check_offset(I) when is_integer(I) ->
ok;
check_offset(Tz) when Tz=:=""; Tz=:="Z"; Tz=:="z" ->
diff --git a/lib/kernel/src/logger_h_common.erl b/lib/kernel/src/logger_h_common.erl
index 336398cd4a..d556938f02 100644
--- a/lib/kernel/src/logger_h_common.erl
+++ b/lib/kernel/src/logger_h_common.erl
@@ -24,13 +24,15 @@
-export([log_to_binary/2,
check_common_config/1,
- call_cast_or_drop/2,
+ call_cast_or_drop/4,
check_load/1,
limit_burst/1,
- kill_if_choked/4,
- flush_log_requests/0,
- flush_log_requests/1,
+ kill_if_choked/5,
+ flush_log_events/0,
+ flush_log_events/1,
handler_exit/2,
+ set_restart_flag/2,
+ unset_restart_flag/2,
cancel_timer/1,
stop_or_restart/3,
overload_levels_ok/1,
@@ -41,7 +43,7 @@
%%% Covert log data on any form to binary
-spec log_to_binary(LogEvent,Config) -> LogString when
LogEvent :: logger:log_event(),
- Config :: logger:config(),
+ Config :: logger:handler_config(),
LogString :: binary().
log_to_binary(#{msg:={report,_},meta:=#{report_cb:=_}}=Log,Config) ->
do_log_to_binary(Log,Config);
@@ -52,7 +54,8 @@ log_to_binary(Log,Config) ->
do_log_to_binary(Log,Config).
do_log_to_binary(Log,Config) ->
- {Formatter,FormatterConfig} = maps:get(formatter,Config),
+ {Formatter,FormatterConfig} =
+ maps:get(formatter,Config,{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}),
String = try_format(Log,Formatter,FormatterConfig),
try unicode:characters_to_binary(String)
catch _:_ ->
@@ -84,29 +87,37 @@ try_format(Log,Formatter,FormatterConfig) ->
%%%-----------------------------------------------------------------
%%% Check that the configuration term is valid
-check_common_config({toggle_sync_qlen,N}) when is_integer(N) ->
+check_common_config({mode_tab,_Tid}) ->
valid;
-check_common_config({drop_new_reqs_qlen,N}) when is_integer(N) ->
+check_common_config({handler_pid,Pid}) when is_pid(Pid) ->
valid;
-check_common_config({flush_reqs_qlen,N}) when is_integer(N) ->
+
+check_common_config({sync_mode_qlen,N}) when is_integer(N) ->
+ valid;
+check_common_config({drop_mode_qlen,N}) when is_integer(N) ->
+ valid;
+check_common_config({flush_qlen,N}) when is_integer(N) ->
valid;
-check_common_config({enable_burst_limit,Bool}) when Bool == true;
+
+check_common_config({burst_limit_enable,Bool}) when Bool == true;
Bool == false ->
valid;
-check_common_config({burst_limit_size,N}) when is_integer(N) ->
+check_common_config({burst_limit_max_count,N}) when is_integer(N) ->
valid;
-check_common_config({burst_window_time,N}) when is_integer(N) ->
+check_common_config({burst_limit_window_time,N}) when is_integer(N) ->
valid;
-check_common_config({enable_kill_overloaded,Bool}) when Bool == true;
- Bool == false ->
+
+check_common_config({overload_kill_enable,Bool}) when Bool == true;
+ Bool == false ->
valid;
-check_common_config({handler_overloaded_qlen,N}) when is_integer(N) ->
+check_common_config({overload_kill_qlen,N}) when is_integer(N) ->
valid;
-check_common_config({handler_overloaded_mem,N}) when is_integer(N) ->
+check_common_config({overload_kill_mem_size,N}) when is_integer(N) ->
valid;
-check_common_config({handler_restart_after,NorA}) when is_integer(NorA);
- NorA == never ->
+check_common_config({overload_kill_restart_after,NorA}) when is_integer(NorA);
+ NorA == never ->
valid;
+
check_common_config({filesync_repeat_interval,NorA}) when is_integer(NorA);
NorA == no_repeat ->
valid;
@@ -116,16 +127,16 @@ check_common_config(_) ->
%%%-----------------------------------------------------------------
%%% Overload Protection
-call_cast_or_drop(Name, Bin) ->
- %% If the handler process is getting overloaded, the log request
+call_cast_or_drop(_Name, HandlerPid, ModeTab, Bin) ->
+ %% If the handler process is getting overloaded, the log event
%% will be synchronous instead of asynchronous (slows down the
%% logging tempo of a process doing lots of logging. If the
- %% handler is choked, drop mode is set and no request will be sent.
- try ?get_mode(Name) of
+ %% handler is choked, drop mode is set and no event will be sent.
+ try ?get_mode(ModeTab) of
async ->
- gen_server:cast(Name, {log,Bin});
+ gen_server:cast(HandlerPid, {log,Bin});
sync ->
- try gen_server:call(Name, {log,Bin}, ?DEFAULT_CALL_TIMEOUT) of
+ try gen_server:call(HandlerPid, {log,Bin}, ?DEFAULT_CALL_TIMEOUT) of
%% if return value from call == dropped, the
%% message has been flushed by handler and should
%% therefore not be counted as dropped in stats
@@ -133,32 +144,50 @@ call_cast_or_drop(Name, Bin) ->
dropped -> ok
catch
_:{timeout,_} ->
- ?observe(Name,{dropped,1})
+ ?observe(_Name,{dropped,1})
end;
drop ->
- ?observe(Name,{dropped,1})
+ ?observe(_Name,{dropped,1})
catch
%% if the ETS table doesn't exist (maybe because of a
- %% handler restart), we can only drop the request
- _:_ -> ?observe(Name,{dropped,1})
+ %% handler restart), we can only drop the event
+ _:_ -> ?observe(_Name,{dropped,1})
end,
ok.
handler_exit(_Name, Reason) ->
exit(Reason).
-check_load(State = #{id:=Name, mode := Mode,
- toggle_sync_qlen := ToggleSyncQLen,
- drop_new_reqs_qlen := DropNewQLen,
- flush_reqs_qlen := FlushQLen}) ->
+set_restart_flag(Name, Module) ->
+ Flag = list_to_atom(lists:concat([Module,"_",Name,"_restarting"])),
+ spawn(fun() ->
+ register(Flag, self()),
+ timer:sleep(infinity)
+ end),
+ ok.
+
+unset_restart_flag(Name, Module) ->
+ Flag = list_to_atom(lists:concat([Module,"_",Name,"_restarting"])),
+ case whereis(Flag) of
+ undefined ->
+ false;
+ Pid ->
+ exit(Pid, kill),
+ true
+ end.
+
+check_load(State = #{id:=_Name, mode_tab := ModeTab, mode := Mode,
+ sync_mode_qlen := SyncModeQLen,
+ drop_mode_qlen := DropModeQLen,
+ flush_qlen := FlushQLen}) ->
{_,Mem} = process_info(self(), memory),
- ?observe(Name,{max_mem,Mem}),
+ ?observe(_Name,{max_mem,Mem}),
{_,QLen} = process_info(self(), message_queue_len),
- ?observe(Name,{max_qlen,QLen}),
+ ?observe(_Name,{max_qlen,QLen}),
%% When the handler process gets scheduled in, it's impossible
%% to predict the QLen. We could jump "up" arbitrarily from say
%% async to sync, async to drop, sync to flush, etc. However, when
- %% the handler process manages the log requests (without flushing),
+ %% the handler process manages the log events (without flushing),
%% one after the other, we will move "down" from drop to sync and
%% from sync to async. This way we don't risk getting stuck in
%% drop or sync mode with an empty mailbox.
@@ -166,33 +195,33 @@ check_load(State = #{id:=Name, mode := Mode,
if
QLen >= FlushQLen ->
{flush, 0,1};
- QLen >= DropNewQLen ->
- %% Note that drop mode will force log requests to
+ QLen >= DropModeQLen ->
+ %% Note that drop mode will force log events to
%% be dropped on the client side (never sent get to
%% the handler).
IncDrops = if Mode == drop -> 0; true -> 1 end,
- {?change_mode(Name, Mode, drop), IncDrops,0};
- QLen >= ToggleSyncQLen ->
- {?change_mode(Name, Mode, sync), 0,0};
+ {?change_mode(ModeTab, Mode, drop), IncDrops,0};
+ QLen >= SyncModeQLen ->
+ {?change_mode(ModeTab, Mode, sync), 0,0};
true ->
- {?change_mode(Name, Mode, async), 0,0}
+ {?change_mode(ModeTab, Mode, async), 0,0}
end,
State1 = ?update_other(drops,DROPS,_NewDrops,State),
{Mode1, QLen, Mem,
?update_other(flushes,FLUSHES,_NewFlushes,
State1#{last_qlen => QLen})}.
-limit_burst(#{enable_burst_limit := false}) ->
+limit_burst(#{burst_limit_enable := false}) ->
{true,0,0};
limit_burst(#{burst_win_ts := BurstWinT0,
burst_msg_count := BurstMsgCount,
- burst_window_time := BurstWinTime,
- burst_limit_size := BurstLimitSz}) ->
- if (BurstMsgCount >= BurstLimitSz) ->
+ burst_limit_window_time := BurstLimitWinTime,
+ burst_limit_max_count := BurstLimitMaxCnt}) ->
+ if (BurstMsgCount >= BurstLimitMaxCnt) ->
%% the limit for allowed messages has been reached
BurstWinT1 = ?timestamp(),
case ?diff_time(BurstWinT1,BurstWinT0) of
- BurstCheckTime when BurstCheckTime < (BurstWinTime*1000) ->
+ BurstCheckTime when BurstCheckTime < (BurstLimitWinTime*1000) ->
%% we're still within the burst time frame
{false,BurstWinT0,BurstMsgCount};
_BurstCheckTime ->
@@ -204,38 +233,42 @@ limit_burst(#{burst_win_ts := BurstWinT0,
{true,BurstWinT0,BurstMsgCount+1}
end.
-kill_if_choked(Name, QLen, Mem,
- #{enable_kill_overloaded := KillIfOL,
- handler_overloaded_qlen := HOLQLen,
- handler_overloaded_mem := HOLMem}) ->
+kill_if_choked(Name, QLen, Mem, HandlerMod,
+ State = #{overload_kill_enable := KillIfOL,
+ overload_kill_qlen := OLKillQLen,
+ overload_kill_mem_size := OLKillMem}) ->
if KillIfOL andalso
- ((QLen > HOLQLen) orelse (Mem > HOLMem)) ->
+ ((QLen > OLKillQLen) orelse (Mem > OLKillMem)) ->
+ HandlerMod:log_handler_info(Name,
+ "Handler ~p overloaded and stopping",
+ [Name], State),
+ set_restart_flag(Name, HandlerMod),
handler_exit(Name, {shutdown,{overloaded,Name,QLen,Mem}});
true ->
ok
end.
-flush_log_requests() ->
- flush_log_requests(-1).
+flush_log_events() ->
+ flush_log_events(-1).
-flush_log_requests(Limit) ->
+flush_log_events(Limit) ->
process_flag(priority, high),
- Flushed = flush_log_requests(0, Limit),
+ Flushed = flush_log_events(0, Limit),
process_flag(priority, normal),
Flushed.
-flush_log_requests(Limit, Limit) ->
+flush_log_events(Limit, Limit) ->
Limit;
-flush_log_requests(N, Limit) ->
- %% flush log requests but leave other requests, such as
+flush_log_events(N, Limit) ->
+ %% flush log events but leave other events, such as
%% file/disk_log_sync, info and change_config, so that these
%% have a chance to be processed even under heavy load
receive
{'$gen_cast',{log,_}} ->
- flush_log_requests(N+1, Limit);
+ flush_log_events(N+1, Limit);
{'$gen_call',{Pid,MRef},{log,_}} ->
Pid ! {MRef, dropped},
- flush_log_requests(N+1, Limit)
+ flush_log_events(N+1, Limit)
after
0 -> N
end.
@@ -245,7 +278,7 @@ cancel_timer(TRef) -> timer:cancel(TRef).
stop_or_restart(Name, {shutdown,Reason={overloaded,_Name,_QLen,_Mem}},
- #{handler_restart_after := RestartAfter}) ->
+ #{overload_kill_restart_after := RestartAfter}) ->
%% If we're terminating because of an overload situation (see
%% logger_h_common:kill_if_choked/4), we need to remove the handler
%% and set a restart timer. A separate process must perform this
@@ -262,7 +295,7 @@ stop_or_restart(Name, {shutdown,Reason={overloaded,_Name,_QLen,_Mem}},
exit(HandlerPid, kill)
end,
case logger:get_handler_config(Name) of
- {ok,{HMod,HConfig}} when is_integer(RestartAfter) ->
+ {ok,#{module:=HMod}=HConfig} when is_integer(RestartAfter) ->
_ = logger:remove_handler(Name),
_ = timer:apply_after(RestartAfter, logger, add_handler,
[Name,HMod,HConfig]);
@@ -293,10 +326,10 @@ stop_or_restart(_Name, _Reason, _State) ->
ok.
overload_levels_ok(HandlerConfig) ->
- TSQL = maps:get(toggle_sync_qlen, HandlerConfig, ?TOGGLE_SYNC_QLEN),
- DNRQL = maps:get(drop_new_reqs_qlen, HandlerConfig, ?DROP_NEW_REQS_QLEN),
- FRQL = maps:get(flush_reqs_qlen, HandlerConfig, ?FLUSH_REQS_QLEN),
- (DNRQL > 1) andalso (TSQL =< DNRQL) andalso (DNRQL =< FRQL).
+ SMQL = maps:get(sync_mode_qlen, HandlerConfig, ?SYNC_MODE_QLEN),
+ DMQL = maps:get(drop_mode_qlen, HandlerConfig, ?DROP_MODE_QLEN),
+ FQL = maps:get(flush_qlen, HandlerConfig, ?FLUSH_QLEN),
+ (DMQL > 1) andalso (SMQL =< DMQL) andalso (DMQL =< FQL).
error_notify(Term) ->
?internal_log(error, Term).
diff --git a/lib/kernel/src/logger_h_common.hrl b/lib/kernel/src/logger_h_common.hrl
index ed365ce6eb..ad80b51109 100644
--- a/lib/kernel/src/logger_h_common.hrl
+++ b/lib/kernel/src/logger_h_common.hrl
@@ -4,47 +4,47 @@
%%! *** NOTE ***
%%! It's important that:
-%%! TOGGLE_SYNC_QLEN < DROP_NEW_REQS_QLEN < FLUSH_REQS_QLEN
-%%! and that DROP_NEW_REQS_QLEN >= 2.
+%%! SYNC_MODE_QLEN =< DROP_MODE_QLEN =< FLUSH_QLEN
+%%! and that DROP_MODE_QLEN >= 2.
%%! Otherwise the handler could end up in drop mode with no new
%%! log requests to process. This would cause all future requests
%%! to be dropped (no switch to async mode would ever take place).
%% This specifies the message_queue_len value where the log
%% requests switch from asynchronous casts to synchronous calls.
--define(TOGGLE_SYNC_QLEN, 10).
+-define(SYNC_MODE_QLEN, 10).
%% Above this message_queue_len, log requests will be dropped,
%% i.e. no log requests get sent to the handler process.
--define(DROP_NEW_REQS_QLEN, 200).
+-define(DROP_MODE_QLEN, 200).
%% Above this message_queue_len, the handler process will flush
%% its mailbox and only leave this number of messages in it.
--define(FLUSH_REQS_QLEN, 1000).
+-define(FLUSH_QLEN, 1000).
%% Never flush more than this number of messages in one go,
%% or the handler will be unresponsive for seconds (keep this
%% number as large as possible or the mailbox could grow large).
-define(FLUSH_MAX_N, 5000).
-%% BURST_LIMIT is the max number of log requests allowed to be
-%% written within a BURST_WINDOW_TIME time frame.
--define(ENABLE_BURST_LIMIT, true).
--define(BURST_LIMIT_SIZE, 500).
--define(BURST_WINDOW_TIME, 1000).
+%% BURST_LIMIT_MAX_COUNT is the max number of log requests allowed
+%% to be written within a BURST_LIMIT_WINDOW_TIME time frame.
+-define(BURST_LIMIT_ENABLE, true).
+-define(BURST_LIMIT_MAX_COUNT, 500).
+-define(BURST_LIMIT_WINDOW_TIME, 1000).
%% This enables/disables the feature to automatically get the
%% handler terminated if it gets too loaded (and can't keep up).
--define(ENABLE_KILL_OVERLOADED, false).
+-define(OVERLOAD_KILL_ENABLE, false).
%% If the message_queue_len goes above this size even after
%% flushing has been performed, the handler is terminated.
--define(HANDLER_OVERLOADED_QLEN, 20000).
+-define(OVERLOAD_KILL_QLEN, 20000).
%% If the memory usage exceeds this level
--define(HANDLER_OVERLOADED_MEM, 3000000).
+-define(OVERLOAD_KILL_MEM_SIZE, 3000000).
%% This is the default time that the handler will wait before
%% restarting and accepting new requests. The value 'never'
%% disables restarts.
--define(HANDLER_RESTART_AFTER, 5000).
-%%-define(HANDLER_RESTART_AFTER, never).
+-define(OVERLOAD_KILL_RESTART_AFTER, 5000).
+%%-define(OVERLOAD_KILL_RESTART_AFTER, never).
%% The handler sends asynchronous write requests to the process
%% controlling the i/o device, but every once in this interval
@@ -77,29 +77,30 @@
-define(DISK_LOG_MAX_NO_BYTES, 1048576).
%%%-----------------------------------------------------------------
+%%% Utility macros
+
+-define(name_to_reg_name(MODULE,Name),
+ list_to_atom(lists:concat([MODULE,"_",Name]))).
+
+%%%-----------------------------------------------------------------
%%% Overload protection macros
-define(timestamp(), erlang:monotonic_time(microsecond)).
--define(get_mode(HandlerName),
- case ets:lookup(HandlerName, mode) of
- [{mode,sync}] ->
- case whereis(HandlerName)==self() of
- true -> async;
- _ -> sync
- end;
+-define(get_mode(Tid),
+ case ets:lookup(Tid, mode) of
[{mode,M}] -> M;
_ -> async
end).
--define(set_mode(HandlerName, M),
- begin ets:insert(HandlerName, {mode,M}), M end).
+-define(set_mode(Tid, M),
+ begin ets:insert(Tid, {mode,M}), M end).
--define(change_mode(HandlerName, M0, M1),
+-define(change_mode(Tid, M0, M1),
if M0 == M1 ->
M0;
true ->
- ets:insert(HandlerName, {mode,M1}),
+ ets:insert(Tid, {mode,M1}),
M1
end).
@@ -124,7 +125,7 @@
%%% slow down execution and therefore should not be include in code
%%% to be officially released.
--define(TEST_HOOKS, true).
+%%-define(TEST_HOOKS, true).
-ifdef(TEST_HOOKS).
-define(TEST_HOOKS_TAB, logger_h_test_hooks).
diff --git a/lib/kernel/src/logger_internal.hrl b/lib/kernel/src/logger_internal.hrl
index fedd6db370..8941409a25 100644
--- a/lib/kernel/src/logger_internal.hrl
+++ b/lib/kernel/src/logger_internal.hrl
@@ -19,12 +19,11 @@
%%
-include_lib("kernel/include/logger.hrl").
-define(LOGGER_TABLE,logger).
--define(LOGGER_KEY,'$logger_config$').
+-define(PRIMARY_KEY,'$primary_config$').
-define(HANDLER_KEY,'$handler_config$').
-define(LOGGER_META_KEY,'$logger_metadata$').
-define(STANDARD_HANDLER, default).
--define(DEFAULT_HANDLER_FILTERS,
- ?DEFAULT_HANDLER_FILTERS([beam,erlang,otp])).
+-define(DEFAULT_HANDLER_FILTERS,?DEFAULT_HANDLER_FILTERS([otp])).
-define(DEFAULT_HANDLER_FILTERS(Domain),
[{remote_gl,{fun logger_filters:remote_gl/2,stop}},
{domain,{fun logger_filters:domain/2,{log,super,Domain}}},
@@ -33,7 +32,7 @@
-define(DEFAULT_FORMAT_CONFIG,#{legacy_header=>true,
single_line=>false}).
-define(DEFAULT_FORMAT_TEMPLATE_HEADER,
- [{logger_formatter,header},"\n",msg,"\n"]).
+ [[logger_formatter,header],"\n",msg,"\n"]).
-define(DEFAULT_FORMAT_TEMPLATE_SINGLE,
[time," ",level,": ",msg,"\n"]).
-define(DEFAULT_FORMAT_TEMPLATE,
@@ -55,14 +54,17 @@
%%%-----------------------------------------------------------------
%%% Levels
%%% Using same as syslog
--define(LEVELS,[emergency,
+-define(LEVELS,[none,
+ emergency,
alert,
critical,
error,
warning,
notice,
info,
- debug]).
+ debug,
+ all]).
+-define(LOG_NONE,-1).
-define(EMERGENCY,0).
-define(ALERT,1).
-define(CRITICAL,2).
@@ -71,6 +73,7 @@
-define(NOTICE,5).
-define(INFO,6).
-define(DEBUG,7).
+-define(LOG_ALL,10).
-define(IS_LEVEL(L),
(L=:=emergency orelse
diff --git a/lib/kernel/src/logger_server.erl b/lib/kernel/src/logger_server.erl
index 47010c9fa5..e50954fc40 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -25,8 +25,8 @@
-export([start_link/0,
add_handler/3, remove_handler/1,
add_filter/2, remove_filter/2,
- set_module_level/2, unset_module_level/1,
- cache_module_level/1,
+ set_module_level/2, unset_module_level/0,
+ unset_module_level/1, cache_module_level/1,
set_config/2, set_config/3, update_config/2,
update_formatter_config/2]).
@@ -53,7 +53,7 @@ add_handler(Id,Module,Config0) ->
{ok,ok} ->
case sanity_check(Id,Config0) of
ok ->
- Default = default_config(Id),
+ Default = default_config(Id,Module),
Config = maps:merge(Default,Config0),
call({add_handler,Id,Module,Config});
Error ->
@@ -75,30 +75,41 @@ add_filter(Owner,Filter) ->
remove_filter(Owner,FilterId) ->
call({remove_filter,Owner,FilterId}).
-set_module_level(Module,Level) when is_atom(Module) ->
- case sanity_check(logger,level,Level) of
- ok -> call({set_module_level,Module,Level});
- Error -> Error
+set_module_level(Modules,Level) when is_list(Modules) ->
+ case lists:all(fun(M) -> is_atom(M) end,Modules) of
+ true ->
+ case sanity_check(primary,level,Level) of
+ ok -> call({set_module_level,Modules,Level});
+ Error -> Error
+ end;
+ false ->
+ {error,{not_a_list_of_modles,Modules}}
end;
-set_module_level(Module,_) ->
- {error,{not_a_module,Module}}.
+set_module_level(Modules,_) ->
+ {error,{not_a_list_of_modules,Modules}}.
+
+unset_module_level() ->
+ call({unset_module_level,all}).
-unset_module_level(Module) when is_atom(Module) ->
- call({unset_module_level,Module});
-unset_module_level(Module) ->
- {error,{not_a_module,Module}}.
+unset_module_level(Modules) when is_list(Modules) ->
+ case lists:all(fun(M) -> is_atom(M) end,Modules) of
+ true ->
+ call({unset_module_level,Modules});
+ false ->
+ {error,{not_a_list_of_modles,Modules}}
+ end;
+unset_module_level(Modules) ->
+ {error,{not_a_list_of_modules,Modules}}.
cache_module_level(Module) ->
gen_server:cast(?SERVER,{cache_module_level,Module}).
-
set_config(Owner,Key,Value) ->
update_config(Owner,#{Key=>Value}).
-set_config(Owner,Config0) ->
- case sanity_check(Owner,Config0) of
+set_config(Owner,Config) ->
+ case sanity_check(Owner,Config) of
ok ->
- Config = maps:merge(default_config(Owner),Config0),
call({set_config,Owner,Config});
Error ->
Error
@@ -125,11 +136,12 @@ update_formatter_config(_HandlerId, FormatterConfig) ->
init([]) ->
process_flag(trap_exit, true),
+ put(?LOGGER_SERVER_TAG,true),
Tid = logger_config:new(?LOGGER_TABLE),
- LoggerConfig = maps:merge(default_config(logger),
+ PrimaryConfig = maps:merge(default_config(primary),
#{handlers=>[simple]}),
- logger_config:create(Tid,logger,LoggerConfig),
- SimpleConfig0 = maps:merge(default_config(simple),
+ logger_config:create(Tid,primary,PrimaryConfig),
+ SimpleConfig0 = maps:merge(default_config(simple,logger_simple_h),
#{filter_default=>stop,
filters=>?DEFAULT_HANDLER_FILTERS}),
%% If this fails, then the node should crash
@@ -154,9 +166,9 @@ handle_call({add_handler,Id,Module,HConfig}, From, #state{tid=Tid}=State) ->
case erlang:function_exported(Module, log, 2) of
true ->
logger_config:create(Tid,Id,Module,HConfig1),
- {ok,Config} = do_get_config(Tid,logger),
+ {ok,Config} = do_get_config(Tid,primary),
Handlers = maps:get(handlers,Config,[]),
- do_set_config(Tid,logger,
+ do_set_config(Tid,primary,
Config#{handlers=>[Id|Handlers]});
false ->
{error,{invalid_handler,
@@ -170,7 +182,7 @@ handle_call({add_handler,Id,Module,HConfig}, From, #state{tid=Tid}=State) ->
handle_call({remove_handler,HandlerId}, From, #state{tid=Tid}=State) ->
case logger_config:get(Tid,HandlerId) of
{ok,{Module,HConfig}} ->
- {ok,Config} = do_get_config(Tid,logger),
+ {ok,Config} = do_get_config(Tid,primary),
Handlers0 = maps:get(handlers,Config,[]),
Handlers = lists:delete(HandlerId,Handlers0),
call_h_async(
@@ -179,7 +191,7 @@ handle_call({remove_handler,HandlerId}, From, #state{tid=Tid}=State) ->
call_h(Module,removing_handler,[HConfig],ok)
end,
fun(_Res) ->
- do_set_config(Tid,logger,Config#{handlers=>Handlers}),
+ do_set_config(Tid,primary,Config#{handlers=>Handlers}),
logger_config:delete(Tid,HandlerId),
ok
end,From,State);
@@ -203,13 +215,15 @@ handle_call({update_config,Id,NewConfig}, From, #state{tid=Tid}=State) ->
Error ->
{reply,Error,State}
end;
-handle_call({set_config,logger,Config}, _From, #state{tid=Tid}=State) ->
- {ok,#{handlers:=Handlers}} = logger_config:get(Tid,logger),
- Reply = do_set_config(Tid,logger,Config#{handlers=>Handlers}),
+handle_call({set_config,primary,Config0}, _From, #state{tid=Tid}=State) ->
+ Config = maps:merge(default_config(primary),Config0),
+ {ok,#{handlers:=Handlers}} = logger_config:get(Tid,primary),
+ Reply = do_set_config(Tid,primary,Config#{handlers=>Handlers}),
{reply,Reply,State};
-handle_call({set_config,HandlerId,Config}, From, #state{tid=Tid}=State) ->
+handle_call({set_config,HandlerId,Config0}, From, #state{tid=Tid}=State) ->
case logger_config:get(Tid,HandlerId) of
{ok,{Module,OldConfig}} ->
+ Config = maps:merge(default_config(HandlerId,Module),Config0),
call_h_async(
fun() ->
call_h(Module,changing_config,[OldConfig,Config],
@@ -239,11 +253,11 @@ handle_call({update_formatter_config,HandlerId,NewFConfig},_From,
{error,{not_found,HandlerId}}
end,
{reply,Reply,State};
-handle_call({set_module_level,Module,Level}, _From, #state{tid=Tid}=State) ->
- Reply = logger_config:set_module_level(Tid,Module,Level),
+handle_call({set_module_level,Modules,Level}, _From, #state{tid=Tid}=State) ->
+ Reply = logger_config:set_module_level(Tid,Modules,Level),
{reply,Reply,State};
-handle_call({unset_module_level,Module}, _From, #state{tid=Tid}=State) ->
- Reply = logger_config:unset_module_level(Tid,Module),
+handle_call({unset_module_level,Modules}, _From, #state{tid=Tid}=State) ->
+ Reply = logger_config:unset_module_level(Tid,Modules),
{reply,Reply,State}.
handle_cast({async_req_reply,_Ref,_Reply} = Reply,State) ->
@@ -270,7 +284,7 @@ handle_info({Ref,_Reply},State) when is_reference(Ref) ->
handle_info({'DOWN',_Ref,_Proc,_Pid,_Reason} = Down,State) ->
call_h_reply(Down,State);
handle_info(Unexpected,State) when element(1,Unexpected) == 'EXIT' ->
- %% The simple logger will send an 'EXIT' message when it is replaced
+ %% The simple handler will send an 'EXIT' message when it is replaced
%% We may as well ignore all 'EXIT' messages that we get
?LOG_INTERNAL(debug,
[{logger,got_unexpected_message},
@@ -343,16 +357,18 @@ do_set_config(Tid,Id,Config) ->
logger_config:set(Tid,Id,Config),
ok.
-default_config(logger) ->
- #{level=>info,
+default_config(primary) ->
+ #{level=>notice,
filters=>[],
filter_default=>log};
default_config(Id) ->
#{id=>Id,
- level=>info,
+ level=>all,
filters=>[],
filter_default=>log,
formatter=>{?DEFAULT_FORMATTER,#{}}}.
+default_config(Id,Module) ->
+ (default_config(Id))#{module=>Module}.
sanity_check(Owner,Key,Value) ->
sanity_check_1(Owner,[{Key,Value}]).
@@ -369,8 +385,8 @@ sanity_check_1(Owner,Config) when is_list(Config) ->
catch throw:Error -> {error,Error}
end.
-get_type(logger) ->
- logger;
+get_type(primary) ->
+ primary;
get_type(Id) ->
check_id(Id),
handler.
@@ -387,8 +403,8 @@ check_config(Owner,[{filter_default,FD}|Config]) ->
check_config(handler,[{formatter,Formatter}|Config]) ->
check_formatter(Formatter),
check_config(handler,Config);
-check_config(logger,[C|_]) ->
- throw({invalid_logger_config,C});
+check_config(primary,[C|_]) ->
+ throw({invalid_primary_config,C});
check_config(handler,[{_,_}|Config]) ->
%% Arbitrary config elements are allowed for handlers
check_config(handler,Config);
diff --git a/lib/kernel/src/logger_std_h.erl b/lib/kernel/src/logger_std_h.erl
index 63c3ab2dac..ce9daa50ab 100644
--- a/lib/kernel/src/logger_std_h.erl
+++ b/lib/kernel/src/logger_std_h.erl
@@ -28,15 +28,17 @@
-include_lib("kernel/include/file.hrl").
%% API
--export([start_link/3, info/1, filesync/1, reset/1]).
+-export([start_link/3, info/1, sync/1, reset/1]).
%% gen_server and proc_lib callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
%% logger callbacks
--export([log/2, adding_handler/1, removing_handler/1,
- changing_config/2, swap_buffer/2]).
+-export([log/2, adding_handler/1, removing_handler/1, changing_config/2]).
+
+%% handler internal
+-export([log_handler_info/4]).
%%%===================================================================
%%% API
@@ -48,7 +50,7 @@
%%% handler process gets added
-spec start_link(Name, Config, HandlerState) -> {ok,Pid} | {error,Reason} when
Name :: atom(),
- Config :: logger:config(),
+ Config :: logger:handler_config(),
HandlerState :: map(),
Pid :: pid(),
Reason :: term().
@@ -58,18 +60,19 @@ start_link(Name, Config, HandlerState) ->
%%%-----------------------------------------------------------------
%%%
--spec filesync(Name) -> ok | {error,Reason} when
+-spec sync(Name) -> ok | {error,Reason} when
Name :: atom(),
Reason :: handler_busy | {badarg,term()}.
-filesync(Name) when is_atom(Name) ->
+sync(Name) when is_atom(Name) ->
try
- gen_server:call(Name, filesync, ?DEFAULT_CALL_TIMEOUT)
+ gen_server:call(?name_to_reg_name(?MODULE,Name),
+ filesync, ?DEFAULT_CALL_TIMEOUT)
catch
_:{timeout,_} -> {error,handler_busy}
end;
-filesync(Name) ->
- {error,{badarg,{filesync,[Name]}}}.
+sync(Name) ->
+ {error,{badarg,{sync,[Name]}}}.
%%%-----------------------------------------------------------------
%%%
@@ -80,7 +83,8 @@ filesync(Name) ->
info(Name) when is_atom(Name) ->
try
- gen_server:call(Name, info, ?DEFAULT_CALL_TIMEOUT)
+ gen_server:call(?name_to_reg_name(?MODULE,Name),
+ info, ?DEFAULT_CALL_TIMEOUT)
catch
_:{timeout,_} -> {error,handler_busy}
end;
@@ -95,7 +99,8 @@ info(Name) ->
reset(Name) when is_atom(Name) ->
try
- gen_server:call(Name, reset, ?DEFAULT_CALL_TIMEOUT)
+ gen_server:call(?name_to_reg_name(?MODULE,Name),
+ reset, ?DEFAULT_CALL_TIMEOUT)
catch
_:{timeout,_} -> {error,handler_busy}
end;
@@ -113,23 +118,16 @@ adding_handler(#{id:=Name}=Config) ->
case check_config(adding, Config) of
{ok, Config1} ->
%% create initial handler state by merging defaults with config
- HConfig = maps:get(?MODULE, Config1, #{}),
+ HConfig = maps:get(config, Config1, #{}),
HState = maps:merge(get_init_state(), HConfig),
case logger_h_common:overload_levels_ok(HState) of
true ->
- case start(Name, Config1, HState) of
- ok ->
- %% Make sure wait_for_buffer is not stored, so we
- %% won't hang and wait for buffer on a restart
- {ok, maps:remove(wait_for_buffer,Config1)};
- Error ->
- Error
- end;
+ start(Name, Config1, HState);
false ->
- #{toggle_sync_qlen := TSQL,
- drop_new_reqs_qlen := DNRQL,
- flush_reqs_qlen := FRQL} = HState,
- {error,{invalid_levels,{TSQL,DNRQL,FRQL}}}
+ #{sync_mode_qlen := SMQL,
+ drop_mode_qlen := DMQL,
+ flush_qlen := FQL} = HState,
+ {error,{invalid_levels,{SMQL,DMQL,FQL}}}
end;
Error ->
Error
@@ -137,24 +135,27 @@ adding_handler(#{id:=Name}=Config) ->
%%%-----------------------------------------------------------------
%%% Updating handler config
-changing_config(OldConfig=#{id:=Name, ?MODULE:=#{type:=Type}},
+changing_config(OldConfig=#{id:=Name, config:=OldHConfig},
NewConfig=#{id:=Name}) ->
- MyConfig = maps:get(?MODULE, NewConfig, #{}),
- case maps:get(type, MyConfig, Type) of
+ #{type:=Type, handler_pid:=HPid, mode_tab:=ModeTab} = OldHConfig,
+ NewHConfig = maps:get(config, NewConfig, #{}),
+ case maps:get(type, NewHConfig, Type) of
Type ->
- MyConfig1 = MyConfig#{type=>Type},
- changing_config1(Name, OldConfig,
- NewConfig#{?MODULE=>MyConfig1});
+ NewHConfig1 = NewHConfig#{type=>Type,
+ handler_pid=>HPid,
+ mode_tab=>ModeTab},
+ changing_config1(HPid, OldConfig,
+ NewConfig#{config=>NewHConfig1});
_ ->
{error,{illegal_config_change,OldConfig,NewConfig}}
end;
changing_config(OldConfig, NewConfig) ->
{error,{illegal_config_change,OldConfig,NewConfig}}.
-changing_config1(Name, OldConfig, NewConfig) ->
+changing_config1(HPid, OldConfig, NewConfig) ->
case check_config(changing, NewConfig) of
Result = {ok,NewConfig1} ->
- try gen_server:call(Name, {change_config,OldConfig,NewConfig1},
+ try gen_server:call(HPid, {change_config,OldConfig,NewConfig1},
?DEFAULT_CALL_TIMEOUT) of
ok -> Result;
HError -> HError
@@ -167,38 +168,38 @@ changing_config1(Name, OldConfig, NewConfig) ->
check_config(adding, Config) ->
%% Merge in defaults on handler level
- MyConfig0 = maps:get(?MODULE, Config, #{}),
- MyConfig = maps:merge(#{type => standard_io},
- MyConfig0),
- case check_my_config(maps:to_list(MyConfig)) of
+ HConfig0 = maps:get(config, Config, #{}),
+ HConfig = maps:merge(#{type => standard_io},
+ HConfig0),
+ case check_h_config(maps:to_list(HConfig)) of
ok ->
- {ok,Config#{?MODULE=>MyConfig}};
+ {ok,Config#{config=>HConfig}};
Error ->
Error
end;
check_config(changing, Config) ->
- MyConfig = maps:get(?MODULE, Config, #{}),
- case check_my_config(maps:to_list(MyConfig)) of
+ HConfig = maps:get(config, Config, #{}),
+ case check_h_config(maps:to_list(HConfig)) of
ok -> {ok,Config};
Error -> Error
end.
-check_my_config([{type,Type} | Config]) when Type == standard_io;
- Type == standard_error ->
- check_my_config(Config);
-check_my_config([{type,{file,File}} | Config]) when is_list(File) ->
- check_my_config(Config);
-check_my_config([{type,{file,File,Modes}} | Config]) when is_list(File),
- is_list(Modes) ->
- check_my_config(Config);
-check_my_config([Other | Config]) ->
+check_h_config([{type,Type} | Config]) when Type == standard_io;
+ Type == standard_error ->
+ check_h_config(Config);
+check_h_config([{type,{file,File}} | Config]) when is_list(File) ->
+ check_h_config(Config);
+check_h_config([{type,{file,File,Modes}} | Config]) when is_list(File),
+ is_list(Modes) ->
+ check_h_config(Config);
+check_h_config([Other | Config]) ->
case logger_h_common:check_common_config(Other) of
valid ->
- check_my_config(Config);
+ check_h_config(Config);
invalid ->
{error,{invalid_config,?MODULE,Other}}
end;
-check_my_config([]) ->
+check_h_config([]) ->
ok.
@@ -208,35 +209,27 @@ removing_handler(#{id:=Name}) ->
stop(Name).
%%%-----------------------------------------------------------------
-%%% Get buffer when swapping from simple handler
-swap_buffer(Name,Buffer) ->
- case whereis(Name) of
- undefined ->
- ok;
- _ ->
- Name ! {buffer,Buffer}
- end.
-
-%%%-----------------------------------------------------------------
%%% Log a string or report
-spec log(LogEvent, Config) -> ok | dropped when
LogEvent :: logger:log_event(),
- Config :: logger:config().
+ Config :: logger:handler_config().
-log(LogEvent,Config=#{id:=Name}) ->
- %% if the handler has crashed, we must drop this request
+log(LogEvent, Config = #{id := Name,
+ config := #{handler_pid := HPid,
+ mode_tab := ModeTab}}) ->
+ %% if the handler has crashed, we must drop this event
%% and hope the handler restarts so we can try again
- true = is_pid(whereis(Name)),
- Bin = logger_h_common:log_to_binary(LogEvent,Config),
- logger_h_common:call_cast_or_drop(Name, Bin).
+ true = is_process_alive(HPid),
+ Bin = logger_h_common:log_to_binary(LogEvent, Config),
+ logger_h_common:call_cast_or_drop(Name, HPid, ModeTab, Bin).
%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
-init([Name, Config,
- State0 = #{type := Type, file_ctrl_sync_int := FileCtrlSyncInt}]) ->
- register(Name, self()),
+init([Name, Config = #{config := HConfig},
+ State0 = #{type := Type, file_ctrl_sync_int := FileCtrlSyncInt}]) ->
+ register(?name_to_reg_name(?MODULE,Name), self()),
process_flag(trap_exit, true),
process_flag(message_queue_data, off_heap),
@@ -245,59 +238,59 @@ init([Name, Config,
case do_init(Name, Type) of
{ok,InitState} ->
- catch ets:new(Name, [public, named_table]),
- ?set_mode(Name, async),
- State = maps:merge(State0, InitState),
- T0 = ?timestamp(),
- State1 =
- ?merge_with_stats(State#{mode => async,
- file_ctrl_sync => FileCtrlSyncInt,
- last_qlen => 0,
- last_log_ts => T0,
- last_op => sync,
- burst_win_ts => T0,
- burst_msg_count => 0}),
- proc_lib:init_ack({ok,self()}),
- gen_server:cast(self(), repeated_filesync),
- enter_loop(Config, State1);
+ try ets:new(Name, [public]) of
+ ModeTab ->
+ ?set_mode(ModeTab, async),
+ State = maps:merge(State0, InitState),
+ T0 = ?timestamp(),
+ State1 =
+ ?merge_with_stats(State#{
+ mode_tab => ModeTab,
+ mode => async,
+ file_ctrl_sync => FileCtrlSyncInt,
+ last_qlen => 0,
+ last_log_ts => T0,
+ last_op => sync,
+ burst_win_ts => T0,
+ burst_msg_count => 0}),
+ Config1 =
+ Config#{config => HConfig#{handler_pid => self(),
+ mode_tab => ModeTab}},
+ proc_lib:init_ack({ok,self(),Config1}),
+ gen_server:cast(self(), repeated_filesync),
+ enter_loop(Config1, State1)
+ catch
+ _:Error ->
+ logger_h_common:error_notify({init_handler,Name,Error}),
+ proc_lib:init_ack(Error)
+ end;
Error ->
logger_h_common:error_notify({init_handler,Name,Error}),
proc_lib:init_ack(Error)
end.
-do_init(Name, Std) when Std=:=standard_io; Std=:=standard_error ->
- case open_log_file(Name, Std) of
- {ok,FileCtrlPid} ->
- {ok,#{id=>Name,type=>Std,file_ctrl_pid=>FileCtrlPid}};
- Error ->
- Error
- end;
-do_init(Name, FileInfo) when is_tuple(FileInfo) ->
- case open_log_file(Name, FileInfo) of
+do_init(Name, Type) ->
+ case open_log_file(Name, Type) of
{ok,FileCtrlPid} ->
- {ok,#{id=>Name,type=>FileInfo,file_ctrl_pid=>FileCtrlPid}};
+ case logger_h_common:unset_restart_flag(Name, ?MODULE) of
+ true ->
+ %% inform about restart
+ gen_server:cast(self(), {log_handler_info,
+ "Handler ~p restarted",
+ [Name]});
+ false ->
+ %% initial start
+ ok
+ end,
+ {ok,#{id=>Name,type=>Type,file_ctrl_pid=>FileCtrlPid}};
Error ->
Error
end.
-enter_loop(#{wait_for_buffer:=true}=Config,State) ->
- State1 =
- receive
- {buffer,Buffer} ->
- lists:foldl(
- fun(Log,S) ->
- Bin = logger_h_common:log_to_binary(Log,Config),
- {_,S1} = do_log(Bin,cast,S),
- S1
- end,
- State,
- Buffer)
- end,
- gen_server:enter_loop(?MODULE,[],State1);
enter_loop(_Config,State) ->
gen_server:enter_loop(?MODULE,[],State).
-%% This is the synchronous log request.
+%% This is the synchronous log event.
handle_call({log, Bin}, _From, State) ->
{Result,State1} = do_log(Bin, call, State),
%% Result == ok | dropped
@@ -313,7 +306,7 @@ handle_call(filesync, _From, State = #{type := Type,
handle_call({change_config,_OldConfig,NewConfig}, _From,
State = #{filesync_repeat_interval := FSyncInt0}) ->
- HConfig = maps:get(?MODULE, NewConfig, #{}),
+ HConfig = maps:get(config, NewConfig, #{}),
State1 = maps:merge(State, HConfig),
case logger_h_common:overload_levels_ok(State1) of
true ->
@@ -335,10 +328,10 @@ handle_call({change_config,_OldConfig,NewConfig}, _From,
end,
{reply, ok, State1};
false ->
- #{toggle_sync_qlen := TSQL,
- drop_new_reqs_qlen := DNRQL,
- flush_reqs_qlen := FRQL} = State1,
- {reply, {error,{invalid_levels,{TSQL,DNRQL,FRQL}}}, State}
+ #{sync_mode_qlen := SMQL,
+ drop_mode_qlen := DMQL,
+ flush_qlen := FQL} = State1,
+ {reply, {error,{invalid_levels,{SMQL,DMQL,FQL}}}, State}
end;
handle_call(info, _From, State) ->
@@ -352,15 +345,19 @@ handle_call(reset, _From, State) ->
handle_call(stop, _From, State) ->
{stop, {shutdown,stopped}, ok, State}.
-%% This is the asynchronous log request.
+%% This is the asynchronous log event.
handle_cast({log, Bin}, State) ->
{_,State1} = do_log(Bin, cast, State),
{noreply, State1};
+handle_cast({log_handler_info, Format, Args}, State = #{id:=Name}) ->
+ log_handler_info(Name, Format, Args, State),
+ {noreply, State};
+
%% If FILESYNC_REPEAT_INTERVAL is set to a millisec value, this
%% clause gets called repeatedly by the handler. In order to
%% guarantee that a filesync *always* happens after the last log
-%% request, the repeat operation must be active!
+%% event, the repeat operation must be active!
handle_cast(repeated_filesync,
State = #{type := Type,
file_ctrl_pid := FileCtrlPid,
@@ -430,19 +427,19 @@ code_change(_OldVsn, State, _Extra) ->
%%%-----------------------------------------------------------------
%%%
get_init_state() ->
- #{toggle_sync_qlen => ?TOGGLE_SYNC_QLEN,
- drop_new_reqs_qlen => ?DROP_NEW_REQS_QLEN,
- flush_reqs_qlen => ?FLUSH_REQS_QLEN,
- enable_burst_limit => ?ENABLE_BURST_LIMIT,
- burst_limit_size => ?BURST_LIMIT_SIZE,
- burst_window_time => ?BURST_WINDOW_TIME,
- enable_kill_overloaded => ?ENABLE_KILL_OVERLOADED,
- handler_overloaded_qlen => ?HANDLER_OVERLOADED_QLEN,
- handler_overloaded_mem => ?HANDLER_OVERLOADED_MEM,
- handler_restart_after => ?HANDLER_RESTART_AFTER,
- file_ctrl_sync_int => ?CONTROLLER_SYNC_INTERVAL,
- filesync_ok_qlen => ?FILESYNC_OK_QLEN,
- filesync_repeat_interval => ?FILESYNC_REPEAT_INTERVAL}.
+ #{sync_mode_qlen => ?SYNC_MODE_QLEN,
+ drop_mode_qlen => ?DROP_MODE_QLEN,
+ flush_qlen => ?FLUSH_QLEN,
+ burst_limit_enable => ?BURST_LIMIT_ENABLE,
+ burst_limit_max_count => ?BURST_LIMIT_MAX_COUNT,
+ burst_limit_window_time => ?BURST_LIMIT_WINDOW_TIME,
+ overload_kill_enable => ?OVERLOAD_KILL_ENABLE,
+ overload_kill_qlen => ?OVERLOAD_KILL_QLEN,
+ overload_kill_mem_size => ?OVERLOAD_KILL_MEM_SIZE,
+ overload_kill_restart_after => ?OVERLOAD_KILL_RESTART_AFTER,
+ file_ctrl_sync_int => ?CONTROLLER_SYNC_INTERVAL,
+ filesync_ok_qlen => ?FILESYNC_OK_QLEN,
+ filesync_repeat_interval => ?FILESYNC_REPEAT_INTERVAL}.
%%%-----------------------------------------------------------------
%%% Add a standard handler to the logger.
@@ -451,9 +448,9 @@ get_init_state() ->
%%% exist if the handler is not registered).
%%%
%%% Handler specific config should be provided with a sub map associated
-%%% with a key named the same as this module, e.g:
+%%% with a key named 'config', e.g:
%%%
-%%% Config = #{logger_std_h => #{toggle_sync_qlen => 50}
+%%% Config = #{config => #{sync_mode_qlen => 50}
%%%
%%% The standard handler process is linked to logger_sup, which is
%%% part of the kernel application's supervision tree.
@@ -466,8 +463,8 @@ start(Name, Config, HandlerState) ->
type => worker,
modules => [?MODULE]},
case supervisor:start_child(logger_sup, LoggerStdH) of
- {ok,_Pid} ->
- ok;
+ {ok,_Pid,Config1} ->
+ {ok,Config1};
Error ->
Error
end.
@@ -475,16 +472,16 @@ start(Name, Config, HandlerState) ->
%%%-----------------------------------------------------------------
%%% Stop and remove the handler.
stop(Name) ->
- case whereis(Name) of
+ case whereis(?name_to_reg_name(?MODULE,Name)) of
undefined ->
ok;
- _ ->
+ Pid ->
%% We don't want to do supervisor:terminate_child here
%% since we need to distinguish this explicit stop from a
%% system termination in order to avoid circular attempts
%% at removing the handler (implying deadlocks and
%% timeouts).
- _ = gen_server:call(Name,stop),
+ _ = gen_server:call(Pid, stop),
_ = supervisor:delete_child(logger_sup, Name),
ok
end.
@@ -495,21 +492,31 @@ stop(Name) ->
if C == 0 -> Interval;
true -> C-1 end).
-%% check for overload between every request (and set Mode to async,
+%% check for overload between every event (and set Mode to async,
%% sync or drop accordingly), but never flush the whole mailbox
-%% before LogWindowSize requests have been handled
-do_log(Bin, CallOrCast, State = #{id:=Name}) ->
+%% before LogWindowSize events have been handled
+do_log(Bin, CallOrCast, State = #{id:=Name, mode:=Mode0}) ->
T1 = ?timestamp(),
%% check if the handler is getting overloaded, or if it's
%% recovering from overload (the check must be done for each
- %% request to react quickly to large bursts of requests and
+ %% event to react quickly to large bursts of events and
%% to ensure that the handler can never end up in drop mode
%% with an empty mailbox, which would stop operation)
{Mode1,QLen,Mem,State1} = logger_h_common:check_load(State),
+ if (Mode1 == drop) andalso (Mode0 =/= drop) ->
+ log_handler_info(Name, "Handler ~p switched to drop mode",
+ [Name], State);
+ (Mode0 == drop) andalso ((Mode1 == async) orelse (Mode1 == sync)) ->
+ log_handler_info(Name, "Handler ~p switched to ~w mode",
+ [Name,Mode1], State);
+ true ->
+ ok
+ end,
+
%% kill the handler if it can't keep up with the load
- logger_h_common:kill_if_choked(Name, QLen, Mem, State),
+ logger_h_common:kill_if_choked(Name, QLen, Mem, ?MODULE, State),
if Mode1 == flush ->
flush(Name, QLen, T1, State1);
@@ -519,10 +526,14 @@ do_log(Bin, CallOrCast, State = #{id:=Name}) ->
%% this clause is called by do_log/3 after an overload check
%% has been performed, where QLen > FlushQLen
-flush(Name, _QLen0, T1, State=#{last_log_ts := _T0}) ->
+flush(Name, _QLen0, T1, State=#{last_log_ts := _T0, mode_tab := ModeTab}) ->
%% flush messages in the mailbox (a limited number in
%% order to not cause long delays)
- _NewFlushed = logger_h_common:flush_log_requests(?FLUSH_MAX_N),
+ NewFlushed = logger_h_common:flush_log_events(?FLUSH_MAX_N),
+
+ %% write info in log about flushed messages
+ log_handler_info(Name, "Handler ~p flushed ~w log events",
+ [Name,NewFlushed], State),
%% because of the receive loop when flushing messages, the
%% handler will be scheduled out often and the mailbox could
@@ -530,50 +541,51 @@ flush(Name, _QLen0, T1, State=#{last_log_ts := _T0}) ->
{_,_QLen1} = process_info(self(), message_queue_len),
?observe(Name,{max_qlen,_QLen1}),
- %% Add 1 for the current log request
- ?observe(Name,{flushed,_NewFlushed+1}),
+ %% Add 1 for the current log event
+ ?observe(Name,{flushed,NewFlushed+1}),
State1 = ?update_max_time(?diff_time(T1,_T0),State),
- {dropped,?update_other(flushed,FLUSHED,_NewFlushed,
- State1#{mode => ?set_mode(Name,async),
+ {dropped,?update_other(flushed,FLUSHED,NewFlushed,
+ State1#{mode => ?set_mode(ModeTab,async),
last_qlen => 0,
last_log_ts => T1})}.
%% this clause is called to write to file
-write(Name, Mode, T1, Bin, _CallOrCast,
- State = #{file_ctrl_pid := FileCtrlPid,
+write(_Name, Mode, T1, Bin, _CallOrCast,
+ State = #{mode_tab := ModeTab,
+ file_ctrl_pid := FileCtrlPid,
file_ctrl_sync := FileCtrlSync,
last_qlen := LastQLen,
last_log_ts := T0,
file_ctrl_sync_int := FileCtrlSyncInt}) ->
%% check if we need to limit the number of writes
- %% during a burst of log requests
+ %% during a burst of log events
{DoWrite,BurstWinT,BurstMsgCount} = logger_h_common:limit_burst(State),
- %% only send a synhrounous request to the file controller process
+ %% only send a synhrounous event to the file controller process
%% every FileCtrlSyncInt time, to give the handler time between
%% file writes so it can keep up with incoming messages
{Result,LastQLen1} =
if DoWrite, FileCtrlSync == 0 ->
- ?observe(Name,{_CallOrCast,1}),
+ ?observe(_Name,{_CallOrCast,1}),
file_write_sync(FileCtrlPid, Bin, false),
{ok,element(2, process_info(self(), message_queue_len))};
DoWrite ->
- ?observe(Name,{_CallOrCast,1}),
+ ?observe(_Name,{_CallOrCast,1}),
file_write_async(FileCtrlPid, Bin),
{ok,LastQLen};
not DoWrite ->
- ?observe(Name,{flushed,1}),
+ ?observe(_Name,{flushed,1}),
{dropped,LastQLen}
end,
- %% Check if the time since the previous log request is long enough -
+ %% Check if the time since the previous log event is long enough -
%% and the queue length small enough - to assume the mailbox has
%% been emptied, and if so, do filesync operation and reset mode to
%% async. Note that this is the best we can do to detect an idle
%% handler without setting a timer after each log call/cast. If the
- %% time between two consecutive log requests is fast and no new
- %% request comes in after the last one, idle state won't be detected!
+ %% time between two consecutive log events is fast and no new
+ %% event comes in after the last one, idle state won't be detected!
Time = ?diff_time(T1,T0),
{Mode1,BurstMsgCount1} =
if (LastQLen1 < ?FILESYNC_OK_QLEN) andalso
@@ -585,7 +597,7 @@ write(Name, Mode, T1, Bin, _CallOrCast,
_File ->
file_ctrl_filesync_async(FileCtrlPid)
end,
- {?change_mode(Name, Mode, async),0};
+ {?change_mode(ModeTab, Mode, async),0};
true ->
{Mode,BurstMsgCount}
end,
@@ -634,6 +646,20 @@ close_log_file(Fd) ->
_ = file:datasync(Fd),
_ = file:close(Fd).
+
+log_handler_info(Name, Format, Args, #{file_ctrl_pid := FileCtrlPid}) ->
+ Config =
+ case logger:get_handler_config(Name) of
+ {ok,Conf} -> Conf;
+ _ -> #{formatter=>{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}
+ end,
+ Meta = #{time=>erlang:system_time(microsecond)},
+ Bin = logger_h_common:log_to_binary(#{level => notice,
+ msg => {Format,Args},
+ meta => Meta}, Config),
+ _ = file_write_async(FileCtrlPid, Bin),
+ ok.
+
%%%-----------------------------------------------------------------
%%% File control process
@@ -706,7 +732,7 @@ file_ctrl_init(HandlerName, StdDev, Starter) ->
file_ctrl_loop(Fd, Type, DevName, Synced,
PrevWriteResult, PrevSyncResult, HandlerName) ->
receive
- %% asynchronous request
+ %% asynchronous event
{log,Bin} ->
Result = if Type == file ->
write_to_dev(Fd, Bin, DevName,
@@ -717,7 +743,7 @@ file_ctrl_loop(Fd, Type, DevName, Synced,
file_ctrl_loop(Fd, Type, DevName, false,
Result, PrevSyncResult, HandlerName);
- %% synchronous request
+ %% synchronous event
{{log,From,Bin,FileSync},MRef} ->
if Type == file ->
%% check that file hasn't been deleted
@@ -790,7 +816,7 @@ sync_dev(Fd, DevName, PrevSyncResult, HandlerName) ->
%% don't report same error twice
PrevSyncResult;
Error ->
- logger_h_common:error_notify({HandlerName,filesync,DevName,Error}),
+ logger_h_common:error_notify({HandlerName,sync,DevName,Error}),
Error
end.
diff --git a/lib/kernel/test/Makefile b/lib/kernel/test/Makefile
index 2ad1e3107c..0646395800 100644
--- a/lib/kernel/test/Makefile
+++ b/lib/kernel/test/Makefile
@@ -71,7 +71,6 @@ MODULES= \
init_SUITE \
kernel_config_SUITE \
logger_SUITE \
- logger_bench_SUITE \
logger_disk_log_h_SUITE \
logger_env_var_SUITE \
logger_filters_SUITE \
diff --git a/lib/kernel/test/error_logger_SUITE.erl b/lib/kernel/test/error_logger_SUITE.erl
index 6c4526d0cf..895478f170 100644
--- a/lib/kernel/test/error_logger_SUITE.erl
+++ b/lib/kernel/test/error_logger_SUITE.erl
@@ -33,7 +33,7 @@
off_heap/1,
error_report/1, info_report/1, error/1, info/1,
emulator/1, via_logger_process/1, other_node/1,
- tty/1, logfile/1, add/1, delete/1]).
+ tty/1, logfile/1, add/1, delete/1, format_depth/1]).
-export([generate_error/2]).
@@ -48,7 +48,8 @@ suite() ->
all() ->
[off_heap, error_report, info_report, error, info, emulator,
- via_logger_process, other_node, tty, logfile, add, delete].
+ via_logger_process, other_node, tty, logfile, add, delete,
+ format_depth].
groups() ->
[].
@@ -309,6 +310,21 @@ delete(Config) when is_list(Config) ->
ok.
%%-----------------------------------------------------------------
+
+format_depth(_Config) ->
+ ok = application:set_env(kernel,error_logger_format_depth,30),
+ 30 = error_logger:get_format_depth(),
+ ok = application:set_env(kernel,error_logger_format_depth,3),
+ 10 = error_logger:get_format_depth(),
+ ok = application:set_env(kernel,error_logger_format_depth,11),
+ 11 = error_logger:get_format_depth(),
+ ok = application:set_env(kernel,error_logger_format_depth,unlimited),
+ unlimited = error_logger:get_format_depth(),
+ ok = application:unset_env(kernel,error_logger_format_depth),
+ unlimited = error_logger:get_format_depth(),
+ ok.
+
+%%-----------------------------------------------------------------
%% Check that the report has been received.
%%-----------------------------------------------------------------
reported(Tag, Type, Report) ->
diff --git a/lib/kernel/test/kernel.spec b/lib/kernel/test/kernel.spec
index 86d2155828..62afc9f97b 100644
--- a/lib/kernel/test/kernel.spec
+++ b/lib/kernel/test/kernel.spec
@@ -2,4 +2,3 @@
{config, "../test_server/ts.unix.config"}.
{suites,"../kernel_test", all}.
-{skip_suites,"../kernel_test",[logger_bench_SUITE],"Not ready"}.
diff --git a/lib/kernel/test/logger_SUITE.erl b/lib/kernel/test/logger_SUITE.erl
index f7ec59a7b7..f837c31e64 100644
--- a/lib/kernel/test/logger_SUITE.erl
+++ b/lib/kernel/test/logger_SUITE.erl
@@ -50,7 +50,7 @@ init_per_suite(Config) ->
end_per_suite(Config) ->
case ?config(default_handler,Config) of
- {HMod,HConfig} ->
+ #{module:=HMod} = HConfig ->
ok = logger:add_handler(?STANDARD_HANDLER,HMod,HConfig);
_ ->
ok
@@ -63,8 +63,8 @@ end_per_group(_Group, _Config) ->
ok.
init_per_testcase(_TestCase, Config) ->
- {ok,LC} = logger:get_logger_config(),
- [{logger_config,LC}|Config].
+ PC = logger:get_primary_config(),
+ [{logger_config,PC}|Config].
end_per_testcase(Case, Config) ->
try apply(?MODULE,Case,[cleanup,Config])
@@ -82,11 +82,12 @@ all() ->
add_remove_filter,
change_config,
set_formatter,
+ log_no_levels,
log_all_levels_api,
macros,
set_level,
- set_level_module,
- cache_level_module,
+ set_module_level,
+ cache_module_level,
format_report,
filter_failed,
handler_failed,
@@ -105,29 +106,29 @@ start_stop(_Config) ->
add_remove_handler(_Config) ->
register(callback_receiver,self()),
- #{handlers:=Hs0} = logger:i(),
+ Hs0 = logger:get_handler_config(),
{error,{not_found,h1}} = logger:get_handler_config(h1),
ok = logger:add_handler(h1,?MODULE,#{}),
[add] = test_server:messages_get(),
- #{handlers:=Hs} = logger:i(),
- {value,_,Hs0} = lists:keytake(h1,1,Hs),
- {ok,{?MODULE,#{level:=info,filters:=[],filter_default:=log}}} = % defaults
+ Hs = logger:get_handler_config(),
+ Hs0 = lists:filter(fun(#{id:=h1}) -> false; (_) -> true end, Hs),
+ {ok,#{module:=?MODULE,level:=all,filters:=[],filter_default:=log}} = %defaults
logger:get_handler_config(h1),
ok = logger:set_handler_config(h1,filter_default,stop),
[changing_config] = test_server:messages_get(),
- ?LOG_INFO("hello",[]),
+ ?LOG_NOTICE("hello",[]),
ok = check_no_log(),
ok = logger:set_handler_config(h1,filter_default,log),
[changing_config] = test_server:messages_get(),
- {ok,{?MODULE,#{filter_default:=log}}} = logger:get_handler_config(h1),
- ?LOG_INFO("hello",[]),
- ok = check_logged(info,"hello",[],?MY_LOC(1)),
+ {ok,#{filter_default:=log}} = logger:get_handler_config(h1),
+ ?LOG_NOTICE("hello",[]),
+ ok = check_logged(notice,"hello",[],?MY_LOC(1)),
ok = logger:remove_handler(h1),
[remove] = test_server:messages_get(),
- #{handlers:=Hs0} = logger:i(),
+ Hs0 = logger:get_handler_config(),
{error,{not_found,h1}} = logger:get_handler_config(h1),
{error,{not_found,h1}} = logger:remove_handler(h1),
- logger:info("hello",[]),
+ logger:notice("hello",[]),
ok = check_no_log(),
ok.
@@ -136,13 +137,13 @@ add_remove_handler(cleanup,_Config) ->
ok.
multiple_handlers(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
ok = logger:add_handler(h2,?MODULE,#{level=>error,filter_default=>log}),
?LOG_ERROR("hello",[]),
ok = check_logged(error,"hello",[],?MY_LOC(1)),
ok = check_logged(error,"hello",[],?MY_LOC(2)),
- ?LOG_INFO("hello",[]),
- ok = check_logged(info,"hello",[],?MY_LOC(1)),
+ ?LOG_NOTICE("hello",[]),
+ ok = check_logged(notice,"hello",[],?MY_LOC(1)),
ok = check_no_log(),
ok.
@@ -152,18 +153,18 @@ multiple_handlers(cleanup,_Config) ->
ok.
add_remove_filter(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
LF = {fun(Log,_) -> Log#{level=>error} end, []},
- ok = logger:add_logger_filter(lf,LF),
- {error,{already_exist,lf}} = logger:add_logger_filter(lf,LF),
- {error,{already_exist,lf}} = logger:add_logger_filter(lf,{fun(Log,_) ->
- Log
- end, []}),
- ?LOG_INFO("hello",[]),
+ ok = logger:add_primary_filter(lf,LF),
+ {error,{already_exist,lf}} = logger:add_primary_filter(lf,LF),
+ {error,{already_exist,lf}} = logger:add_primary_filter(lf,{fun(Log,_) ->
+ Log
+ end, []}),
+ ?LOG_NOTICE("hello",[]),
ok = check_logged(error,"hello",[],?MY_LOC(1)),
ok = check_no_log(),
- ok = logger:add_handler(h2,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h2,?MODULE,#{level=>notice,filter_default=>log}),
HF = {fun(#{level:=error}=Log,_) ->
Log#{level=>mylevel};
(_,_) ->
@@ -175,16 +176,16 @@ add_remove_filter(_Config) ->
{error,{already_exist,hf}} = logger:add_handler_filter(h1,hf,{fun(Log,_) ->
Log
end, []}),
- ?LOG_INFO("hello",[]),
+ ?LOG_NOTICE("hello",[]),
ok = check_logged(mylevel,"hello",[],?MY_LOC(1)),
ok = check_logged(error,"hello",[],?MY_LOC(2)),
- ok = logger:remove_logger_filter(lf),
- {error,{not_found,lf}} = logger:remove_logger_filter(lf),
+ ok = logger:remove_primary_filter(lf),
+ {error,{not_found,lf}} = logger:remove_primary_filter(lf),
- ?LOG_INFO("hello",[]),
- ok = check_logged(info,"hello",[],?MY_LOC(1)),
- ok = check_logged(info,"hello",[],?MY_LOC(2)),
+ ?LOG_NOTICE("hello",[]),
+ ok = check_logged(notice,"hello",[],?MY_LOC(1)),
+ ok = check_logged(notice,"hello",[],?MY_LOC(2)),
?LOG_ERROR("hello",[]),
ok = check_logged(mylevel,"hello",[],?MY_LOC(1)),
@@ -192,9 +193,9 @@ add_remove_filter(_Config) ->
ok = logger:remove_handler_filter(h1,hf),
{error,{not_found,hf}} = logger:remove_handler_filter(h1,hf),
- ?LOG_INFO("hello",[]),
- ok = check_logged(info,"hello",[],?MY_LOC(1)),
- ok = check_logged(info,"hello",[],?MY_LOC(2)),
+ ?LOG_NOTICE("hello",[]),
+ ok = check_logged(notice,"hello",[],?MY_LOC(1)),
+ ok = check_logged(notice,"hello",[],?MY_LOC(2)),
?LOG_ERROR("hello",[]),
ok = check_logged(error,"hello",[],?MY_LOC(1)),
@@ -202,20 +203,20 @@ add_remove_filter(_Config) ->
ok.
add_remove_filter(cleanup,_Config) ->
- logger:remove_logger_filter(lf),
+ logger:remove_primary_filter(lf),
logger:remove_handler(h1),
logger:remove_handler(h2),
ok.
change_config(_Config) ->
%% Overwrite handler config - check that defaults are added
- ok = logger:add_handler(h1,?MODULE,#{level=>debug,custom=>custom}),
- {ok,{?MODULE,#{level:=debug,filter_default:=log,custom:=custom}}} =
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,custom=>custom}),
+ {ok,#{module:=?MODULE,level:=notice,filter_default:=log,custom:=custom}} =
logger:get_handler_config(h1),
register(callback_receiver,self()),
ok = logger:set_handler_config(h1,#{filter_default=>stop}),
[changing_config] = test_server:messages_get(),
- {ok,{?MODULE,#{level:=info,filter_default:=stop}=C2}} =
+ {ok,#{module:=?MODULE,level:=all,filter_default:=stop}=C2} =
logger:get_handler_config(h1),
false = maps:is_key(custom,C2),
{error,fail} = logger:set_handler_config(h1,#{conf_call=>fun() -> {error,fail} end}),
@@ -225,60 +226,60 @@ change_config(_Config) ->
ok =
logger:set_handler_config(
h1,#{conf_call=>fun() -> logger:set_module_level(?MODULE,debug) end}),
- {ok,{?MODULE,C2}} = logger:get_handler_config(h1),
+ {ok,C2} = logger:get_handler_config(h1),
%% Change handler config: Single key
{error,fail} = logger:set_handler_config(h1,conf_call,fun() -> {error,fail} end),
ok = logger:set_handler_config(h1,custom,custom),
[changing_config] = test_server:messages_get(),
- {ok,{?MODULE,#{custom:=custom}=C3}} = logger:get_handler_config(h1),
+ {ok,#{custom:=custom}=C3} = logger:get_handler_config(h1),
C2 = maps:remove(custom,C3),
%% Change handler config: Map
ok = logger:update_handler_config(h1,#{custom=>new_custom}),
[changing_config] = test_server:messages_get(),
- {ok,{_,C4}} = logger:get_handler_config(h1),
+ {ok,C4} = logger:get_handler_config(h1),
C4 = C3#{custom:=new_custom},
- %% Change logger config: Single key
- {ok,LConfig0} = logger:get_logger_config(),
- ok = logger:set_logger_config(level,warning),
- {ok,LConfig1} = logger:get_logger_config(),
- LConfig1 = LConfig0#{level:=warning},
-
- %% Change logger config: Map
- ok = logger:update_logger_config(#{level=>error}),
- {ok,LConfig2} = logger:get_logger_config(),
- LConfig2 = LConfig1#{level:=error},
-
- %% Overwrite logger config - check that defaults are added
- ok = logger:set_logger_config(#{filter_default=>stop}),
- {ok,#{level:=info,filters:=[],filter_default:=stop}=LC1} =
- logger:get_logger_config(),
- 3 = maps:size(LC1),
+ %% Change primary config: Single key
+ PConfig0 = logger:get_primary_config(),
+ ok = logger:set_primary_config(level,warning),
+ PConfig1 = logger:get_primary_config(),
+ PConfig1 = PConfig0#{level:=warning},
+
+ %% Change primary config: Map
+ ok = logger:update_primary_config(#{level=>error}),
+ PConfig2 = logger:get_primary_config(),
+ PConfig2 = PConfig1#{level:=error},
+
+ %% Overwrite primary config - check that defaults are added
+ ok = logger:set_primary_config(#{filter_default=>stop}),
+ #{level:=notice,filters:=[],filter_default:=stop}=PC1 =
+ logger:get_primary_config(),
+ 3 = maps:size(PC1),
%% Check that internal 'handlers' field has not been changed
- #{handlers:=HCs} = logger:i(),
- HIds1 = [Id || {Id,_,_} <- HCs],
- {ok,#{handlers:=HIds2}} = logger_config:get(?LOGGER_TABLE,logger),
- HIds1 = lists:sort(HIds2),
+ MS = [{{{?HANDLER_KEY,'$1'},'_','_','_'},[],['$1']}],
+ HIds1 = lists:sort(ets:select(?LOGGER_TABLE,MS)), % dirty, internal data
+ HIds2 = lists:sort(logger:get_handler_ids()),
+ HIds1 = HIds2,
%% Cleanup
- ok = logger:set_logger_config(LConfig0),
+ ok = logger:set_primary_config(PConfig0),
[] = test_server:messages_get(),
ok.
change_config(cleanup,Config) ->
logger:remove_handler(h1),
- LC = ?config(logger_config,Config),
- logger:set_logger_config(LC),
+ PC = ?config(logger_config,Config),
+ logger:set_primary_config(PC),
ok.
set_formatter(_Config) ->
{error,{not_found,h1}}=logger:set_handler_config(h1,formatter,{?MODULE,[]}),
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
ok = logger:set_handler_config(h1,formatter,{?MODULE,[]}),
- logger:info("hello",[]),
+ logger:notice("hello",[]),
receive
{_Log,#{formatter:={?MODULE,[]}}} ->
ok
@@ -291,9 +292,50 @@ set_formatter(cleanup,_Config) ->
logger:remove_handler(h1),
ok.
+log_no_levels(_Config) ->
+ ok = logger:add_handler(h1,?MODULE,#{level=>all,filter_default=>log}),
+ logger:notice(M1=?map_rep),
+ ok = check_logged(notice,M1,#{}),
+
+ Levels = [emergency,alert,critical,error,warning,notice,info,debug],
+ ok = logger:set_primary_config(level,none),
+ [logger:Level(#{Level=>rep}) || Level <- Levels],
+ ok = check_no_log(),
+
+ ok = logger:set_primary_config(level,all),
+ M2 = ?map_rep,
+ ?LOG_NOTICE(M2),
+ ok = check_logged(notice,M2,#{}),
+
+ ok = logger:set_module_level(?MODULE,none),
+ ?LOG_EMERGENCY(?map_rep),
+ ?LOG_ALERT(?map_rep),
+ ?LOG_CRITICAL(?map_rep),
+ ?LOG_ERROR(?map_rep),
+ ?LOG_WARNING(?map_rep),
+ ?LOG_NOTICE(?map_rep),
+ ?LOG_INFO(?map_rep),
+ ?LOG_DEBUG(?map_rep),
+ ok = check_no_log(),
+
+ ok = logger:unset_module_level(?MODULE),
+ logger:notice(M3=?map_rep),
+ ok = check_logged(notice,M3,#{}),
+
+ ok = logger:set_handler_config(h1,level,none),
+ [logger:Level(#{Level=>rep}) || Level <- Levels],
+ ok = check_no_log(),
+
+ ok.
+log_no_levels(cleanup,_Config) ->
+ logger:remove_handler(h1),
+ logger:set_primary_config(level,info),
+ logger:unset_module_level(?MODULE),
+ ok.
+
log_all_levels_api(_Config) ->
- ok = logger:set_logger_config(level,debug),
- ok = logger:add_handler(h1,?MODULE,#{level=>debug,filter_default=>log}),
+ ok = logger:set_primary_config(level,all),
+ ok = logger:add_handler(h1,?MODULE,#{level=>all,filter_default=>log}),
test_api(emergency),
test_api(alert),
test_api(critical),
@@ -307,12 +349,11 @@ log_all_levels_api(_Config) ->
log_all_levels_api(cleanup,_Config) ->
logger:remove_handler(h1),
- logger:set_logger_config(level,info),
+ logger:set_primary_config(level,notice),
ok.
macros(_Config) ->
- ok = logger:set_module_level(?MODULE,debug),
- ok = logger:add_handler(h1,?MODULE,#{level=>debug,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>all,filter_default=>log}),
test_macros(emergency),
ok.
@@ -322,56 +363,77 @@ macros(cleanup,_Config) ->
ok.
set_level(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>debug,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>all,filter_default=>log}),
logger:debug(?map_rep),
ok = check_no_log(),
- logger:info(M1=?map_rep),
- ok = check_logged(info,M1,#{}),
- ok = logger:set_logger_config(level,debug),
+ logger:notice(M1=?map_rep),
+ ok = check_logged(notice,M1,#{}),
+ ok = logger:set_primary_config(level,debug),
logger:debug(M2=?map_rep),
ok = check_logged(debug,M2,#{}),
ok.
set_level(cleanup,_Config) ->
logger:remove_handler(h1),
- logger:set_logger_config(level,info),
+ logger:set_primary_config(level,notice),
ok.
-set_level_module(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+set_module_level(_Config) ->
+ [] = logger:get_module_level([?MODULE,other]),
+ [] = logger:get_module_level(?MODULE),
+ [] = logger:get_module_level(),
+
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
{error,{invalid_level,bad}} = logger:set_module_level(?MODULE,bad),
- {error,{not_a_module,{bad}}} = logger:set_module_level({bad},warning),
+ {error,{not_a_list_of_modules,{bad}}} =
+ logger:set_module_level({bad},warning),
ok = logger:set_module_level(?MODULE,warning),
- logger:info(?map_rep,?MY_LOC(0)),
+ [{?MODULE,warning}] = logger:get_module_level([?MODULE,other]),
+ [{?MODULE,warning}] = logger:get_module_level(?MODULE),
+ [{?MODULE,warning}] = logger:get_module_level(),
+ logger:notice(?map_rep,?MY_LOC(0)),
ok = check_no_log(),
logger:warning(M1=?map_rep,?MY_LOC(0)),
ok = check_logged(warning,M1,?MY_LOC(1)),
- ok = logger:set_module_level(?MODULE,info),
- logger:info(M2=?map_rep,?MY_LOC(0)),
- ok = check_logged(info,M2,?MY_LOC(1)),
-
- {error,{not_a_module,{bad}}} = logger:unset_module_level({bad}),
+ ok = logger:set_module_level(?MODULE,notice),
+ [{?MODULE,notice}] = logger:get_module_level([?MODULE,other]),
+ [{?MODULE,notice}] = logger:get_module_level(?MODULE),
+ [{?MODULE,notice}] = logger:get_module_level(),
+ logger:notice(M2=?map_rep,?MY_LOC(0)),
+ ok = check_logged(notice,M2,?MY_LOC(1)),
+
+ {error,{not_a_list_of_modules,{bad}}} = logger:unset_module_level({bad}),
ok = logger:unset_module_level(?MODULE),
+ [] = logger:get_module_level([?MODULE,other]),
+ [] = logger:get_module_level(?MODULE),
+ [] = logger:get_module_level(),
+
+ ok = logger:set_module_level([m1,m2,m3],notice),
+ [{m1,notice},{m2,notice},{m3,notice}] = logger:get_module_level(),
+ ok = logger:unset_module_level(m2),
+ [{m1,notice},{m3,notice}] = logger:get_module_level(),
+ ok = logger:unset_module_level(),
+ [] = logger:get_module_level(),
ok.
-set_level_module(cleanup,_Config) ->
+set_module_level(cleanup,_Config) ->
logger:remove_handler(h1),
logger:unset_module_level(?MODULE),
ok.
-cache_level_module(_Config) ->
+cache_module_level(_Config) ->
ok = logger:unset_module_level(?MODULE),
- [] = ets:lookup(logger,?MODULE), %dirty - add API in logger_config?
- ?LOG_INFO(?map_rep),
+ [] = ets:lookup(?LOGGER_TABLE,?MODULE), %dirty - add API in logger_config?
+ ?LOG_NOTICE(?map_rep),
%% Caching is done asynchronously, so wait a bit for the update
timer:sleep(100),
- [_] = ets:lookup(logger,?MODULE), %dirty - add API in logger_config?
+ [_] = ets:lookup(?LOGGER_TABLE,?MODULE), %dirty - add API in logger_config?
ok = logger:unset_module_level(?MODULE),
- [] = ets:lookup(logger,?MODULE), %dirty - add API in logger_config?
+ [] = ets:lookup(?LOGGER_TABLE,?MODULE), %dirty - add API in logger_config?
ok.
-cache_level_module(cleanup,_Config) ->
+cache_module_level(cleanup,_Config) ->
logger:unset_module_level(?MODULE),
ok.
@@ -402,22 +464,22 @@ format_report(_Config) ->
ok.
filter_failed(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
%% Logger filters
{error,{invalid_filter,_}} =
- logger:add_logger_filter(lf,{fun(_) -> ok end,args}),
- ok = logger:add_logger_filter(lf,{fun(_,_) -> a=b end,args}),
- {ok,#{filters:=[_]}} = logger:get_logger_config(),
- ok = logger:info(M1=?map_rep),
- ok = check_logged(info,M1,#{}),
- {error,{not_found,lf}} = logger:remove_logger_filter(lf),
-
- ok = logger:add_logger_filter(lf,{fun(_,_) -> faulty_return end,args}),
- {ok,#{filters:=[_]}} = logger:get_logger_config(),
- ok = logger:info(M2=?map_rep),
- ok = check_logged(info,M2,#{}),
- {error,{not_found,lf}} = logger:remove_logger_filter(lf),
+ logger:add_primary_filter(lf,{fun(_) -> ok end,args}),
+ ok = logger:add_primary_filter(lf,{fun(_,_) -> a=b end,args}),
+ #{filters:=[_]} = logger:get_primary_config(),
+ ok = logger:notice(M1=?map_rep),
+ ok = check_logged(notice,M1,#{}),
+ {error,{not_found,lf}} = logger:remove_primary_filter(lf),
+
+ ok = logger:add_primary_filter(lf,{fun(_,_) -> faulty_return end,args}),
+ #{filters:=[_]} = logger:get_primary_config(),
+ ok = logger:notice(M2=?map_rep),
+ ok = check_logged(notice,M2,#{}),
+ {error,{not_found,lf}} = logger:remove_primary_filter(lf),
%% Handler filters
{error,{not_found,h0}} =
@@ -426,15 +488,15 @@ filter_failed(_Config) ->
{error,{invalid_filter,_}} =
logger:add_handler_filter(h1,hf,{fun(_) -> ok end,args}),
ok = logger:add_handler_filter(h1,hf,{fun(_,_) -> a=b end,args}),
- {ok,{?MODULE,#{filters:=[_]}}} = logger:get_handler_config(h1),
- ok = logger:info(M3=?map_rep),
- ok = check_logged(info,M3,#{}),
+ {ok,#{filters:=[_]}} = logger:get_handler_config(h1),
+ ok = logger:notice(M3=?map_rep),
+ ok = check_logged(notice,M3,#{}),
{error,{not_found,hf}} = logger:remove_handler_filter(h1,hf),
ok = logger:add_handler_filter(h1,hf,{fun(_,_) -> faulty_return end,args}),
- {ok,{?MODULE,#{filters:=[_]}}} = logger:get_handler_config(h1),
- ok = logger:info(M4=?map_rep),
- ok = check_logged(info,M4,#{}),
+ {ok,#{filters:=[_]}} = logger:get_handler_config(h1),
+ ok = logger:notice(M4=?map_rep),
+ ok = check_logged(notice,M4,#{}),
{error,{not_found,hf}} = logger:remove_handler_filter(h1,hf),
ok.
@@ -455,20 +517,20 @@ handler_failed(_Config) ->
{error,{invalid_formatter,[]}} =
logger:add_handler(h1,?MODULE,#{formatter=>[]}),
{error,{invalid_handler,_}} = logger:add_handler(h1,nomodule,#{filter_default=>log}),
- logger:info(?map_rep),
+ logger:notice(?map_rep),
check_no_log(),
- #{handlers:=H1} = logger:i(),
- false = lists:keymember(h1,1,H1),
+ H1 = logger:get_handler_config(),
+ false = lists:search(fun(#{id:=h1}) -> true; (_) -> false end,H1),
{error,{not_found,h1}} = logger:remove_handler(h1),
ok = logger:add_handler(h2,?MODULE,#{filter_default=>log,log_call=>fun() -> a = b end}),
{error,{already_exist,h2}} = logger:add_handler(h2,othermodule,#{}),
[add] = test_server:messages_get(),
- logger:info(?map_rep),
+ logger:notice(?map_rep),
[remove] = test_server:messages_get(),
- #{handlers:=H2} = logger:i(),
- false = lists:keymember(h2,1,H2),
+ H2 = logger:get_handler_config(),
+ false = lists:search(fun(#{id:=h2}) -> true; (_) -> false end,H2),
{error,{not_found,h2}} = logger:remove_handler(h2),
CallAddHandler = fun() -> logger:add_handler(h2,?MODULE,#{}) end,
@@ -520,18 +582,18 @@ handler_failed(cleanup,_Config) ->
config_sanity_check(_Config) ->
%% Logger config
{error,{invalid_filter_default,bad}} =
- logger:set_logger_config(filter_default,bad),
- {error,{invalid_level,bad}} = logger:set_logger_config(level,bad),
- {error,{invalid_filters,bad}} = logger:set_logger_config(filters,bad),
- {error,{invalid_filter,bad}} = logger:set_logger_config(filters,[bad]),
+ logger:set_primary_config(filter_default,bad),
+ {error,{invalid_level,bad}} = logger:set_primary_config(level,bad),
+ {error,{invalid_filters,bad}} = logger:set_primary_config(filters,bad),
+ {error,{invalid_filter,bad}} = logger:set_primary_config(filters,[bad]),
{error,{invalid_filter,{_,_}}} =
- logger:set_logger_config(filters,[{id,bad}]),
+ logger:set_primary_config(filters,[{id,bad}]),
{error,{invalid_filter,{_,{_,_}}}} =
- logger:set_logger_config(filters,[{id,{bad,args}}]),
+ logger:set_primary_config(filters,[{id,{bad,args}}]),
{error,{invalid_filter,{_,{_,_}}}} =
- logger:set_logger_config(filters,[{id,{fun() -> ok end,args}}]),
- {error,{invalid_logger_config,{bad,bad}}} =
- logger:set_logger_config(bad,bad),
+ logger:set_primary_config(filters,[{id,{fun() -> ok end,args}}]),
+ {error,{invalid_primary_config,{bad,bad}}} =
+ logger:set_primary_config(bad,bad),
%% Handler config
{error,{not_found,h1}} = logger:set_handler_config(h1,a,b),
@@ -555,7 +617,7 @@ config_sanity_check(_Config) ->
logger:set_handler_config(h1,formatter,{logger_formatter,bad}),
{error,{invalid_formatter_config,logger_formatter,{bad,bad}}} =
logger:set_handler_config(h1,formatter,{logger_formatter,#{bad=>bad}}),
- {error,{invalid_formatter_config,logger_formatter,{template,bad}}} =
+ {error,{invalid_formatter_template,logger_formatter,bad}} =
logger:set_handler_config(h1,formatter,{logger_formatter,
#{template=>bad}}),
{error,{invalid_formatter_template,logger_formatter,[1]}} =
@@ -648,30 +710,30 @@ config_sanity_check(cleanup,_Config) ->
ok.
log_failed(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
{error,function_clause} = ?TRY(logger:log(bad,?map_rep)),
- {error,function_clause} = ?TRY(logger:log(info,?map_rep,bad)),
- {error,function_clause} = ?TRY(logger:log(info,fun() -> ?map_rep end,bad)),
- {error,function_clause} = ?TRY(logger:log(info,fun() -> ?map_rep end,bad,#{})),
- {error,function_clause} = ?TRY(logger:log(info,bad,bad,bad)),
- {error,function_clause} = ?TRY(logger:log(info,bad,bad,#{})),
+ {error,function_clause} = ?TRY(logger:log(notice,?map_rep,bad)),
+ {error,function_clause} = ?TRY(logger:log(notice,fun() -> ?map_rep end,bad)),
+ {error,function_clause} = ?TRY(logger:log(notice,fun() -> ?map_rep end,bad,#{})),
+ {error,function_clause} = ?TRY(logger:log(notice,bad,bad,bad)),
+ {error,function_clause} = ?TRY(logger:log(notice,bad,bad,#{})),
check_no_log(),
- ok = logger:log(info,M1=?str,#{}),
- check_logged(info,M1,#{}),
- ok = logger:log(info,M2=?map_rep,#{}),
- check_logged(info,M2,#{}),
- ok = logger:log(info,M3=?keyval_rep,#{}),
- check_logged(info,M3,#{}),
+ ok = logger:log(notice,M1=?str,#{}),
+ check_logged(notice,M1,#{}),
+ ok = logger:log(notice,M2=?map_rep,#{}),
+ check_logged(notice,M2,#{}),
+ ok = logger:log(notice,M3=?keyval_rep,#{}),
+ check_logged(notice,M3,#{}),
%% Should we check report input more thoroughly?
- ok = logger:log(info,M4=?keyval_rep++[other,stuff,in,list],#{}),
- check_logged(info,M4,#{}),
+ ok = logger:log(notice,M4=?keyval_rep++[other,stuff,in,list],#{}),
+ check_logged(notice,M4,#{}),
%% This might break a handler since it is assumed to be a format
%% string and args, so it depends how the handler protects itself
%% against something like io_lib:format("ok","ok")
- ok = logger:log(info,"ok","ok",#{}),
- check_logged(info,"ok","ok",#{}),
+ ok = logger:log(notice,"ok","ok",#{}),
+ check_logged(notice,"ok","ok",#{}),
ok.
@@ -680,7 +742,7 @@ log_failed(cleanup,_Config) ->
ok.
emulator(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log,
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log,
tc_proc=>self()}),
Msg = "Error in process ~p on node ~p with exit value:~n~p~n",
Error = {badmatch,4},
@@ -699,7 +761,7 @@ generate_error(Error, Stack) ->
erlang:raise(error, Error, Stack).
via_logger_process(Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log,
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log,
tc_proc=>self()}),
%% Explicitly send a message to the logger process
@@ -736,7 +798,7 @@ via_logger_process(cleanup, Config) ->
ok.
other_node(_Config) ->
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log,
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log,
tc_proc=>self()}),
{ok,Node} = test_server:start_node(?FUNCTION_NAME,slave,[]),
rpc:call(Node,logger,error,[Msg=?str,#{}]),
@@ -753,8 +815,8 @@ compare_levels(_Config) ->
Levels = [emergency,alert,critical,error,warning,notice,info,debug],
ok = compare(Levels),
{error,badarg} = ?TRY(logger:compare_levels(bad,bad)),
- {error,badarg} = ?TRY(logger:compare_levels({bad},info)),
- {error,badarg} = ?TRY(logger:compare_levels(info,"bad")),
+ {error,badarg} = ?TRY(logger:compare_levels({bad},notice)),
+ {error,badarg} = ?TRY(logger:compare_levels(notice,"bad")),
ok.
compare([L|Rest]) ->
@@ -768,21 +830,21 @@ compare([]) ->
process_metadata(_Config) ->
undefined = logger:get_process_metadata(),
{error,badarg} = ?TRY(logger:set_process_metadata(bad)),
- ok = logger:add_handler(h1,?MODULE,#{level=>info,filter_default=>log}),
+ ok = logger:add_handler(h1,?MODULE,#{level=>notice,filter_default=>log}),
Time = erlang:system_time(microsecond),
ProcMeta = #{time=>Time,line=>0,custom=>proc},
ok = logger:set_process_metadata(ProcMeta),
S1 = ?str,
- ?LOG_INFO(S1,#{custom=>macro}),
- check_logged(info,S1,#{time=>Time,line=>0,custom=>macro}),
+ ?LOG_NOTICE(S1,#{custom=>macro}),
+ check_logged(notice,S1,#{time=>Time,line=>0,custom=>macro}),
Time2 = erlang:system_time(microsecond),
S2 = ?str,
- ?LOG_INFO(S2,#{time=>Time2,line=>1,custom=>macro}),
- check_logged(info,S2,#{time=>Time2,line=>1,custom=>macro}),
+ ?LOG_NOTICE(S2,#{time=>Time2,line=>1,custom=>macro}),
+ check_logged(notice,S2,#{time=>Time2,line=>1,custom=>macro}),
- logger:info(S3=?str,#{custom=>func}),
- check_logged(info,S3,#{time=>Time,line=>0,custom=>func}),
+ logger:notice(S3=?str,#{custom=>func}),
+ check_logged(notice,S3,#{time=>Time,line=>0,custom=>func}),
ProcMeta = logger:get_process_metadata(),
ok = logger:update_process_metadata(#{custom=>changed,custom2=>added}),
diff --git a/lib/kernel/test/logger_bench_SUITE.erl b/lib/kernel/test/logger_bench_SUITE.erl
deleted file mode 100644
index d47122ea9d..0000000000
--- a/lib/kernel/test/logger_bench_SUITE.erl
+++ /dev/null
@@ -1,500 +0,0 @@
-%%
-%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2018. All Rights Reserved.
-%%
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%% http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%%
-%% %CopyrightEnd%
-%%
--module(logger_bench_SUITE).
-
--compile(export_all).
-
-%%%-----------------------------------------------------------------
-%%% To include lager tests, add paths to lager and goldrush
-%%% (goldrush is a dependency inside the lager repo)
-%%%
-%%% To print data to .csv files, add the following to a config file:
-%%% {print_csv,[{console_handler,[{path,"/some/dir/"}]}]}.
-%%%
-%%%-----------------------------------------------------------------
-
--include_lib("common_test/include/ct.hrl").
--include_lib("common_test/include/ct_event.hrl").
--include_lib("kernel/include/logger.hrl").
--include_lib("kernel/src/logger_internal.hrl").
-
--define(msg,lists:flatten(string:pad("Log from "++atom_to_list(?FUNCTION_NAME)++
- ":"++integer_to_list(?LINE),
- 80,trailing,$*))).
--define(meta,#{mfa=>{?MODULE,?FUNCTION_NAME,?FUNCTION_ARITY},
- pid=>self()}).
-
--define(NO_COMPARE,[profile]).
-
--define(TIMES,100000).
-
-suite() ->
- [{timetrap,{seconds,120}}].
-
-init_per_suite(Config) ->
- DataDir = ?config(data_dir,Config),
- have_lager() andalso make(DataDir),
- Config.
-
-end_per_suite(_Config) ->
- ok.
-
-init_per_group(Group, Config) ->
- H = remove_all_handlers(),
- do_init_per_group(Group),
- [{handlers,H}|Config].
-
-do_init_per_group(minimal_handler) ->
- ok = logger:add_handler(?MODULE,?MODULE,#{level=>error,filter_default=>log});
-do_init_per_group(console_handler) ->
- ok = logger:add_handler(?MODULE,logger_std_h,
- #{filter_default=>stop,
- filters=>?DEFAULT_HANDLER_FILTERS,
- logger_std_h=>#{type=>standard_io,
- toggle_sync_qlen => ?TIMES+1,
- drop_new_reqs_qlen => ?TIMES+2,
- flush_reqs_qlen => ?TIMES+3,
- enable_burst_limit => false}}),
- have_lager() andalso lager_helper:start(),
- ok.
-
-end_per_group(Group, Config) ->
- case ?config(saved_config,Config) of
- {_,[{bench,Bench}]} ->
- print_compare_chart(Group,Bench);
- _ ->
- ok
- end,
- add_all_handlers(?config(handlers,Config)),
- do_end_per_group(Group).
-
-do_end_per_group(minimal_handler) ->
- ok = logger:remove_handler(?MODULE);
-do_end_per_group(console_handler) ->
- ok = logger:remove_handler(?MODULE),
- have_lager() andalso lager_helper:stop(),
- ok.
-
-init_per_testcase(_TestCase, Config) ->
- Config.
-
-end_per_testcase(Case, Config) ->
- try apply(?MODULE,Case,[cleanup,Config])
- catch error:undef -> ok
- end,
- wait_for_handlers(),
- ok.
-
-wait_for_handlers() ->
- wait_for_handler(?MODULE),
- wait_for_handler(lager_event).
-
-wait_for_handler(Handler) ->
- case whereis(Handler) of
- undefined ->
- io:format("~p: noproc1",[Handler]),
- ok;
- Pid ->
- case process_info(Pid,message_queue_len) of
- {_,0} ->
- io:format("~p: queue=~p",[Handler,0]),
- ok;
- {_,Q} ->
- io:format("~p: queue=~p",[Handler,Q]),
- timer:sleep(2000),
- wait_for_handler(Handler);
- undefined ->
- io:format("~p: noproc2",[Handler]),
- ok
- end
- end.
-
-groups() ->
- [{minimal_handler,[],[log,
- log_drop,
- log_drop_by_handler,
- macro,
- macro_drop,
- macro_drop_by_handler,
- error_logger,
- error_logger_drop,
- error_logger_drop_by_handler
- ]},
- {console_handler,[],[%profile,
- log,
- log_drop,
- log_drop_by_handler,
- %% log_handler_complete,
- macro,
- macro_drop,
- macro_drop_by_handler,
- %% macro_handler_complete,
- error_logger,
- error_logger_drop,
- error_logger_drop_by_handler%% ,
- %% error_logger_handler_complete
- ] ++ lager_cases()}
- ].
-
-lager_cases() ->
- case have_lager() of
- true ->
- [lager_log,
- lager_log_drop,
- lager_log_drop_by_handler,
- %% lager_log_handler_complete,
- lager_parsetrans,
- lager_parsetrans_drop,
- lager_parsetrans_drop_by_handler%% ,
- %% lager_parsetrans_handler_complete
- ];
- false ->
- []
- end.
-
-
-all() ->
- [{group,minimal_handler},
- {group,console_handler}
- ].
-
-log(Config) ->
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_func/2, [error,?msg], Times).
-
-log_drop(Config) ->
- Times = ?TIMES*100,
- ok = logger:set_logger_config(level,error),
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_func/2, [info,?msg], Times).
-
-log_drop(cleanup,_Config) ->
- ok = logger:set_logger_config(level,info).
-
-log_drop_by_handler(Config) ->
- Times = ?TIMES,
- %% just ensure correct levels
- ok = logger:set_logger_config(level,info),
- ok = logger:set_handler_config(?MODULE,level,error),
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_func/2, [info,?msg], Times).
-
-log_handler_complete(Config) ->
- ok = logger:set_handler_config(?MODULE,formatter,
- {?MODULE,?DEFAULT_FORMAT_CONFIG}),
- handler_complete(Config, ?FUNCTION_NAME, fun do_log_func/2, [error,?msg]).
-
-log_handler_complete(cleanup,_Config) ->
- ok=logger:set_handler_config(?MODULE,formatter,
- {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}).
-
-macro(Config) ->
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_macro/2,[error,?msg], Times).
-
-macro_drop(Config) ->
- Times = ?TIMES*100,
- ok = logger:set_logger_config(level,error),
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_macro/2,[info,?msg], Times).
-
-macro_drop(cleanup,_Config) ->
- ok = logger:set_logger_config(level,info).
-
-macro_drop_by_handler(Config) ->
- Times = ?TIMES,
- %% just ensure correct levels
- ok = logger:set_logger_config(level,info),
- ok = logger:set_handler_config(?MODULE,level,error),
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_macro/2, [info,?msg], Times).
-
-macro_handler_complete(Config) ->
- ok = logger:set_handler_config(?MODULE,formatter,
- {?MODULE,?DEFAULT_FORMAT_CONFIG}),
- handler_complete(Config, ?FUNCTION_NAME, fun do_log_macro/2, [error,?msg]).
-
-macro_handler_complete(cleanup,_Config) ->
- ok=logger:set_handler_config(?MODULE,formatter,
- {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}).
-
-error_logger(Config) ->
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun do_error_logger/2, [error,?msg], Times).
-
-error_logger_drop(Config) ->
- Times = ?TIMES*100,
- ok = logger:set_logger_config(level,error),
- run_benchmark(Config,?FUNCTION_NAME,fun do_error_logger/2, [info,?msg], Times).
-
-error_logger_drop(cleanup,_Config) ->
- ok = logger:set_logger_config(level,info).
-
-error_logger_drop_by_handler(Config) ->
- Times = ?TIMES,
- %% just ensure correct levels
- ok = logger:set_logger_config(level,info),
- ok = logger:set_handler_config(?MODULE,level,error),
- run_benchmark(Config,?FUNCTION_NAME,fun do_log_func/2, [info,?msg], Times).
-
-error_logger_handler_complete(Config) ->
- ok = logger:set_handler_config(?MODULE,formatter,
- {?MODULE,?DEFAULT_FORMAT_CONFIG}),
- handler_complete(Config, ?FUNCTION_NAME, fun do_error_logger/2, [error,?msg]).
-
-error_logger_handler_complete(cleanup,_Config) ->
- ok=logger:set_handler_config(?MODULE,formatter,
- {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}).
-
-lager_log(Config) ->
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun lager_helper:do_func/2, [error,?msg], Times).
-
-lager_log_drop(Config) ->
- Times = ?TIMES*100,
- run_benchmark(Config,?FUNCTION_NAME,fun lager_helper:do_func/2, [info,?msg], Times).
-
-lager_log_drop_by_handler(Config) ->
- %% This concept does not exist, so doing same as lager_log_drop/1
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun lager_helper:do_func/2, [info,?msg], Times).
-
-lager_log_handler_complete(Config) ->
- handler_complete(Config, ?FUNCTION_NAME, fun lager_helper:do_func/2, [error,?msg]).
-
-lager_parsetrans(Config) ->
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun lager_helper:do_parsetrans/2, [error,?msg], Times).
-
-lager_parsetrans_drop(Config) ->
- Times = ?TIMES*100,
- run_benchmark(Config,?FUNCTION_NAME,fun lager_helper:do_parsetrans/2, [info,?msg], Times).
-
-lager_parsetrans_drop_by_handler(Config) ->
- %% This concept does not exist, so doing same as lager_parsetrans_drop/1
- Times = ?TIMES,
- run_benchmark(Config,?FUNCTION_NAME,fun lager_helper:do_parsetrans/2, [info,?msg], Times).
-
-lager_parsetrans_handler_complete(Config) ->
- handler_complete(Config, ?FUNCTION_NAME, fun lager_helper:do_parsetrans/2, [error,?msg]).
-
-
-profile(Config) ->
- Times = ?TIMES,
- %% fprof:apply(fun repeated_apply/3,[fun lager_helper:do_func/2,[error,?msg],Times]),
- fprof:apply(fun repeated_apply/3,[fun do_log_func/2,[error,?msg],Times]),
- ok = fprof:profile(),
- ok = fprof:analyse(dest,"../fprof.analyse"),
- ok.
-
-%%%-----------------------------------------------------------------
-%%% Internal
-%% Handler
-log(_Log,_Config) ->
- ok.
-
-format(Log=#{meta:=#{pid:=Pid}},Config) when is_pid(Pid) ->
- String = ?DEFAULT_FORMATTER:format(Log,Config),
- Pid ! done,
- String;
-format(Log=#{meta:=#{pid:=PidStr}},Config) when is_list(PidStr) ->
- String = ?DEFAULT_FORMATTER:format(Log,Config),
- list_to_pid(PidStr) ! done,
- String.
-
-handler_complete(Config, TC, Fun, Args) ->
- Times = ?TIMES,
- Start = os:perf_counter(microsecond),
- repeated_apply(Fun, Args, Times),
- MSecs = wait_for_done(Start,Times),
- calc_and_report(Config,TC,MSecs,Times).
-
-wait_for_done(Start,0) ->
- os:perf_counter(microsecond) - Start;
-wait_for_done(Start,N) ->
- receive
- done ->
- wait_for_done(Start,N-1)
- after 20000 ->
- ct:fail("missing " ++ integer_to_list(N) ++ " replys")
- end.
-
-%%%-----------------------------------------------------------------
-%%% Benchmark stuff
-run_benchmark(Config,Tag,Fun,Args,Times) ->
- _ = erlang:apply(Fun, Args), % apply once to ensure level is cached
- MSecs = measure_repeated_op(Fun, Args, Times),
- %% fprof:profile(),
- %% fprof:analyse(dest,"../"++atom_to_list(Tag)++".prof"),
- calc_and_report(Config,Tag,MSecs,Times).
-
-measure_repeated_op(Fun, Args, Times) ->
- Start = os:perf_counter(microsecond),
- %% fprof:apply(fun repeated_apply/3, [Fun, Args, Times]),
- repeated_apply(Fun, Args, Times),
- os:perf_counter(microsecond) - Start.
-
-repeated_apply(_F, _Args, Times) when Times =< 0 ->
- ok;
-repeated_apply(F, Args, Times) ->
- erlang:apply(F, Args),
- repeated_apply(F, Args, Times - 1).
-
-calc_and_report(Config,Tag,MSecs,Times) ->
- IOPS = trunc(Times * (1000000 / MSecs)),
- ct_event:notify(#event{ name = benchmark_data, data = [{value,IOPS}] }),
- ct:print("~p:~n~p IOPS, ~p us", [Tag, IOPS, MSecs]),
- ct:comment("~p IOPS, ~p us", [IOPS, MSecs]),
- Bench = case ?config(saved_config,Config) of
- {_,[{bench,B}]} -> B;
- undefined -> []
- end,
- {save_config,[{bench,[{Tag,IOPS,MSecs}|Bench]}]}.
-
-remove_all_handlers() ->
- #{handlers:=Hs} = logger:i(),
- [logger:remove_handler(Id) || {Id,_,_} <- Hs],
- Hs.
-
-add_all_handlers(Hs) ->
- [logger:add_handler(Id,Mod,Config) || {Id,Mod,Config} <- Hs],
- ok.
-
-%%%-----------------------------------------------------------------
-%%% Call logger in different ways
-do_log_func(Level,Msg) ->
- logger:Level(Msg,[],?meta).
-
-do_log_macro(error,Msg) ->
- ?LOG_ERROR(Msg,[]);
-do_log_macro(info,Msg) ->
- ?LOG_INFO(Msg,[]);
-do_log_macro(debug,Msg) ->
- ?LOG_DEBUG(Msg,[]).
-
-do_error_logger(error,Msg) ->
- error_logger:error_msg(Msg,[]);
-do_error_logger(info,Msg) ->
- error_logger:info_msg(Msg,[]).
-
-%%%-----------------------------------------------------------------
-%%%
-print_compare_chart(Group,Bench) ->
- io:format("~-20s~12s~12s~12s~12s",
- ["Microseconds:","Log","Drop","HDrop","Complete"]),
- io:format(user,"~-20s~12s~12s~12s~12s~n",
- ["Microseconds:","Log","Drop","HDrop","Complete"]),
- {Log,Drop,HDrop,Comp} = sort_bench(Bench,[],[],[],[]),
- print_compare_chart(Log,Drop,HDrop,Comp),
- io:format(user,"~n",[]),
- maybe_print_csv_files(Group,
- [{log,Log},{drop,Drop},{hdrop,HDrop},{comp,Comp}]).
-
-print_compare_chart([{What,LIOPS,LMSecs}|Log],
- [{What,DIOPS,DMSecs}|Drop],
- [{What,HIOPS,HMSecs}|HDrop],
- [{What,CIOPS,CMSecs}|Comp]) ->
- io:format("~-20w~12w~12w~12w~12w",[What,LMSecs,DMSecs,HMSecs,CMSecs]),
- io:format(user,"~-20w~12w~12w~12w~12w~n",[What,LMSecs,DMSecs,HMSecs,CMSecs]),
- print_compare_chart(Log,Drop,HDrop,Comp);
-print_compare_chart([{What,LIOPS,LMSecs}|Log],
- [{What,DIOPS,DMSecs}|Drop],
- [{What,HIOPS,HMSecs}|HDrop],
- []=Comp) ->
- io:format("~-20w~12w~12w~12w",[What,LMSecs,DMSecs,HMSecs]),
- io:format(user,"~-20w~12w~12w~12w~n",[What,LMSecs,DMSecs,HMSecs]),
- print_compare_chart(Log,Drop,HDrop,Comp);
-print_compare_chart([],[],[],[]) ->
- ok;
-print_compare_chart(Log,Drop,HDrop,Comp) ->
- ct:fail({Log,Drop,HDrop,Comp}).
-
-sort_bench([{TC,IOPS,MSecs}|Bench],Log,Drop,HDrop,Comp) ->
- case lists:member(TC,?NO_COMPARE) of
- true ->
- sort_bench(Bench,Log,Drop,HDrop,Comp);
- false ->
- TCStr = atom_to_list(TC),
- {What,Type} =
- case re:run(TCStr,"(.*)_(drop.*)",
- [{capture,all_but_first,list}]) of
- {match,[WhatStr,TypeStr]} ->
- {list_to_atom(WhatStr),list_to_atom(TypeStr)};
- nomatch ->
- case re:run(TCStr,"(.*)_(handler_complete.*)",
- [{capture,all_but_first,list}]) of
- {match,[WhatStr,TypeStr]} ->
- {list_to_atom(WhatStr),list_to_atom(TypeStr)};
- nomatch ->
- {TC,log}
- end
- end,
- case Type of
- log ->
- sort_bench(Bench,[{What,IOPS,MSecs}|Log],Drop,HDrop,Comp);
- drop ->
- sort_bench(Bench,Log,[{What,IOPS,MSecs}|Drop],HDrop,Comp);
- drop_by_handler ->
- sort_bench(Bench,Log,Drop,[{What,IOPS,MSecs}|HDrop],Comp);
- handler_complete ->
- sort_bench(Bench,Log,Drop,HDrop,[{What,IOPS,MSecs}|Comp])
- end
- end;
-sort_bench([],Log,Drop,HDrop,Comp) ->
- {lists:keysort(1,Log),
- lists:keysort(1,Drop),
- lists:keysort(1,HDrop),
- lists:keysort(1,Comp)}.
-
-maybe_print_csv_files(Group,Data) ->
- case ct:get_config({print_csv,Group}) of
- undefined ->
- ok;
- Cfg ->
- Path = proplists:get_value(path,Cfg,".."),
- Files = [begin
- File = filename:join(Path,F)++".csv",
- case filelib:is_regular(File) of
- true ->
- {ok,Fd} = file:open(File,[append]),
- Fd;
- false ->
- {ok,Fd} = file:open(File,[write]),
- ok = file:write(Fd,
- "error_logger,lager_log,"
- "lager_parsetrans,logger_log,"
- "logger_macro\n"),
- Fd
- end
- end || {F,_} <- Data],
- [print_csv_file(F,D) || {F,D} <- lists:zip(Files,Data)],
- [file:close(Fd) || Fd <- Files],
- ok
- end.
-
-print_csv_file(Fd,{_,Data}) ->
- AllIOPS = [integer_to_list(IOPS) || {_,IOPS,_} <- Data],
- ok = file:write(Fd,lists:join(",",AllIOPS)++"\n").
-
-have_lager() ->
- code:ensure_loaded(lager) == {module,lager}.
-
-make(Dir) ->
- {ok,Cwd} = file:get_cwd(),
- ok = file:set_cwd(Dir),
- up_to_date = make:all([load]),
- ok = file:set_cwd(Cwd),
- code:add_path(Dir).
diff --git a/lib/kernel/test/logger_bench_SUITE_data/Emakefile b/lib/kernel/test/logger_bench_SUITE_data/Emakefile
deleted file mode 100644
index 85c82bdaab..0000000000
--- a/lib/kernel/test/logger_bench_SUITE_data/Emakefile
+++ /dev/null
@@ -1 +0,0 @@
-{['lager_helper'],[{outdir,"."},debug_info,{i,"/home/uabshan/Work/git/otp/lib/kernel/src"},{i,"/home/uabshan/Work/git/otp/lib/kernel/include"}]}.
diff --git a/lib/kernel/test/logger_bench_SUITE_data/lager_helper.erl b/lib/kernel/test/logger_bench_SUITE_data/lager_helper.erl
deleted file mode 100644
index 296ced4276..0000000000
--- a/lib/kernel/test/logger_bench_SUITE_data/lager_helper.erl
+++ /dev/null
@@ -1,73 +0,0 @@
--module(lager_helper).
-
--compile(export_all).
--compile({parse_transform,lager_transform}).
-
--include_lib("kernel/src/logger_internal.hrl").
-
-start() ->
- application:load(lager),
- application:set_env(lager, error_logger_redirect, false),
- application:set_env(lager, async_threshold, 100010),
- application:set_env(lager, async_threshold_window, 100),
- application:set_env(lager,handlers,[{?MODULE,[{level,error}]}]),
- lager:start().
-
-stop() ->
- application:stop(lager).
-
-do_func(Level,Msg) ->
- lager:log(Level,[{pid,self()}],Msg,[]).
-
-do_parsetrans(error,Msg) ->
- lager:error(Msg,[]);
-do_parsetrans(info,Msg) ->
- lager:info(Msg,[]).
-
-%%%-----------------------------------------------------------------
-%%% Dummy handler for lager
--record(state, {level :: {'mask', integer()},
- formatter :: atom(),
- format_config :: any()}).
-init(Opts) ->
- Level = proplists:get_value(level,Opts,info),
- Formatter = proplists:get_value(formatter,Opts,logger_bench_SUITE),
- FormatConfig = proplists:get_value(format_config,Opts,?DEFAULT_FORMAT_CONFIG),
- {ok,#state{level=lager_util:config_to_mask(Level),
- formatter=Formatter,
- format_config=FormatConfig}}.
-
-handle_call(get_loglevel, #state{level=Level} = State) ->
- {ok, Level, State};
-handle_call({set_loglevel, Level}, State) ->
- try lager_util:config_to_mask(Level) of
- Levels ->
- {ok, ok, State#state{level=Levels}}
- catch
- _:_ ->
- {ok, {error, bad_log_level}, State}
- end;
-handle_call(_Request, State) ->
- {ok, ok, State}.
-
-handle_event({log, Message},
- #state{level=L,formatter=Formatter,format_config=FormatConfig} = State) ->
- case lager_util:is_loggable(Message, L, ?MODULE) of
- true ->
- Metadata =
- case maps:from_list(lager_msg:metadata(Message)) of
- Meta = #{pid:=Pid} when is_pid(Pid) ->
- Meta;
- Meta = #{pid:=PidStr} when is_list(PidStr) ->
- Meta
- end,
- Log = #{level=>lager_msg:severity(Message),
- msg=>{report,lager_msg:message(Message)},
- meta=>Metadata},
- io:put_chars(user, Formatter:format(Log,FormatConfig)),
- {ok, State};
- false ->
- {ok, State}
- end;
-handle_event(_Event, State) ->
- {ok, State}.
diff --git a/lib/kernel/test/logger_disk_log_h_SUITE.erl b/lib/kernel/test/logger_disk_log_h_SUITE.erl
index 7a1736c814..5f7b505ecb 100644
--- a/lib/kernel/test/logger_disk_log_h_SUITE.erl
+++ b/lib/kernel/test/logger_disk_log_h_SUITE.erl
@@ -82,7 +82,7 @@ all() ->
bad_input,
info_and_reset,
reconfig,
- disk_log_sync,
+ sync,
disk_log_full,
disk_log_wrap,
disk_log_events,
@@ -107,10 +107,10 @@ start_stop_handler(_Config) ->
ok = logger:add_handler(?MODULE, logger_disk_log_h, #{}),
{error,{already_exist,?MODULE}} =
logger:add_handler(?MODULE, logger_disk_log_h, #{}),
- true = is_pid(whereis(?MODULE)),
+ true = is_pid(whereis(h_proc_name())),
ok = logger:remove_handler(?MODULE),
timer:sleep(500),
- undefined = whereis(?MODULE).
+ undefined = whereis(h_proc_name()).
start_stop_handler(cleanup, _Config) ->
logger:remove_handler(?MODULE).
@@ -123,8 +123,8 @@ create_log(Config) ->
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}},
#{file=>LogFile1}),
- logger:info("hello", ?domain),
- logger_disk_log_h:disk_log_sync(Name1),
+ logger:notice("hello", ?domain),
+ logger_disk_log_h:sync(Name1),
ct:pal("Checking contents of ~p", [?log_no(LogFile1,1)]),
try_read_file(?log_no(LogFile1,1), {ok,<<"hello\n">>}, 5000),
@@ -136,8 +136,8 @@ create_log(Config) ->
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}},
#{file=>LogFile2}),
- logger:info("dummy", ?domain),
- logger_disk_log_h:disk_log_sync(Name2),
+ logger:notice("dummy", ?domain),
+ logger_disk_log_h:sync(Name2),
ct:pal("Checking contents of ~p", [?log_no(LogFile2,1)]),
try_read_file(?log_no(LogFile2,1), {ok,<<"dummy\n">>}, 5000),
@@ -157,22 +157,22 @@ open_existing_log(Config) ->
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}},
#{file=>LogFile1}),
- logger:info("one", ?domain),
- logger_disk_log_h:disk_log_sync(HName),
+ logger:notice("one", ?domain),
+ logger_disk_log_h:sync(HName),
ct:pal("Checking contents of ~p", [?log_no(LogFile1,1)]),
try_read_file(?log_no(LogFile1,1), {ok,<<"one\n">>}, 5000),
- logger:info("two", ?domain),
+ logger:notice("two", ?domain),
ok = remove_and_stop(HName),
try_read_file(?log_no(LogFile1,1), {ok,<<"one\ntwo\n">>}, 5000),
- logger:info("two and a half", ?domain),
+ logger:notice("two and a half", ?domain),
ok = start_and_add(HName, #{filter_default=>stop,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}},
#{file=>LogFile1}),
- logger:info("three", ?domain),
- logger_disk_log_h:disk_log_sync(HName),
+ logger:notice("three", ?domain),
+ logger_disk_log_h:sync(HName),
try_read_file(?log_no(LogFile1,1), {ok,<<"one\ntwo\nthree\n">>}, 5000),
remove_and_stop(HName),
try_read_file(?log_no(LogFile1,1), {ok,<<"one\ntwo\nthree\n">>}, 5000).
@@ -196,23 +196,23 @@ disk_log_opts(Config) ->
ct:log("Fullname = ~s", [WFileFull]),
{WFileFull,wrap,{Size,2},1} = {Get(file,WInfo1),Get(type,WInfo1),
Get(size,WInfo1),Get(current_file,WInfo1)},
- logger:info("123", ?domain),
- logger_disk_log_h:disk_log_sync(WName),
+ logger:notice("123", ?domain),
+ logger_disk_log_h:sync(WName),
timer:sleep(500),
1 = Get(current_file, disk_log:info(WName)),
- logger:info("45", ?domain),
- logger_disk_log_h:disk_log_sync(WName),
+ logger:notice("45", ?domain),
+ logger_disk_log_h:sync(WName),
timer:sleep(500),
1 = Get(current_file, disk_log:info(WName)),
- logger:info("6", ?domain),
- logger_disk_log_h:disk_log_sync(WName),
+ logger:notice("6", ?domain),
+ logger_disk_log_h:sync(WName),
timer:sleep(500),
2 = Get(current_file, disk_log:info(WName)),
- logger:info("7890", ?domain),
- logger_disk_log_h:disk_log_sync(WName),
+ logger:notice("7890", ?domain),
+ logger_disk_log_h:sync(WName),
timer:sleep(500),
2 = Get(current_file, disk_log:info(WName)),
@@ -229,8 +229,8 @@ disk_log_opts(Config) ->
ct:log("Fullname = ~s", [HFile1Full]),
{HFile1Full,halt,infinity} = {Get(file,HInfo1),Get(type,HInfo1),
Get(size,HInfo1)},
- logger:info("12345", ?domain),
- logger_disk_log_h:disk_log_sync(HName1),
+ logger:notice("12345", ?domain),
+ logger_disk_log_h:sync(HName1),
timer:sleep(500),
1 = Get(no_written_items, disk_log:info(HName1)),
@@ -253,17 +253,17 @@ disk_log_opts(Config) ->
default_formatter(Config) ->
PrivDir = ?config(priv_dir,Config),
LogFile = filename:join(PrivDir,atom_to_list(?FUNCTION_NAME)),
- HConfig = #{disk_log_opts => #{file=>LogFile},
- filter_default=>log},
+ HandlerConfig = #{config => #{file=>LogFile},
+ filter_default=>log},
ct:pal("Log: ~p", [LogFile]),
- ok = logger:add_handler(?MODULE, logger_disk_log_h, HConfig),
+ ok = logger:add_handler(?MODULE, logger_disk_log_h, HandlerConfig),
ok = logger:set_handler_config(?MODULE,formatter,
{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}),
LogName = lists:concat([LogFile, ".1"]),
- logger:info("dummy"),
+ logger:notice("dummy"),
wait_until_written(LogName),
{ok,Bin} = file:read_file(LogName),
- match = re:run(Bin, "=INFO REPORT====.*\ndummy", [{capture,none}]),
+ match = re:run(Bin, "=NOTICE REPORT====.*\ndummy", [{capture,none}]),
ok.
default_formatter(cleanup, _Config) ->
logger:remove_handler(?MODULE).
@@ -277,8 +277,8 @@ logging(Config) ->
formatter=>{?MODULE,self()}},
#{file => LogFile}),
MsgFormatter = fun(Term) -> {io_lib:format("Term:~p",[Term]),[]} end,
- logger:info([{x,y}], #{report_cb => MsgFormatter}),
- logger:info([{x,y}], #{}),
+ logger:notice([{x,y}], #{report_cb => MsgFormatter}),
+ logger:notice([{x,y}], #{}),
ct:pal("Checking contents of ~p", [?log_no(LogFile,1)]),
try_read_file(?log_no(LogFile,1), {ok,<<"Term:[{x,y}]\n x: y\n">>}, 5000).
@@ -290,10 +290,10 @@ errors(Config) ->
PrivDir = ?config(priv_dir,Config),
Name1 = list_to_atom(lists:concat([?FUNCTION_NAME,"_1"])),
LogFile1 = filename:join(PrivDir,Name1),
- HConfig = #{disk_log_opts=>#{file=>LogFile1},
- filter_default=>log,
- formatter=>{?MODULE,self()}},
- ok = logger:add_handler(Name1, logger_disk_log_h, HConfig),
+ HandlerConfig = #{config=>#{file=>LogFile1},
+ filter_default=>log,
+ formatter=>{?MODULE,self()}},
+ ok = logger:add_handler(Name1, logger_disk_log_h, HandlerConfig),
{error,{already_exist,Name1}} =
logger:add_handler(Name1, logger_disk_log_h, #{}),
@@ -302,7 +302,7 @@ errors(Config) ->
{error,{illegal_config_change,_,_}} =
logger:set_handler_config(Name1,
- disk_log_opts,
+ config,
#{file=>LogFile1,
type=>halt}),
{error,{illegal_config_change,_,_}} =
@@ -321,45 +321,42 @@ formatter_fail(Config) ->
Name = ?FUNCTION_NAME,
LogFile = filename:join(PrivDir,Name),
ct:pal("Log = ~p", [LogFile]),
- HConfig = #{disk_log_opts => #{file=>LogFile},
- filter_default=>stop,
- filters=>?DEFAULT_HANDLER_FILTERS([?MODULE])},
+ HandlerConfig = #{config => #{file=>LogFile},
+ filter_default=>stop,
+ filters=>?DEFAULT_HANDLER_FILTERS([?MODULE])},
%% no formatter!
- logger:add_handler(Name, logger_disk_log_h, HConfig),
- Pid = whereis(Name),
+ logger:add_handler(Name, logger_disk_log_h, HandlerConfig),
+ Pid = whereis(h_proc_name(Name)),
true = is_pid(Pid),
- #{handlers:=HC1} = logger:i(),
- H = [Id || {Id,_,_} <- HC1],
+ H = logger:get_handler_ids(),
true = lists:member(Name,H),
%% Formatter is added automatically
- {ok,{_,#{formatter:={logger_formatter,_}}}} =
- logger:get_handler_config(Name),
- logger:info(M1=?msg,?domain),
- Got1 = try_match_file(?log_no(LogFile,1),"[0-9\\+\\-T:\\.]* info: "++M1,5000),
+ {ok,#{formatter:={logger_formatter,_}}} = logger:get_handler_config(Name),
+ logger:notice(M1=?msg,?domain),
+ Got1 = try_match_file(?log_no(LogFile,1),"[0-9\\+\\-T:\\.]* notice: "++M1,5000),
ok = logger:set_handler_config(Name,formatter,{nonexistingmodule,#{}}),
- logger:info(M2=?msg,?domain),
+ logger:notice(M2=?msg,?domain),
Got2 = try_match_file(?log_no(LogFile,1),
- escape(Got1)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M2,
+ escape(Got1)++"[0-9\\+\\-T:\\.]* notice: FORMATTER CRASH: .*"++M2,
5000),
ok = logger:set_handler_config(Name,formatter,{?MODULE,crash}),
- logger:info(M3=?msg,?domain),
+ logger:notice(M3=?msg,?domain),
Got3 = try_match_file(?log_no(LogFile,1),
- escape(Got2)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M3,
+ escape(Got2)++"[0-9\\+\\-T:\\.]* notice: FORMATTER CRASH: .*"++M3,
5000),
ok = logger:set_handler_config(Name,formatter,{?MODULE,bad_return}),
- logger:info(?msg,?domain),
+ logger:notice(?msg,?domain),
try_match_file(?log_no(LogFile,1),
escape(Got3)++"FORMATTER ERROR: bad_return_value",
5000),
%% Check that handler is still alive and was never dead
- Pid = whereis(Name),
- #{handlers:=HC2} = logger:i(),
- H = [Id || {Id,_,_} <- HC2],
+ Pid = whereis(h_proc_name(Name)),
+ H = logger:get_handler_ids(),
ok.
formatter_fail(cleanup,_Config) ->
@@ -369,48 +366,49 @@ formatter_fail(cleanup,_Config) ->
config_fail(_Config) ->
{error,{handler_not_added,{invalid_config,logger_disk_log_h,{bad,bad}}}} =
logger:add_handler(?MODULE,logger_disk_log_h,
- #{logger_disk_log_h => #{bad => bad},
+ #{config => #{bad => bad},
filter_default=>log,
formatter=>{?MODULE,self()}}),
{error,{handler_not_added,{invalid_levels,{_,1,_}}}} =
logger:add_handler(?MODULE,logger_disk_log_h,
- #{logger_disk_log_h => #{drop_new_reqs_qlen=>1}}),
+ #{config => #{drop_mode_qlen=>1}}),
{error,{handler_not_added,{invalid_levels,{43,42,_}}}} =
logger:add_handler(?MODULE,logger_disk_log_h,
- #{logger_disk_log_h => #{toggle_sync_qlen=>43,
- drop_new_reqs_qlen=>42}}),
+ #{config => #{sync_mode_qlen=>43,
+ drop_mode_qlen=>42}}),
{error,{handler_not_added,{invalid_levels,{_,43,42}}}} =
logger:add_handler(?MODULE,logger_disk_log_h,
- #{logger_disk_log_h => #{drop_new_reqs_qlen=>43,
- flush_reqs_qlen=>42}}),
+ #{config => #{drop_mode_qlen=>43,
+ flush_qlen=>42}}),
ok = logger:add_handler(?MODULE,logger_disk_log_h,
#{filter_default=>log,
formatter=>{?MODULE,self()}}),
%% can't change the disk log options for a log already in use
{error,{illegal_config_change,_,_}} =
- logger:set_handler_config(?MODULE,disk_log_opts,
+ logger:set_handler_config(?MODULE,config,
#{max_no_files=>2}),
%% can't change name of an existing handler
{error,{illegal_config_change,_,_}} =
logger:set_handler_config(?MODULE,id,bad),
- %% incorrect values of OP params
+ %% incorrect values of OP params
+ {ok,#{config := HConfig}} = logger:get_handler_config(?MODULE),
{error,{invalid_levels,_}} =
- logger:set_handler_config(?MODULE,logger_disk_log_h,
- #{toggle_sync_qlen=>100,
- flush_reqs_qlen=>99}),
+ logger:set_handler_config(?MODULE,config,
+ HConfig#{sync_mode_qlen=>100,
+ flush_qlen=>99}),
%% invalid name of config parameter
{error,{invalid_config,logger_disk_log_h,{filesync_rep_int,2000}}} =
- logger:set_handler_config(?MODULE, logger_disk_log_h,
- #{filesync_rep_int => 2000}),
+ logger:set_handler_config(?MODULE, config,
+ HConfig#{filesync_rep_int => 2000}),
ok.
config_fail(cleanup,_Config) ->
logger:remove_handler(?MODULE).
bad_input(_Config) ->
- {error,{badarg,{disk_log_sync,["BadType"]}}} =
- logger_disk_log_h:disk_log_sync("BadType"),
+ {error,{badarg,{sync,["BadType"]}}} =
+ logger_disk_log_h:sync("BadType"),
{error,{badarg,{info,["BadType"]}}} = logger_disk_log_h:info("BadType"),
{error,{badarg,{reset,["BadType"]}}} = logger_disk_log_h:reset("BadType").
@@ -431,16 +429,16 @@ reconfig(Config) ->
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}}),
#{id := ?MODULE,
- toggle_sync_qlen := ?TOGGLE_SYNC_QLEN,
- drop_new_reqs_qlen := ?DROP_NEW_REQS_QLEN,
- flush_reqs_qlen := ?FLUSH_REQS_QLEN,
- enable_burst_limit := ?ENABLE_BURST_LIMIT,
- burst_limit_size := ?BURST_LIMIT_SIZE,
- burst_window_time := ?BURST_WINDOW_TIME,
- enable_kill_overloaded := ?ENABLE_KILL_OVERLOADED,
- handler_overloaded_qlen := ?HANDLER_OVERLOADED_QLEN,
- handler_overloaded_mem := ?HANDLER_OVERLOADED_MEM,
- handler_restart_after := ?HANDLER_RESTART_AFTER,
+ sync_mode_qlen := ?SYNC_MODE_QLEN,
+ drop_mode_qlen := ?DROP_MODE_QLEN,
+ flush_qlen := ?FLUSH_QLEN,
+ burst_limit_enable := ?BURST_LIMIT_ENABLE,
+ burst_limit_max_count := ?BURST_LIMIT_MAX_COUNT,
+ burst_limit_window_time := ?BURST_LIMIT_WINDOW_TIME,
+ overload_kill_enable := ?OVERLOAD_KILL_ENABLE,
+ overload_kill_qlen := ?OVERLOAD_KILL_QLEN,
+ overload_kill_mem_size := ?OVERLOAD_KILL_MEM_SIZE,
+ overload_kill_restart_after := ?OVERLOAD_KILL_RESTART_AFTER,
filesync_repeat_interval := ?FILESYNC_REPEAT_INTERVAL,
log_opts := #{type := ?DISK_LOG_TYPE,
max_no_files := ?DISK_LOG_MAX_NO_FILES,
@@ -448,29 +446,30 @@ reconfig(Config) ->
file := _DiskLogFile}} =
logger_disk_log_h:info(?MODULE),
- ok = logger:set_handler_config(?MODULE, logger_disk_log_h,
- #{toggle_sync_qlen => 1,
- drop_new_reqs_qlen => 2,
- flush_reqs_qlen => 3,
- enable_burst_limit => false,
- burst_limit_size => 10,
- burst_window_time => 10,
- enable_kill_overloaded => true,
- handler_overloaded_qlen => 100000,
- handler_overloaded_mem => 10000000,
- handler_restart_after => never,
- filesync_repeat_interval => no_repeat}),
+ {ok,#{config := HConfig0}} = logger:get_handler_config(?MODULE),
+ HConfig1 = HConfig0#{sync_mode_qlen => 1,
+ drop_mode_qlen => 2,
+ flush_qlen => 3,
+ burst_limit_enable => false,
+ burst_limit_max_count => 10,
+ burst_limit_window_time => 10,
+ overload_kill_enable => true,
+ overload_kill_qlen => 100000,
+ overload_kill_mem_size => 10000000,
+ overload_kill_restart_after => never,
+ filesync_repeat_interval => no_repeat},
+ ok = logger:set_handler_config(?MODULE, config, HConfig1),
#{id := ?MODULE,
- toggle_sync_qlen := 1,
- drop_new_reqs_qlen := 2,
- flush_reqs_qlen := 3,
- enable_burst_limit := false,
- burst_limit_size := 10,
- burst_window_time := 10,
- enable_kill_overloaded := true,
- handler_overloaded_qlen := 100000,
- handler_overloaded_mem := 10000000,
- handler_restart_after := never,
+ sync_mode_qlen := 1,
+ drop_mode_qlen := 2,
+ flush_qlen := 3,
+ burst_limit_enable := false,
+ burst_limit_max_count := 10,
+ burst_limit_window_time := 10,
+ overload_kill_enable := true,
+ overload_kill_qlen := 100000,
+ overload_kill_mem_size := 10000000,
+ overload_kill_restart_after := never,
filesync_repeat_interval := no_repeat} =
logger_disk_log_h:info(?MODULE),
@@ -482,7 +481,7 @@ reconfig(Config) ->
#{filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()},
- disk_log_opts=>
+ config=>
#{type => halt,
max_no_files => 1,
max_no_bytes => 1024,
@@ -497,13 +496,13 @@ reconfig(Config) ->
reconfig(cleanup, _Config) ->
logger:remove_handler(?MODULE).
-disk_log_sync(Config) ->
+sync(Config) ->
Dir = ?config(priv_dir,Config),
File = filename:join(Dir, ?FUNCTION_NAME),
Log = lists:concat([File,".1"]),
ok = logger:add_handler(?MODULE,
logger_disk_log_h,
- #{disk_log_opts => #{file => File},
+ #{config => #{file => File},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,nl}}),
@@ -513,7 +512,7 @@ disk_log_sync(Config) ->
[{disk_log,blog,<<"first\n">>},
{disk_log,sync}]),
- logger:info("first", ?domain),
+ logger:notice("first", ?domain),
%% wait for automatic disk_log_sync
check_tracer(?FILESYNC_REPEAT_INTERVAL*2),
@@ -524,16 +523,18 @@ disk_log_sync(Config) ->
{disk_log,sync}]),
%% two log requests in fast succession will make the handler skip
%% an automatic disk log sync
- logger:info("second", ?domain),
- logger:info("third", ?domain),
- %% do explicit disk_log_sync
- logger_disk_log_h:disk_log_sync(?MODULE),
+ logger:notice("second", ?domain),
+ logger:notice("third", ?domain),
+ %% do explicit sync
+ logger_disk_log_h:sync(?MODULE),
check_tracer(100),
%% check that if there's no repeated disk_log_sync active,
%% a disk_log_sync is still performed when handler goes idle
- logger:set_handler_config(?MODULE, logger_disk_log_h,
- #{filesync_repeat_interval => no_repeat}),
+ {ok,#{config := HConfig}} = logger:get_handler_config(?MODULE),
+ HConfig1 = HConfig#{filesync_repeat_interval => no_repeat},
+ ok = logger:set_handler_config(?MODULE, config, HConfig1),
+
no_repeat = maps:get(filesync_repeat_interval,
logger_disk_log_h:info(?MODULE)),
@@ -543,9 +544,9 @@ disk_log_sync(Config) ->
{disk_log,blog,<<"fifth\n">>},
{disk_log,sync}]),
- logger:info("fourth", ?domain),
+ logger:notice("fourth", ?domain),
timer:sleep(?IDLE_DETECT_TIME_MSEC*2),
- logger:info("fifth", ?domain),
+ logger:notice("fifth", ?domain),
%% wait for automatic disk_log_sync
check_tracer(?IDLE_DETECT_TIME_MSEC*2),
@@ -559,16 +560,17 @@ disk_log_sync(Config) ->
start_tracer([{logger_disk_log_h,handle_cast,2}],
[OneSync || _ <- lists:seq(1, 1 + trunc(WaitT/SyncInt))]),
- logger:set_handler_config(?MODULE, logger_disk_log_h,
- #{filesync_repeat_interval => SyncInt}),
+ HConfig2 = HConfig#{filesync_repeat_interval => SyncInt},
+ ok = logger:set_handler_config(?MODULE, config, HConfig2),
+
SyncInt = maps:get(filesync_repeat_interval,
logger_disk_log_h:info(?MODULE)),
timer:sleep(WaitT),
- logger:set_handler_config(?MODULE, logger_disk_log_h,
- #{filesync_repeat_interval => no_repeat}),
+ HConfig3 = HConfig#{filesync_repeat_interval => no_repeat},
+ ok = logger:set_handler_config(?MODULE, config, HConfig3),
check_tracer(100),
ok.
-disk_log_sync(cleanup,_Config) ->
+sync(cleanup,_Config) ->
dbg:stop_clear(),
logger:remove_handler(?MODULE).
@@ -584,7 +586,7 @@ disk_log_wrap(Config) ->
#{filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()},
- disk_log_opts=>
+ config=>
#{type => wrap,
max_no_files => MaxFiles,
max_no_bytes => MaxBytes,
@@ -598,7 +600,7 @@ disk_log_wrap(Config) ->
Pid
end,
{ok,_} = dbg:tracer(process, {TraceFun, Tester}),
- {ok,_} = dbg:p(whereis(?MODULE), [c]),
+ {ok,_} = dbg:p(whereis(h_proc_name()), [c]),
{ok,_} = dbg:tp(logger_disk_log_h, handle_info, 2, []),
Text = [34 + rand:uniform(126-34) || _ <- lists:seq(1,MaxBytes)],
@@ -606,7 +608,7 @@ disk_log_wrap(Config) ->
%% fill first file
lists:foreach(fun(N) ->
Log = lists:concat([File,".",N]),
- logger:info(Text, ?domain),
+ logger:notice(Text, ?domain),
wait_until_written(Log),
ct:pal("N = ~w",
[N = Get(current_file,
@@ -640,7 +642,7 @@ disk_log_full(Config) ->
#{filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()},
- disk_log_opts=>
+ config=>
#{type => halt,
max_no_files => 1,
max_no_bytes => MaxBytes,
@@ -652,12 +654,12 @@ disk_log_full(Config) ->
Pid
end,
{ok,_} = dbg:tracer(process, {TraceFun, Tester}),
- {ok,_} = dbg:p(whereis(?MODULE), [c]),
+ {ok,_} = dbg:p(whereis(h_proc_name()), [c]),
{ok,_} = dbg:tp(logger_disk_log_h, handle_info, 2, []),
NoOfChars = 5,
Text = [34 + rand:uniform(126-34) || _ <- lists:seq(1,NoOfChars)],
- [logger:info(Text, ?domain) || _ <- lists:seq(1,trunc(MaxBytes/NoOfChars)+1)],
+ [logger:notice(Text, ?domain) || _ <- lists:seq(1,trunc(MaxBytes/NoOfChars)+1)],
%% wait for trace messages
timer:sleep(2000),
@@ -701,10 +703,10 @@ disk_log_events(Config) ->
Pid
end,
{ok,_} = dbg:tracer(process, {TraceFun, Tester}),
- {ok,_} = dbg:p(whereis(?MODULE), [c]),
+ {ok,_} = dbg:p(whereis(h_proc_name()), [c]),
{ok,_} = dbg:tp(logger_disk_log_h, handle_info, 2, []),
- [whereis(?MODULE) ! E || E <- Events],
+ [whereis(h_proc_name()) ! E || E <- Events],
%% wait for trace messages
timer:sleep(2000),
dbg:stop_clear(),
@@ -737,7 +739,7 @@ write_failure(Config) ->
ct:pal("LogOpts = ~p", [LogOpts = maps:get(log_opts, HState)]),
ok = log_on_remote_node(Node, "Logged1"),
- rpc:call(Node, logger_disk_log_h, disk_log_sync, [?STANDARD_HANDLER]),
+ rpc:call(Node, logger_disk_log_h, sync, [?STANDARD_HANDLER]),
?check_no_log,
try_read_file(Log, {ok,<<"Logged1\n">>}, ?SYNC_REP_INT),
@@ -757,7 +759,7 @@ write_failure(Config) ->
rpc:call(Node, ?MODULE, set_result, [disk_log_blog,ok]),
ok = log_on_remote_node(Node, "Logged2"),
- rpc:call(Node, logger_disk_log_h, disk_log_sync, [?STANDARD_HANDLER]),
+ rpc:call(Node, logger_disk_log_h, sync, [?STANDARD_HANDLER]),
?check_no_log,
try_read_file(Log, {ok,<<"Logged1\nLogged2\n">>}, ?SYNC_REP_INT),
ok.
@@ -782,7 +784,7 @@ sync_failure(Config) ->
SyncInt = 500,
ok = rpc:call(Node, logger, set_handler_config,
- [?STANDARD_HANDLER, logger_disk_log_h,
+ [?STANDARD_HANDLER, config,
#{filesync_repeat_interval => SyncInt}]),
Info = rpc:call(Node, logger_disk_log_h, info, [?STANDARD_HANDLER]),
SyncInt = maps:get(filesync_repeat_interval, Info),
@@ -817,7 +819,7 @@ start_h_on_new_node(Config, File) ->
logger_test_lib:setup(
Config,
[{logger,[{handler,default,logger_disk_log_h,
- #{ disk_log_opts => #{ file => File }}}]}]),
+ #{ config => #{ file => File }}}]}]),
ok = rpc:call(Node,logger,set_handler_config,[?STANDARD_HANDLER,formatter,
{?MODULE,nl}]),
Node.
@@ -825,7 +827,7 @@ start_h_on_new_node(Config, File) ->
log_on_remote_node(Node,Msg) ->
_ = spawn_link(Node,
fun() -> erlang:group_leader(whereis(user),self()),
- logger:info(Msg)
+ logger:notice(Msg)
end),
ok.
@@ -852,14 +854,14 @@ op_switch_to_sync(Config) ->
{Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NumOfReqs = 500,
NewHConfig =
- HConfig#{logger_disk_log_h => DLHConfig#{toggle_sync_qlen => 2,
- drop_new_reqs_qlen => NumOfReqs+1,
- flush_reqs_qlen => 2*NumOfReqs,
- enable_burst_limit => false}},
+ HConfig#{config => DLHConfig#{sync_mode_qlen => 2,
+ drop_mode_qlen => NumOfReqs+1,
+ flush_qlen => 2*NumOfReqs,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Lines = count_lines(Log),
- ok = file:delete(Log),
+ ok = file_delete(Log),
NumOfReqs = Lines,
ok.
op_switch_to_sync(cleanup, _Config) ->
@@ -876,21 +878,21 @@ op_switch_to_drop(Config) ->
Procs = 2,
Bursts = 10,
NewHConfig =
- HConfig#{logger_disk_log_h =>
- DLHConfig#{toggle_sync_qlen => 1,
- drop_new_reqs_qlen => 2,
- flush_reqs_qlen => Procs*NumOfReqs*Bursts,
- enable_burst_limit => false}},
+ HConfig#{config =>
+ DLHConfig#{sync_mode_qlen => 1,
+ drop_mode_qlen => 2,
+ flush_qlen => Procs*NumOfReqs*Bursts,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
%% It sometimes happens that the handler either gets
%% the requests in a slow enough pace so that dropping
%% never occurs. Therefore, lets generate a number of
%% bursts to increase the chance of message buildup.
- [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info) ||
+ [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice) ||
_ <- lists:seq(1, Bursts)],
Logged = count_lines(Log),
- ok= stop_handler(?MODULE),
- _ = file:delete(Log),
+ ok = stop_handler(?MODULE),
+ _ = file_delete(Log),
ct:pal("Number of messages dropped = ~w (~w)",
[Procs*NumOfReqs*Bursts-Logged,Procs*NumOfReqs*Bursts]),
true = (Logged < (Procs*NumOfReqs*Bursts)),
@@ -921,12 +923,12 @@ op_switch_to_flush(Config) ->
%% (verify with coverage of flush_log_requests/2)
NewHConfig =
- HConfig#{logger_disk_log_h =>
- DLHConfig#{toggle_sync_qlen => 2,
+ HConfig#{config =>
+ DLHConfig#{sync_mode_qlen => 2,
%% disable drop mode
- drop_new_reqs_qlen => 300,
- flush_reqs_qlen => 300,
- enable_burst_limit => false}},
+ drop_mode_qlen => 300,
+ flush_qlen => 300,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 1500,
Procs = 10,
@@ -938,11 +940,11 @@ op_switch_to_flush(Config) ->
%% sync messages gets tested). Therefore, lets
%% generate a number of bursts to increase the chance
%% of message buildup in some random fashion.
- [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info) ||
+ [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice) ||
_ <- lists:seq(1,Bursts)],
Logged = count_lines(Log),
ok= stop_handler(?MODULE),
- _ = file:delete(Log),
+ _ = file_delete(Log),
ct:pal("Number of messages flushed/dropped = ~w (~w)",
[NumOfReqs*Procs*Bursts-Logged,NumOfReqs*Procs*Bursts]),
true = (Logged < (NumOfReqs*Procs*Bursts)),
@@ -964,17 +966,17 @@ op_switch_to_flush(cleanup, _Config) ->
limit_burst_disabled(Config) ->
{Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig =
- HConfig#{logger_disk_log_h => DLHConfig#{enable_burst_limit => false,
- burst_limit_size => 10,
- burst_window_time => 2000,
- drop_new_reqs_qlen => 200,
- flush_reqs_qlen => 300}},
+ HConfig#{config => DLHConfig#{burst_limit_enable => false,
+ burst_limit_max_count => 10,
+ burst_limit_window_time => 2000,
+ drop_mode_qlen => 200,
+ flush_qlen => 300}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 100,
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages logged = ~w", [Logged]),
- ok = file:delete(Log),
+ ok = file_delete(Log),
NumOfReqs = Logged.
limit_burst_disabled(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -983,17 +985,17 @@ limit_burst_enabled_one(Config) ->
{Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
ReqLimit = 10,
NewHConfig =
- HConfig#{logger_disk_log_h => DLHConfig#{enable_burst_limit => true,
- burst_limit_size => ReqLimit,
- burst_window_time => 2000,
- drop_new_reqs_qlen => 200,
- flush_reqs_qlen => 300}},
+ HConfig#{config => DLHConfig#{burst_limit_enable => true,
+ burst_limit_max_count => ReqLimit,
+ burst_limit_window_time => 2000,
+ drop_mode_qlen => 200,
+ flush_qlen => 300}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 100,
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages logged = ~w", [Logged]),
- ok = file:delete(Log),
+ ok = file_delete(Log),
ReqLimit = Logged.
limit_burst_enabled_one(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -1003,19 +1005,19 @@ limit_burst_enabled_period(Config) ->
ReqLimit = 10,
BurstTWin = 1000,
NewHConfig =
- HConfig#{logger_disk_log_h => DLHConfig#{enable_burst_limit => true,
- burst_limit_size => ReqLimit,
- burst_window_time => BurstTWin,
- drop_new_reqs_qlen => 20000,
- flush_reqs_qlen => 20001}},
+ HConfig#{config => DLHConfig#{burst_limit_enable => true,
+ burst_limit_max_count => ReqLimit,
+ burst_limit_window_time => BurstTWin,
+ drop_mode_qlen => 20000,
+ flush_qlen => 20001}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
Windows = 3,
- Sent = send_burst({t,BurstTWin*Windows}, seq, {chars,79}, info),
+ Sent = send_burst({t,BurstTWin*Windows}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages sent = ~w~nNumber of messages logged = ~w",
[Sent,Logged]),
- ok = file:delete(Log),
+ ok = file_delete(Log),
true = (Logged > (ReqLimit*Windows)) andalso
(Logged < (ReqLimit*(Windows+2))).
limit_burst_enabled_period(cleanup, _Config) ->
@@ -1024,37 +1026,37 @@ limit_burst_enabled_period(cleanup, _Config) ->
kill_disabled(Config) ->
{Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig =
- HConfig#{logger_disk_log_h=>DLHConfig#{enable_kill_overloaded=>false,
- handler_overloaded_qlen=>10,
- handler_overloaded_mem=>100}},
+ HConfig#{config=>DLHConfig#{overload_kill_enable=>false,
+ overload_kill_qlen=>10,
+ overload_kill_mem_size=>100}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 100,
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages logged = ~w", [Logged]),
- ok = file:delete(Log),
- true = is_pid(whereis(?MODULE)),
+ ok = file_delete(Log),
+ true = is_pid(whereis(h_proc_name())),
ok.
kill_disabled(cleanup, _Config) ->
ok = stop_handler(?MODULE).
qlen_kill_new(Config) ->
{_Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
- Pid0 = whereis(?MODULE),
+ Pid0 = whereis(h_proc_name()),
{_,Mem0} = process_info(Pid0, memory),
- RestartAfter = ?HANDLER_RESTART_AFTER,
+ RestartAfter = ?OVERLOAD_KILL_RESTART_AFTER,
NewHConfig =
- HConfig#{logger_disk_log_h =>
- DLHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>10,
- handler_overloaded_mem=>Mem0+50000,
- handler_restart_after=>RestartAfter}},
+ HConfig#{config =>
+ DLHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>10,
+ overload_kill_mem_size=>Mem0+50000,
+ overload_kill_restart_after=>RestartAfter}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
MRef = erlang:monitor(process, Pid0),
NumOfReqs = 100,
Procs = 2,
- send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info),
- %% send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice),
+ %% send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
receive
{'DOWN', MRef, _, _, Info} ->
case Info of
@@ -1064,7 +1066,7 @@ qlen_kill_new(Config) ->
ct:pal("Slow shutdown, handler process was killed!", [])
end,
timer:sleep(RestartAfter + 2000),
- true = is_pid(whereis(?MODULE)),
+ true = is_pid(whereis(h_proc_name())),
ok
after
5000 ->
@@ -1077,21 +1079,21 @@ qlen_kill_new(cleanup, _Config) ->
mem_kill_new(Config) ->
{_Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
- Pid0 = whereis(?MODULE),
+ Pid0 = whereis(h_proc_name()),
{_,Mem0} = process_info(Pid0, memory),
- RestartAfter = ?HANDLER_RESTART_AFTER,
+ RestartAfter = ?OVERLOAD_KILL_RESTART_AFTER,
NewHConfig =
- HConfig#{logger_disk_log_h =>
- DLHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>50000,
- handler_overloaded_mem=>Mem0+500,
- handler_restart_after=>RestartAfter}},
+ HConfig#{config =>
+ DLHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>50000,
+ overload_kill_mem_size=>Mem0+500,
+ overload_kill_restart_after=>RestartAfter}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
MRef = erlang:monitor(process, Pid0),
NumOfReqs = 100,
Procs = 2,
- send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info),
- %% send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice),
+ %% send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
receive
{'DOWN', MRef, _, _, Info} ->
case Info of
@@ -1101,7 +1103,7 @@ mem_kill_new(Config) ->
ct:pal("Slow shutdown, handler process was killed!", [])
end,
timer:sleep(RestartAfter + 2000),
- true = is_pid(whereis(?MODULE)),
+ true = is_pid(whereis(h_proc_name())),
ok
after
5000 ->
@@ -1115,17 +1117,17 @@ mem_kill_new(cleanup, _Config) ->
restart_after(Config) ->
{Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig1 =
- HConfig#{logger_disk_log_h=>DLHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>10,
- handler_restart_after=>never}},
+ HConfig#{config=>DLHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>10,
+ overload_kill_restart_after=>never}},
ok = logger:set_handler_config(?MODULE, NewHConfig1),
- MRef1 = erlang:monitor(process, whereis(?MODULE)),
+ MRef1 = erlang:monitor(process, whereis(h_proc_name())),
%% kill handler
- send_burst({n,100}, {spawn,2,0}, {chars,79}, info),
+ send_burst({n,100}, {spawn,2,0}, {chars,79}, notice),
receive
{'DOWN', MRef1, _, _, _Info1} ->
- timer:sleep(?HANDLER_RESTART_AFTER + 1000),
- undefined = whereis(?MODULE),
+ timer:sleep(?OVERLOAD_KILL_RESTART_AFTER + 1000),
+ undefined = whereis(h_proc_name()),
ok
after
5000 ->
@@ -1133,20 +1135,20 @@ restart_after(Config) ->
end,
{Log,_,_} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
- RestartAfter = ?HANDLER_RESTART_AFTER,
+ RestartAfter = ?OVERLOAD_KILL_RESTART_AFTER,
NewHConfig2 =
- HConfig#{logger_disk_log_h=>DLHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>10,
- handler_restart_after=>RestartAfter}},
+ HConfig#{config=>DLHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>10,
+ overload_kill_restart_after=>RestartAfter}},
ok = logger:set_handler_config(?MODULE, NewHConfig2),
- Pid0 = whereis(?MODULE),
+ Pid0 = whereis(h_proc_name()),
MRef2 = erlang:monitor(process, Pid0),
%% kill handler
- send_burst({n,100}, {spawn,2,0}, {chars,79}, info),
+ send_burst({n,100}, {spawn,2,0}, {chars,79}, notice),
receive
{'DOWN', MRef2, _, _, _Info2} ->
timer:sleep(RestartAfter + 2000),
- Pid1 = whereis(?MODULE),
+ Pid1 = whereis(h_proc_name()),
true = is_pid(Pid1),
false = (Pid1 == Pid0),
ok
@@ -1158,7 +1160,7 @@ restart_after(Config) ->
restart_after(cleanup, _Config) ->
ok = stop_handler(?MODULE).
-%% send handler requests (filesync, info, reset, change_config)
+%% send handler requests (sync, info, reset, change_config)
%% during high load to verify that sync, dropping and flushing is
%% handled correctly.
handler_requests_under_load() ->
@@ -1166,18 +1168,18 @@ handler_requests_under_load() ->
handler_requests_under_load(Config) ->
{Log,HConfig,DLHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig =
- HConfig#{logger_disk_log_h => DLHConfig#{toggle_sync_qlen => 2,
- drop_new_reqs_qlen => 1000,
- flush_reqs_qlen => 2000,
- enable_burst_limit => false}},
+ HConfig#{config => DLHConfig#{sync_mode_qlen => 2,
+ drop_mode_qlen => 1000,
+ flush_qlen => 2000,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
- Pid = spawn_link(fun() -> send_requests(?MODULE, 1, [{disk_log_sync,[]},
+ Pid = spawn_link(fun() -> send_requests(?MODULE, 1, [{sync,[]},
{info,[]},
{reset,[]},
{change_config,[]}])
end),
Procs = 100,
- Sent = Procs * send_burst({n,5000}, {spawn,Procs,10}, {chars,79}, info),
+ Sent = Procs * send_burst({n,5000}, {spawn,Procs,10}, {chars,79}, notice),
Pid ! {self(),finish},
ReqResult = receive {Pid,Result} -> Result end,
Logged = count_lines(Log),
@@ -1190,7 +1192,7 @@ handler_requests_under_load(Config) ->
Errors = [{Req,FindError(Res)} || {Req,Res} <- ReqResult],
NoOfReqs = lists:foldl(fun({_,Res}, N) -> N + length(Res) end, 0, ReqResult),
ct:pal("~w requests made. Errors: ~n~p", [NoOfReqs,Errors]),
- ok = file:delete(Log).
+ ok = file_delete(Log).
handler_requests_under_load(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -1204,7 +1206,7 @@ send_requests(HName, TO, Reqs = [{Req,Res}|Rs]) ->
case Req of
change_config ->
logger:set_handler_config(HName, logger_disk_log_h,
- #{enable_kill_overloaded =>
+ #{overload_kill_enable =>
false});
Func ->
logger_disk_log_h:Func(HName)
@@ -1220,19 +1222,18 @@ start_handler(Name, FuncName, Config) ->
ct:pal("Logging to ~tp", [File]),
ok = logger:add_handler(Name,
logger_disk_log_h,
- #{disk_log_opts=>#{file => File,
- max_no_files => 1,
- max_no_bytes => 100000000},
+ #{config=>#{file => File,
+ max_no_files => 1,
+ max_no_bytes => 100000000},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([Name]),
formatter=>{?MODULE,op}}),
- {ok,{_,HConfig = #{logger_disk_log_h := DLHConfig}}} =
- logger:get_handler_config(Name),
+ {ok,HConfig = #{config := DLHConfig}} = logger:get_handler_config(Name),
{lists:concat([File,".1"]),HConfig,DLHConfig}.
stop_handler(Name) ->
- ok = logger:remove_handler(Name),
- ct:pal("Handler ~p stopped!", [Name]).
+ ct:pal("Stopping handler ~p!", [Name]),
+ logger:remove_handler(Name).
send_burst(NorT, Type, {chars,Sz}, Class) ->
Text = [34 + rand:uniform(126-34) || _ <- lists:seq(1,Sz)],
@@ -1304,9 +1305,11 @@ format(#{msg:={report,#{label:={gen_server,terminate}}}},op) ->
"";
format(#{msg:={report,#{label:={proc_lib,crash}}}},op) ->
"";
-format(#{msg:={F,A}},Pid) when is_list(F), is_list(A) ->
+format(#{msg:={F,A}},OpOrPid) when is_list(F), is_list(A) ->
String = lists:flatten(io_lib:format(F,A)),
- Pid ! {log,String},
+ if is_pid(OpOrPid) -> OpOrPid ! {log,String};
+ true -> ok
+ end,
String++"\n";
format(#{msg:={string,String0}},Pid) ->
String = unicode:characters_to_list(String0),
@@ -1322,16 +1325,17 @@ remove(Handler, LogName) ->
HState = #{log_names := Logs} = logger_disk_log_h:info(),
false = maps:is_key(LogName, HState),
false = lists:member(LogName, Logs),
- false = logger_config:exist(logger, LogName),
+ false = logger_config:exist(?LOGGER_TABLE, LogName),
{error,no_such_log} = disk_log:info(LogName),
ok.
start_and_add(Name, Config, LogOpts) ->
- ct:pal("Adding handler ~w with: ~p",
- [Name,Config#{disk_log_opts=>LogOpts}]),
- ok = logger:add_handler(Name, logger_disk_log_h,
- Config#{disk_log_opts=>LogOpts}),
- Pid = whereis(Name),
+ HConfig = maps:get(config, Config, #{}),
+ HConfig1 = maps:merge(HConfig, LogOpts),
+ Config1 = Config#{config=>HConfig1},
+ ct:pal("Adding handler ~w with: ~p", [Name,Config1]),
+ ok = logger:add_handler(Name, logger_disk_log_h, Config1),
+ Pid = whereis(h_proc_name(Name)),
true = is_pid(Pid),
Name = proplists:get_value(name, disk_log:info(Name)),
ok.
@@ -1339,7 +1343,7 @@ start_and_add(Name, Config, LogOpts) ->
remove_and_stop(Handler) ->
ok = logger:remove_handler(Handler),
timer:sleep(500),
- undefined = whereis(Handler),
+ undefined = whereis(h_proc_name(Handler)),
ok.
try_read_file(FileName, Expected, Time) ->
@@ -1405,17 +1409,21 @@ wait_until_written(File, Sz) ->
end.
count_lines1(File) ->
- Counter = fun Cnt(Dev,LC) ->
- case file:read_line(Dev) of
- eof -> LC;
- _ -> Cnt(Dev,LC+1)
- end
- end,
{_,Dev} = file:open(File, [read]),
- Lines = Counter(Dev, 0),
+ Lines = count_lines2(Dev, 0),
file:close(Dev),
Lines.
+count_lines2(Dev, LC) ->
+ case file:read_line(Dev) of
+ {ok,"Handler logger_disk_log_h_SUITE " ++_} ->
+ %% Not counting handler info
+ count_lines2(Dev,LC);
+ {ok,_} ->
+ count_lines2(Dev,LC+1);
+ eof -> LC
+ end.
+
repeat_until_ok(Fun, N) ->
repeat_until_ok(Fun, 0, N, undefined).
@@ -1442,7 +1450,7 @@ repeat_until_ok(Fun, C, Stop, FirstReason) ->
start_tracer(Trace,Expected) ->
Pid = self(),
dbg:tracer(process,{fun tracer/2,{Pid,Expected}}),
- dbg:p(whereis(?MODULE),[c]),
+ dbg:p(h_proc_name(),[c]),
tpl(Trace),
ok.
@@ -1498,3 +1506,11 @@ escape([H|T]) ->
[H|escape(T)];
escape([]) ->
[].
+
+h_proc_name() ->
+ h_proc_name(?MODULE).
+h_proc_name(Name) ->
+ list_to_atom(lists:concat([logger_disk_log_h,"_",Name])).
+
+file_delete(Log) ->
+ file:delete(Log).
diff --git a/lib/kernel/test/logger_env_var_SUITE.erl b/lib/kernel/test/logger_env_var_SUITE.erl
index 601d331fb0..6e182d4bca 100644
--- a/lib/kernel/test/logger_env_var_SUITE.erl
+++ b/lib/kernel/test/logger_env_var_SUITE.erl
@@ -63,8 +63,7 @@ groups() ->
]},
{bad,[],[bad_error_logger,
bad_level,
- bad_sasl_compatibility,
- bad_progress]}].
+ bad_sasl_compatibility]}].
all() ->
[default,
@@ -78,128 +77,126 @@ all() ->
].
default(Config) ->
- {ok,#{handlers:=Hs},_Node} = setup(Config,[]),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},_Node} = setup(Config,[]),
+ notice = maps:get(level,P),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- true = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
+ [] = ML,
ok.
default_sasl_compatible(Config) ->
- {ok,#{handlers:=Hs},_Node} = setup(Config,
- [{logger_sasl_compatible,true}]),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},_Node} =
+ setup(Config,[{logger_sasl_compatible,true}]),
+ info = maps:get(level,P),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp]}}} =
- lists:keyfind(domain,1,StdFilters),
- false = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- true = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ true = exists(sasl,Hs),
+ [] = ML,
ok.
error_logger_tty(Config) ->
- {ok,#{handlers:=Hs},_Node} = setup(Config,[{error_logger,tty}]),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},_Node} =
+ setup(Config,[{error_logger,tty}]),
+ notice = maps:get(level,P),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- true = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
+ [] = ML,
ok.
error_logger_tty_sasl_compatible(Config) ->
- {ok,#{handlers:=Hs},_Node} = setup(Config,
- [{error_logger,tty},
- {logger_sasl_compatible,true}]),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},_Node} =
+ setup(Config,
+ [{error_logger,tty},
+ {logger_sasl_compatible,true}]),
+ info = maps:get(level,P),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp]}}} =
- lists:keyfind(domain,1,StdFilters),
- false = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- true = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ true = exists(sasl,Hs),
+ [] = ML,
ok.
error_logger_false(Config) ->
- {ok,#{handlers:=Hs,logger:=L},_Node} =
+ {ok,#{handlers:=Hs,primary:=P,module_levels:=ML},_Node} =
setup(Config,
[{error_logger,false},
{logger_level,notice}]),
- false = lists:keymember(?STANDARD_HANDLER,1,Hs),
- {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs),
- info = maps:get(level,SimpleC),
- notice = maps:get(level,L),
+ false = exists(?STANDARD_HANDLER,Hs),
+ #{module:=logger_simple_h} = SimpleC = find(simple,Hs),
+ all = maps:get(level,SimpleC),
+ notice = maps:get(level,P),
SimpleFilters = maps:get(filters,SimpleC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,SimpleFilters),
- true = lists:keymember(stop_progress,1,SimpleFilters),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,SimpleFilters),
+ false = exists(sasl,Hs),
+ [] = ML,
ok.
error_logger_false_progress(Config) ->
- {ok,#{handlers:=Hs,logger:=L},_Node} =
+ {ok,#{handlers:=Hs,primary:=P,module_levels:=ML},_Node} =
setup(Config,
[{error_logger,false},
- {logger_level,notice},
- {logger_progress_reports,log}]),
- false = lists:keymember(?STANDARD_HANDLER,1,Hs),
- {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs),
- info = maps:get(level,SimpleC),
- notice = maps:get(level,L),
+ {logger_level,notice}]),
+ false = exists(?STANDARD_HANDLER,Hs),
+ #{module:=logger_simple_h} = SimpleC = find(simple,Hs),
+ all = maps:get(level,SimpleC),
+ notice = maps:get(level,P),
SimpleFilters = maps:get(filters,SimpleC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,SimpleFilters),
- false = lists:keymember(stop_progress,1,SimpleFilters),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,SimpleFilters),
+ false = exists(sasl,Hs),
+ [] = ML,
ok.
error_logger_false_sasl_compatible(Config) ->
- {ok,#{handlers:=Hs,logger:=L},_Node} =
+ {ok,#{handlers:=Hs,primary:=P,module_levels:=ML},_Node} =
setup(Config,
[{error_logger,false},
{logger_level,notice},
{logger_sasl_compatible,true}]),
- false = lists:keymember(?STANDARD_HANDLER,1,Hs),
- {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs),
- info = maps:get(level,SimpleC),
- notice = maps:get(level,L),
+ false = exists(?STANDARD_HANDLER,Hs),
+ #{module:=logger_simple_h} = SimpleC = find(simple,Hs),
+ all = maps:get(level,SimpleC),
+ info = maps:get(level,P),
SimpleFilters = maps:get(filters,SimpleC),
- {domain,{_,{log,super,[beam,erlang,otp]}}} =
- lists:keyfind(domain,1,SimpleFilters),
- false = lists:keymember(stop_progress,1,SimpleFilters),
- true = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,SimpleFilters),
+ true = exists(sasl,Hs),
+ [] = ML,
ok.
error_logger_silent(Config) ->
{ok,#{handlers:=Hs},_Node} = setup(Config,
[{error_logger,silent}]),
- false = lists:keymember(?STANDARD_HANDLER,1,Hs),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ false = exists(?STANDARD_HANDLER,Hs),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
ok.
error_logger_silent_sasl_compatible(Config) ->
{ok,#{handlers:=Hs},_Node} = setup(Config,
[{error_logger,silent},
{logger_sasl_compatible,true}]),
- false = lists:keymember(?STANDARD_HANDLER,1,Hs),
- false = lists:keymember(simple,1,Hs),
- true = lists:keymember(sasl,1,Hs),
+ false = exists(?STANDARD_HANDLER,Hs),
+ false = exists(simple,Hs),
+ true = exists(sasl,Hs),
ok.
error_logger_file(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,_Hs,Node} = setup(Config,
- [{error_logger,{file,Log}}]),
+ {ok,_,Node} = setup(Config,
+ [{error_logger,{file,Log}}]),
check_default_log(Node,Log,
file,% dest
0),% progress in std logger
@@ -208,70 +205,67 @@ error_logger_file(Config) ->
logger_file(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,#{handlers:=Hs},Node}
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},Node}
= setup(Config,
[{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
- #{logger_std_h=>#{type=>{file,Log}}}}]}]),
+ #{config=>#{type=>{file,Log}}}}]}]),
check_default_log(Node,Log,
file,% dest
0),% progress in std logger
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- true = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
-
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
+ [] = ML,
ok.
logger_file_sasl_compatible(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,#{handlers:=Hs},Node}
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},Node}
= setup(Config,
[{logger_sasl_compatible,true},
{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
- #{logger_std_h=>#{type=>{file,Log}}}}]}]),
+ #{config=>#{type=>{file,Log}}}}]}]),
check_default_log(Node,Log,
file,% dest
0),% progress in std logger
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ info = maps:get(level,P),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp]}}} =
- lists:keyfind(domain,1,StdFilters),
- false = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- true = lists:keymember(sasl,1,Hs),
-
+ {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ true = exists(sasl,Hs),
+ [] = ML,
ok.
logger_file_log_progress(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,#{handlers:=Hs},Node}
+ {ok,#{primary:=P,handlers:=Hs,module_levels:=ML},Node}
= setup(Config,
- [{logger_progress_reports,log},
+ [{logger_level,info},
{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
- #{logger_std_h=>#{type=>{file,Log}}}}]}]),
+ #{config=>#{type=>{file,Log}}}}]}]),
check_default_log(Node,Log,
file,% dest
- 6),% progress in std logger
+ 6,% progress in std logger
+ info),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ info = maps:get(level,P),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- false = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
-
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
+ [] = ML,
ok.
logger_file_no_filter(Config) ->
@@ -281,16 +275,16 @@ logger_file_no_filter(Config) ->
[{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
#{filter_default=>log,filters=>[],
- logger_std_h=>#{type=>{file,Log}}}}]}]),
+ config=>#{type=>{file,Log}}}}]}]),
check_default_log(Node,Log,
file,% dest
6),% progress in std logger
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
[] = maps:get(filters,StdC),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
ok.
@@ -301,17 +295,17 @@ logger_file_no_filter_level(Config) ->
[{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
#{filters=>[],level=>error,
- logger_std_h=>#{type=>{file,Log}}}}]}]),
+ config=>#{type=>{file,Log}}}}]}]),
check_default_log(Node,Log,
file,% dest
0,% progress in std logger
error),% level
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
error = maps:get(level,StdC),
[] = maps:get(filters,StdC),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
ok.
@@ -323,68 +317,67 @@ logger_file_formatter(Config) ->
[{handler,?STANDARD_HANDLER,logger_std_h,
#{filters=>[],
formatter=>{logger_formatter,#{}},
- logger_std_h=>#{type=>{file,Log}}}}]}]),
+ config=>#{type=>{file,Log}}}}]}]),
check_single_log(Node,Log,
file,% dest
6),% progress in std logger
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
[] = maps:get(filters,StdC),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
ok.
logger_filters(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,#{handlers:=Hs,logger:=Logger},Node}
+ {ok,#{handlers:=Hs,primary:=P},Node}
= setup(Config,
- [{logger_progress_reports,log},
+ [{logger_level,info},
{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
- #{logger_std_h=>#{type=>{file,Log}}}},
+ #{config=>#{type=>{file,Log}}}},
{filters,log,[{stop_progress,{fun logger_filters:progress/2,stop}}]}
]}]),
check_default_log(Node,Log,
file,% dest
- 0),% progress in std logger
+ 0,% progress in std logger
+ info),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- false = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
- LoggerFilters = maps:get(filters,Logger),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
+ LoggerFilters = maps:get(filters,P),
true = lists:keymember(stop_progress,1,LoggerFilters),
ok.
logger_filters_stop(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,#{handlers:=Hs,logger:=Logger},Node}
+ {ok,#{handlers:=Hs,primary:=P},Node}
= setup(Config,
- [{logger_progress_reports,log},
+ [{logger_level,info},
{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
#{filters=>[],
- logger_std_h=>#{type=>{file,Log}}}},
+ config=>#{type=>{file,Log}}}},
{filters,stop,[{log_error,{fun logger_filters:level/2,{log,gt,info}}}]}
]}]),
check_default_log(Node,Log,
file,% dest
- 0,
- notice),% progress in std logger
+ 0,% progress in std logger
+ info),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
[] = maps:get(filters,StdC),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
- LoggerFilters = maps:get(filters,Logger),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
+ LoggerFilters = maps:get(filters,P),
true = lists:keymember(log_error,1,LoggerFilters),
ok.
@@ -393,24 +386,23 @@ logger_module_level(Config) ->
Log = file(Config,?FUNCTION_NAME),
{ok,#{handlers:=Hs,module_levels:=ModuleLevels},Node}
= setup(Config,
- [{logger_progress_reports,log},
+ [{logger_level,info},
{logger,
[{handler,?STANDARD_HANDLER,logger_std_h,
- #{logger_std_h=>#{type=>{file,Log}}}},
+ #{config=>#{type=>{file,Log}}}},
{module_level,error,[supervisor]}
]}]),
check_default_log(Node,Log,
file,% dest
- 3),% progress in std logger
+ 3,% progress in std logger
+ info),
- {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_std_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- false = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
[{supervisor,error}] = ModuleLevels,
ok.
@@ -420,19 +412,17 @@ logger_disk_log(Config) ->
= setup(Config,
[{logger,
[{handler,?STANDARD_HANDLER,logger_disk_log_h,
- #{disk_log_opts=>#{file=>Log}}}]}]),
+ #{config=>#{file=>Log}}}]}]),
check_default_log(Node,Log,
disk_log,% dest
0),% progress in std logger
- {?STANDARD_HANDLER,logger_disk_log_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_disk_log_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
StdFilters = maps:get(filters,StdC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,StdFilters),
- true = lists:keymember(stop_progress,1,StdFilters),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
ok.
@@ -444,31 +434,29 @@ logger_disk_log_formatter(Config) ->
[{handler,?STANDARD_HANDLER,logger_disk_log_h,
#{filters=>[],
formatter=>{logger_formatter,#{}},
- disk_log_opts=>#{file=>Log}}}]}]),
+ config=>#{file=>Log}}}]}]),
check_single_log(Node,Log,
disk_log,% dest
6),% progress in std logger
- {?STANDARD_HANDLER,logger_disk_log_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs),
- info = maps:get(level,StdC),
+ #{module:=logger_disk_log_h} = StdC = find(?STANDARD_HANDLER,Hs),
+ all = maps:get(level,StdC),
[] = maps:get(filters,StdC),
- false = lists:keymember(simple,1,Hs),
- false = lists:keymember(sasl,1,Hs),
+ false = exists(simple,Hs),
+ false = exists(sasl,Hs),
ok.
logger_undefined(Config) ->
- {ok,#{handlers:=Hs,logger:=L},_Node} =
+ {ok,#{handlers:=Hs,primary:=P},_Node} =
setup(Config,[{logger,[{handler,?STANDARD_HANDLER,undefined}]}]),
- false = lists:keymember(?STANDARD_HANDLER,1,Hs),
- {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs),
- info = maps:get(level,SimpleC),
- info = maps:get(level,L),
+ false = exists(?STANDARD_HANDLER,Hs),
+ #{module:=logger_simple_h} = SimpleC = find(simple,Hs),
+ all = maps:get(level,SimpleC),
+ notice = maps:get(level,P),
SimpleFilters = maps:get(filters,SimpleC),
- {domain,{_,{log,super,[beam,erlang,otp,sasl]}}} =
- lists:keyfind(domain,1,SimpleFilters),
- true = lists:keymember(stop_progress,1,SimpleFilters),
- false = lists:keymember(sasl,1,Hs),
+ {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,SimpleFilters),
+ false = exists(sasl,Hs),
ok.
@@ -483,14 +471,15 @@ logger_many_handlers_default_first(Config) ->
#{level=>error,
filters=>[],
formatter=>{logger_formatter,#{}},
- logger_std_h=>#{type=>{file,LogErr}}}
+ config=>#{type=>{file,LogErr}}}
},
{handler,info,logger_std_h,
#{level=>info,
filters=>[{level,{fun logger_filters:level/2,{stop,gteq,error}}}],
- logger_std_h=>#{type=>{file,LogInfo}}}
+ config=>#{type=>{file,LogInfo}}}
}
- ]}], LogErr, LogInfo, 6).
+ ]},
+ {logger_level,info}], LogErr, LogInfo, 6).
%% Test that we can add multiple handlers with the default last
logger_many_handlers_default_last(Config) ->
@@ -501,15 +490,16 @@ logger_many_handlers_default_last(Config) ->
[{handler,info,logger_std_h,
#{level=>info,
filters=>[{level,{fun logger_filters:level/2,{stop,gteq,error}}}],
- logger_std_h=>#{type=>{file,LogInfo}}}
+ config=>#{type=>{file,LogInfo}}}
},
{handler,?STANDARD_HANDLER,logger_std_h,
#{level=>error,
filters=>[],
formatter=>{logger_formatter,#{}},
- logger_std_h=>#{type=>{file,LogErr}}}
+ config=>#{type=>{file,LogErr}}}
}
- ]}], LogErr, LogInfo, 7).
+ ]},
+ {logger_level,info}], LogErr, LogInfo, 7).
%% Check that we can handle that an added logger has a broken filter
%% This used to cause a deadlock.
@@ -523,15 +513,16 @@ logger_many_handlers_default_last_broken_filter(Config) ->
#{level=>info,
filters=>[{broken,{fun logger_filters:level/2,broken_state}},
{level,{fun logger_filters:level/2,{stop,gteq,error}}}],
- logger_std_h=>#{type=>{file,LogInfo}}}
+ config=>#{type=>{file,LogInfo}}}
},
{handler,?STANDARD_HANDLER,logger_std_h,
#{level=>error,
filters=>[],
formatter=>{logger_formatter,#{}},
- logger_std_h=>#{type=>{file,LogErr}}}
+ config=>#{type=>{file,LogErr}}}
}
- ]}], LogErr, LogInfo, 7).
+ ]},
+ {logger_level,info}], LogErr, LogInfo, 7).
logger_many_handlers(Config, Env, LogErr, LogInfo, NumProgress) ->
{ok,#{handlers:=Hs},Node} = setup(Config,Env),
@@ -539,31 +530,32 @@ logger_many_handlers(Config, Env, LogErr, LogInfo, NumProgress) ->
file,% dest
0,% progress in std logger
error), % level
- ok = rpc:call(Node,logger_std_h,filesync,[info]),
+ ok = rpc:call(Node,logger_std_h,sync,[info]),
{ok, Bin} = file:read_file(LogInfo),
ct:log("Log content:~n~s",[Bin]),
- match(Bin,<<"info:">>,NumProgress+1,info,info),
+ match(Bin,<<"info:">>,NumProgress,info,info),
+ match(Bin,<<"notice:">>,1,notice,info),
match(Bin,<<"alert:">>,0,alert,info),
ok.
sasl_compatible_false(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,_Hs,Node} = setup(Config,
- [{error_logger,{file,Log}},
- {logger_sasl_compatible,false},
- {logger_progress_reports,log}]),
+ {ok,_,Node} = setup(Config,
+ [{error_logger,{file,Log}},
+ {logger_sasl_compatible,false},
+ {logger_level,info}]), % to get progress
check_default_log(Node,Log,
file,% dest
- 6),% progress in std logger
+ 6,% progress in std logger
+ info),
ok.
sasl_compatible_false_no_progress(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,_Hs,Node} = setup(Config,
- [{error_logger,{file,Log}},
- {logger_sasl_compatible,false},
- {logger_progress_reports,stop}]),
+ {ok,_,Node} = setup(Config,
+ [{error_logger,{file,Log}},
+ {logger_sasl_compatible,false}]),
check_default_log(Node,Log,
file,% dest
0),% progress in std logger
@@ -571,9 +563,9 @@ sasl_compatible_false_no_progress(Config) ->
sasl_compatible(Config) ->
Log = file(Config,?FUNCTION_NAME),
- {ok,_Hs,Node} = setup(Config,
- [{error_logger,{file,Log}},
- {sasl_compatible,true}]),
+ {ok,_,Node} = setup(Config,
+ [{error_logger,{file,Log}},
+ {sasl_compatible,true}]),
check_default_log(Node,Log,
file,% dest
0),% progress in std logger
@@ -588,9 +580,6 @@ bad_level(Config) ->
bad_sasl_compatibility(Config) ->
error = setup(Config,[{logger_sasl_compatible,badcomp}]).
-bad_progress(Config) ->
- error = setup(Config,[{logger_progress_reports,badprogress}]).
-
%%%-----------------------------------------------------------------
%%% Internal
file(Config,Func) ->
@@ -598,22 +587,22 @@ file(Config,Func) ->
lists:concat([Func,".log"])).
check_default_log(Node,Log,Dest,NumProgress) ->
- check_default_log(Node,Log,Dest,NumProgress,info).
+ check_default_log(Node,Log,Dest,NumProgress,notice).
check_default_log(Node,Log,Dest,NumProgress,Level) ->
{ok,Bin1,Bin2} = check_log(Node,Log,Dest),
match(Bin1,<<"PROGRESS REPORT">>,NumProgress,info,Level),
match(Bin1,<<"ALERT REPORT">>,1,alert,Level),
- match(Bin1,<<"INFO REPORT">>,0,info,Level),
+ match(Bin1,<<"INFO REPORT">>,0,notice,Level),
match(Bin1,<<"DEBUG REPORT">>,0,debug,Level),
- match(Bin2,<<"INFO REPORT">>,1,info,Level),
+ match(Bin2,<<"INFO REPORT">>,1,notice,Level),
match(Bin2,<<"DEBUG REPORT">>,0,debug,Level),
ok.
check_single_log(Node,Log,Dest,NumProgress) ->
- check_single_log(Node,Log,Dest,NumProgress,info).
+ check_single_log(Node,Log,Dest,NumProgress,notice).
check_single_log(Node,Log,Dest,NumProgress,Level) ->
{ok,Bin1,Bin2} = check_log(Node,Log,Dest),
@@ -654,3 +643,21 @@ match(Bin,Pattern,N,LogLevel,ConfLevel) ->
{match,M} = re:run(Bin,Pattern,[{capture,all},global]),
N = length(M)
end.
+
+find(Id,Handlers) ->
+ case lists:search(fun(#{id:=Id0}) when Id0=:=Id-> true;
+ (_) -> false end,
+ Handlers) of
+ {value,Config} ->
+ Config;
+ false ->
+ false
+ end.
+
+exists(Id,Handlers) ->
+ case find(Id,Handlers) of
+ false ->
+ false;
+ _ ->
+ true
+ end.
diff --git a/lib/kernel/test/logger_formatter_SUITE.erl b/lib/kernel/test/logger_formatter_SUITE.erl
index 7a93f2ca79..864a40b618 100644
--- a/lib/kernel/test/logger_formatter_SUITE.erl
+++ b/lib/kernel/test/logger_formatter_SUITE.erl
@@ -56,6 +56,7 @@ groups() ->
all() ->
[default,
legacy_header,
+ error_logger_notice_header,
single_line,
template,
format_msg,
@@ -69,6 +70,7 @@ all() ->
faulty_log,
faulty_config,
faulty_msg,
+ check_config,
update_config].
default(_Config) ->
@@ -124,6 +126,34 @@ legacy_header(_Config) ->
"=INFO REPORT==== "++_ = String5,
ok.
+error_logger_notice_header(_Config) ->
+ Meta1 = #{error_logger=>#{tag => info_report,type => std_info}},
+ String1 = format(notice,{"~p",[term]},Meta1,
+ #{legacy_header=>true,
+ error_logger_notice_header=>notice}),
+ ct:log(String1),
+ "=NOTICE REPORT==== "++_ = String1,
+
+ String2 = format(notice,{"~p",[term]},Meta1,
+ #{legacy_header=>true,
+ error_logger_notice_header=>info}),
+ ct:log(String2),
+ "=INFO REPORT==== "++_ = String2,
+
+ String3 = format(notice,{"~p",[term]},#{},
+ #{legacy_header=>true,
+ error_logger_notice_header=>notice}),
+ ct:log(String3),
+ "=NOTICE REPORT==== "++_ = String3,
+
+ String4 = format(notice,{"~p",[term]},#{},
+ #{legacy_header=>true,
+ error_logger_notice_header=>info}),
+ ct:log(String4),
+ "=NOTICE REPORT==== "++_ = String4,
+
+ ok.
+
single_line(_Config) ->
Time = timestamp(),
ExpectedTimestamp = default_time_format(Time),
@@ -158,7 +188,7 @@ template(_Config) ->
Template4 = ["string\nnewline"],
String4 = format(info,{"~p",[term]},#{time=>Time},#{template=>Template4,
- single_line=>true}),
+ single_line=>true}),
ct:log(String4),
"string\nnewline" = String4,
@@ -179,7 +209,7 @@ template(_Config) ->
tuple=>{1,atom,"list"},
nested=>#{subkey=>subvalue}},
Template6 = lists:join(";",maps:keys(maps:remove(nested,Meta6)) ++
- [{nested,subkey}]),
+ [[nested,subkey]]),
String6 = format(info,{"~p",[term]},Meta6,#{template=>Template6,
single_line=>true}),
ct:log(String6),
@@ -202,16 +232,16 @@ template(_Config) ->
nested=>#{key1=>#{subkey1=>value1},
key2=>value2}},
Template7 = lists:join(";",[nested,
- {nested,key1},
- {nested,key1,subkey1},
- {nested,key2},
- {nested,key2,subkey2},
- {nested,key3},
- {nested,key3,subkey3}]),
+ [nested,key1],
+ [nested,key1,subkey1],
+ [nested,key2],
+ [nested,key2,subkey2],
+ [nested,key3],
+ [nested,key3,subkey3]]),
String7 = format(info,{"~p",[term]},Meta7,#{template=>Template7,
single_line=>true}),
ct:log(String7),
- [MultipleKeysStr,
+ [MultipleKeysStr7,
"#{subkey1 => value1}",
"value1",
"value2",
@@ -219,11 +249,42 @@ template(_Config) ->
"",
""] = string:split(String7,";",all),
%% Order of keys is not fixed
- case MultipleKeysStr of
+ case MultipleKeysStr7 of
"#{key2 => value2,key1 => #{subkey1 => value1}}" -> ok;
"#{key1 => #{subkey1 => value1},key2 => value2}" -> ok;
- _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr})
+ _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr7})
+ end,
+
+ Meta8 = #{time=>Time,
+ nested=>#{key1=>#{subkey1=>value1},
+ key2=>value2}},
+ Template8 =
+ lists:join(
+ ";",
+ [{nested,["exist:",nested],["noexist"]},
+ {[nested,key1],["exist:",[nested,key1]],["noexist"]},
+ {[nested,key1,subkey1],["exist:",[nested,key1,subkey1]],["noexist"]},
+ {[nested,key2],["exist:",[nested,key2]],["noexist"]},
+ {[nested,key2,subkey2],["exist:",[nested,key2,subkey2]],["noexist"]},
+ {[nested,key3],["exist:",[nested,key3]],["noexist"]},
+ {[nested,key3,subkey3],["exist:",[nested,key3,subkey3]],["noexist"]}]),
+ String8 = format(info,{"~p",[term]},Meta8,#{template=>Template8,
+ single_line=>true}),
+ ct:log(String8),
+ [MultipleKeysStr8,
+ "exist:#{subkey1 => value1}",
+ "exist:value1",
+ "exist:value2",
+ "noexist",
+ "noexist",
+ "noexist"] = string:split(String8,";",all),
+ %% Order of keys is not fixed
+ case MultipleKeysStr8 of
+ "exist:#{key2 => value2,key1 => #{subkey1 => value1}}" -> ok;
+ "exist:#{key1 => #{subkey1 => value1},key2 => value2}" -> ok;
+ _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr8})
end,
+
ok.
format_msg(_Config) ->
@@ -541,23 +602,113 @@ faulty_msg(_Config) ->
#{})),
ok.
+-define(cfgerr(X), {error,{invalid_formatter_config,logger_formatter,X}}).
+check_config(_Config) ->
+ ok = logger_formatter:check_config(#{}),
+ ?cfgerr(bad) = logger_formatter:check_config(bad),
+
+ C1 = #{chars_limit => 1,
+ depth => 1,
+ legacy_header => true,
+ error_logger_notice_header => info,
+ max_size => 1,
+ report_cb => fun(R) -> {"~p",[R]} end,
+ single_line => false,
+ template => [],
+ time_designator => $T,
+ time_offset => 0},
+ ok = logger_formatter:check_config(C1),
+
+ ok = logger_formatter:check_config(#{chars_limit => unlimited}),
+ ?cfgerr({chars_limit,bad}) =
+ logger_formatter:check_config(#{chars_limit => bad}),
+
+ ok = logger_formatter:check_config(#{depth => unlimited}),
+ ?cfgerr({depth,bad}) =
+ logger_formatter:check_config(#{depth => bad}),
+
+ ok = logger_formatter:check_config(#{legacy_header => false}),
+ ?cfgerr({legacy_header,bad}) =
+ logger_formatter:check_config(#{legacy_header => bad}),
+
+ ok = logger_formatter:check_config(#{error_logger_notice_header => notice}),
+ ?cfgerr({error_logger_notice_header,bad}) =
+ logger_formatter:check_config(#{error_logger_notice_header => bad}),
+
+ ok = logger_formatter:check_config(#{max_size => unlimited}),
+ ?cfgerr({max_size,bad}) =
+ logger_formatter:check_config(#{max_size => bad}),
+
+ ?cfgerr({report_cb,F}) =
+ logger_formatter:check_config(#{report_cb => F=fun(_,_) -> {"",[]} end}),
+ ?cfgerr({report_cb,bad}) =
+ logger_formatter:check_config(#{report_cb => bad}),
+
+ ok = logger_formatter:check_config(#{single_line => true}),
+ ?cfgerr({single_line,bad}) =
+ logger_formatter:check_config(#{single_line => bad}),
+
+ Ts = [[key],
+ [[key1,key2]],
+ [{key,[key],[]}],
+ [{[key1,key2],[[key1,key2]],["noexist"]}],
+ ["string"]],
+ [begin
+ ct:log("check template: ~p",[T]),
+ ok = logger_formatter:check_config(#{template => T})
+ end
+ || T <- Ts],
+
+ ETs = [bad,
+ [{key,bad}],
+ [{key,[key],bad}],
+ [{key,[key],"bad"}],
+ "bad",
+ [[key,$a,$b,$c]],
+ [[$a,$b,$c,key]]],
+ [begin
+ ct:log("check template: ~p",[T]),
+ {error,{invalid_formatter_template,logger_formatter,T}} =
+ logger_formatter:check_config(#{template => T})
+ end
+ || T <- ETs],
+
+ ?cfgerr({time_designator,bad}) =
+ logger_formatter:check_config(#{time_designator => bad}),
+ ?cfgerr({time_designator,"b"}) =
+ logger_formatter:check_config(#{time_designator => "b"}),
+
+ ok = logger_formatter:check_config(#{time_offset => -1}),
+ ok = logger_formatter:check_config(#{time_offset => "+02:00"}),
+ ok = logger_formatter:check_config(#{time_offset => "-23:59"}),
+ ok = logger_formatter:check_config(#{time_offset => "+24:00"}),
+ ok = logger_formatter:check_config(#{time_offset => "-25:00"}),
+ ?cfgerr({time_offset,bad}) =
+ logger_formatter:check_config(#{time_offset => bad}),
+ ?cfgerr({time_offset,"02:00"}) =
+ logger_formatter:check_config(#{time_offset => "02:00"}),
+ ?cfgerr({time_offset,"+02"}) =
+ logger_formatter:check_config(#{time_offset => "+02"}),
+
+ ok.
+
%% Test that formatter config can be changed, and that the default
%% template is updated accordingly
update_config(_Config) ->
logger:add_handler_filter(default,silence,{fun(_,_) -> stop end,ok}),
ok = logger:add_handler(?MODULE,?MODULE,#{}),
D = lists:seq(1,1000),
- logger:info("~p~n",[D]),
+ logger:notice("~p~n",[D]),
{Lines1,C1} = check_log(),
[ct:log(L) || L <- Lines1],
ct:log("~p",[C1]),
[Line1] = Lines1,
- [_Time,"info: "++D1] = string:split(Line1," "),
+ [_Time,"notice: "++D1] = string:split(Line1," "),
true = length(D1)>3000,
true = #{}==C1,
ok = logger:update_formatter_config(?MODULE,single_line,false),
- logger:info("~p~n",[D]),
+ logger:notice("~p~n",[D]),
{Lines2,C2} = check_log(),
[ct:log(L) || L <- Lines2],
ct:log("~p",[C2]),
@@ -565,23 +716,37 @@ update_config(_Config) ->
true = #{single_line=>false}==C2,
ok = logger:update_formatter_config(?MODULE,#{legacy_header=>true}),
- logger:info("~p~n",[D]),
+ logger:notice("~p~n",[D]),
{Lines3,C3} = check_log(),
[ct:log(L) || L <- Lines3],
ct:log("~p",[C3]),
- ["=INFO REPORT==== "++_|D3] = Lines3,
+ ["=NOTICE REPORT==== "++_|D3] = Lines3,
true = length(D3)>50,
true = #{legacy_header=>true,single_line=>false}==C3,
ok = logger:update_formatter_config(?MODULE,single_line,true),
- logger:info("~p~n",[D]),
+ logger:notice("~p~n",[D]),
{Lines4,C4} = check_log(),
[ct:log(L) || L <- Lines4],
ct:log("~p",[C4]),
- ["=INFO REPORT==== "++_,D4] = Lines4,
+ ["=NOTICE REPORT==== "++_,D4] = Lines4,
true = length(D4)>3000,
true = #{legacy_header=>true,single_line=>true}==C4,
+ %% Finally, check that error_logger_notice_header works, default=info
+ error_logger:info_msg("~p",[D]),
+ {Lines5,C5} = check_log(),
+ [ct:log(L) || L <- Lines5],
+ ct:log("~p",[C5]),
+ ["=INFO REPORT==== "++_,_D5] = Lines5,
+
+ ok=logger:update_formatter_config(?MODULE,error_logger_notice_header,notice),
+ error_logger:info_msg("~p",[D]),
+ {Lines6,C6} = check_log(),
+ [ct:log(L) || L <- Lines6],
+ ct:log("~p",[C6]),
+ ["=NOTICE REPORT==== "++_,_D6] = Lines6,
+
ok.
update_config(cleanup,_Config) ->
diff --git a/lib/kernel/test/logger_legacy_SUITE.erl b/lib/kernel/test/logger_legacy_SUITE.erl
index cfba35e43f..de73b6152a 100644
--- a/lib/kernel/test/logger_legacy_SUITE.erl
+++ b/lib/kernel/test/logger_legacy_SUITE.erl
@@ -67,25 +67,28 @@ end_per_suite(_Config) ->
init_per_group(std, Config) ->
ok = logger:set_handler_config(
error_logger,filters,
- [{domain,{fun logger_filters:domain/2,
- {log,super,[beam,erlang,otp]}}}]),
+ [{domain,{fun logger_filters:domain/2,{log,super,[otp]}}}]),
Config;
init_per_group(sasl, Config) ->
+ %% Since default level is notice, and progress reports are info,
+ %% we need to raise the global logger level to info in order to
+ %% receive these.
+ ok = logger:set_primary_config(level,info),
ok = logger:set_handler_config(
error_logger,filters,
- [{domain,{fun logger_filters:domain/2,
- {log,super,[beam,erlang,otp,sasl]}}}]),
+ [{domain,{fun logger_filters:domain/2,{log,super,[otp,sasl]}}}]),
%% cth_log_redirect checks if sasl is started before displaying
%% any sasl reports - so just to see the real sasl reports in tc
%% log:
- application:start(sasl),
- Config;
+ {ok,Apps} = application:ensure_all_started(sasl),
+ [{stop_apps,Apps}|Config];
init_per_group(_Group, Config) ->
Config.
-end_per_group(sasl, _Config) ->
- application:stop(sasl),
+end_per_group(sasl, Config) ->
+ Apps = ?config(stop_apps,Config),
+ [application:stop(App) || App <- Apps],
ok;
end_per_group(_Group, _Config) ->
ok.
diff --git a/lib/kernel/test/logger_simple_h_SUITE.erl b/lib/kernel/test/logger_simple_h_SUITE.erl
index 271a2126de..e4e48b538a 100644
--- a/lib/kernel/test/logger_simple_h_SUITE.erl
+++ b/lib/kernel/test/logger_simple_h_SUITE.erl
@@ -48,7 +48,7 @@ suite() ->
{ct_hooks, [logger_test_lib]}].
init_per_suite(Config) ->
- #{handlers:=Hs0} = logger:i(),
+ Hs0 = logger:get_handler_config(),
Hs = lists:keydelete(cth_log_redirect,1,Hs0),
[ok = logger:remove_handler(Id) || {Id,_,_} <- Hs],
Env = [{App,Key,application:get_env(App,Key)} ||
@@ -128,8 +128,8 @@ replace_file(Config) ->
log(Node, emergency, [M1=?str]),
log(Node, alert, [M2=?str,[]]),
log(Node, error, [M3=?map_rep]),
- log(Node, info, [M4=?keyval_rep]),
- log(Node, info, [M41=?keyval_rep++[not_key_val]]),
+ log(Node, warning, [M4=?keyval_rep]),
+ log(Node, warning, [M41=?keyval_rep++[not_key_val]]),
log(Node, critical, [M7=?str,[A7=?keyval_rep]]),
log(Node, notice, [M8=["fake",string,"line:",?LINE]]),
@@ -138,7 +138,7 @@ replace_file(Config) ->
ok = rpc:call(Node, logger, add_handlers,
[[{handler, default, logger_std_h,
- #{ logger_std_h => #{ type => {file, File} },
+ #{ config => #{ type => {file, File} },
formatter => {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}}]]),
{ok,Bin} = sync_and_read(Node, file, File),
@@ -151,10 +151,10 @@ replace_file(Config) ->
"=ERROR REPORT===="++_,
_,
_,
- "=INFO REPORT===="++_,
+ "=WARNING REPORT===="++_,
_,
_,
- "=INFO REPORT===="++_,
+ "=WARNING REPORT===="++_,
_,
_,
_,
@@ -172,8 +172,8 @@ replace_disk_log(Config) ->
log(Node, emergency, [M1=?str]),
log(Node, alert, [M2=?str,[]]),
log(Node, error, [M3=?map_rep]),
- log(Node, info, [M4=?keyval_rep]),
- log(Node, info, [M41=?keyval_rep++[not_key_val]]),
+ log(Node, warning, [M4=?keyval_rep]),
+ log(Node, warning, [M41=?keyval_rep++[not_key_val]]),
log(Node, critical, [M7=?str,[A7=?keyval_rep]]),
log(Node, notice, [M8=["fake",string,"line:",?LINE]]),
@@ -182,7 +182,7 @@ replace_disk_log(Config) ->
ok = rpc:call(Node, logger, add_handlers,
[[{handler, default, logger_disk_log_h,
- #{ disk_log_opts => #{ file => File },
+ #{ config => #{ file => File },
formatter => {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}}]]),
{ok,Bin} = sync_and_read(Node, disk_log, File),
Lines = [unicode:characters_to_list(L) ||
@@ -194,10 +194,10 @@ replace_disk_log(Config) ->
"=ERROR REPORT===="++_,
_,
_,
- "=INFO REPORT===="++_,
+ "=WARNING REPORT===="++_,
_,
_,
- "=INFO REPORT===="++_,
+ "=WARNING REPORT===="++_,
_,
_,
_,
diff --git a/lib/kernel/test/logger_std_h_SUITE.erl b/lib/kernel/test/logger_std_h_SUITE.erl
index 5764abd063..36b123b07d 100644
--- a/lib/kernel/test/logger_std_h_SUITE.erl
+++ b/lib/kernel/test/logger_std_h_SUITE.erl
@@ -55,7 +55,7 @@ suite() ->
init_per_suite(Config) ->
timer:start(), % to avoid progress report
- {ok,{logger_std_h,#{formatter:=OrigFormatter}}} =
+ {ok,#{formatter:=OrigFormatter}} =
logger:get_handler_config(?STANDARD_HANDLER),
[{formatter,OrigFormatter}|Config].
@@ -108,7 +108,7 @@ all() ->
info_and_reset,
reconfig,
file_opts,
- filesync,
+ sync,
write_failure,
sync_failure,
op_switch_to_sync_file,
@@ -132,7 +132,7 @@ all() ->
add_remove_instance_tty(_Config) ->
{error,{handler_not_added,{invalid_config,logger_std_h,{type,tty}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{type => tty},
+ #{config => #{type => tty},
filter_default=>log,
formatter=>{?MODULE,self()}}),
ok.
@@ -166,20 +166,20 @@ add_remove_instance_file2(cleanup,_Config) ->
add_remove_instance_file(Log, Type) ->
ok = logger:add_handler(?MODULE,
logger_std_h,
- #{logger_std_h => #{type => Type},
+ #{config => #{type => Type},
filter_default=>stop,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}}),
- Pid = whereis(?MODULE),
+ Pid = whereis(h_proc_name()),
true = is_pid(Pid),
- logger:info(M1=?msg,?domain),
+ logger:notice(M1=?msg,?domain),
?check(M1),
B1 = ?bin(M1),
try_read_file(Log, {ok,B1}, ?FILESYNC_REP_INT),
ok = logger:remove_handler(?MODULE),
timer:sleep(500),
- undefined = whereis(?MODULE),
- logger:info(?msg,?domain),
+ undefined = whereis(h_proc_name()),
+ logger:notice(?msg,?domain),
?check_no_log,
try_read_file(Log, {ok,B1}, ?FILESYNC_REP_INT),
ok.
@@ -188,11 +188,11 @@ default_formatter(_Config) ->
ok = logger:set_handler_config(?STANDARD_HANDLER,formatter,
{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}),
ct:capture_start(),
- logger:info(M1=?msg),
+ logger:notice(M1=?msg),
timer:sleep(100),
ct:capture_stop(),
[Msg] = ct:capture_get(),
- match = re:run(Msg,"=INFO REPORT====.*\n"++M1,[{capture,none}]),
+ match = re:run(Msg,"=NOTICE REPORT====.*\n"++M1,[{capture,none}]),
ok.
errors(Config) ->
@@ -212,20 +212,20 @@ errors(Config) ->
{handler_not_added,
{invalid_config,logger_std_h,{type,faulty_type}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{type => faulty_type}}),
+ #{config => #{type => faulty_type}}),
NoDir = lists:concat(["/",?MODULE,"_dir"]),
{error,
{handler_not_added,{{open_failed,NoDir,eacces},_}}} =
logger:add_handler(myh2,logger_std_h,
- #{logger_std_h=>#{type=>{file,NoDir}}}),
+ #{config=>#{type=>{file,NoDir}}}),
{error,
{handler_not_added,{{open_failed,Log,_},_}}} =
logger:add_handler(myh3,logger_std_h,
- #{logger_std_h=>#{type=>{file,Log,[bad_file_opt]}}}),
+ #{config=>#{type=>{file,Log,[bad_file_opt]}}}),
- ok = logger:info(?msg).
+ ok = logger:notice(?msg).
errors(cleanup,_Config) ->
logger:remove_handler(?MODULE).
@@ -237,43 +237,40 @@ formatter_fail(Config) ->
%% no formatter
ok = logger:add_handler(?MODULE,
logger_std_h,
- #{logger_std_h => #{type => {file,Log}},
+ #{config => #{type => {file,Log}},
filter_default=>stop,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE])}),
- Pid = whereis(?MODULE),
+ Pid = whereis(h_proc_name()),
true = is_pid(Pid),
- #{handlers:=HC1} = logger:i(),
- H = [Id || {Id,_,_} <- HC1],
+ H = logger:get_handler_ids(),
true = lists:member(?MODULE,H),
%% Formatter is added automatically
- {ok,{_,#{formatter:={logger_formatter,_}}}} =
- logger:get_handler_config(?MODULE),
- logger:info(M1=?msg,?domain),
- Got1 = try_match_file(Log,"[0-9\\+\\-T:\\.]* info: "++M1,5000),
+ {ok,#{formatter:={logger_formatter,_}}} = logger:get_handler_config(?MODULE),
+ logger:notice(M1=?msg,?domain),
+ Got1 = try_match_file(Log,"[0-9\\+\\-T:\\.]* notice: "++M1,5000),
ok = logger:set_handler_config(?MODULE,formatter,{nonexistingmodule,#{}}),
- logger:info(M2=?msg,?domain),
+ logger:notice(M2=?msg,?domain),
Got2 = try_match_file(Log,
- escape(Got1)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M2,
+ escape(Got1)++"[0-9\\+\\-T:\\.]* notice: FORMATTER CRASH: .*"++M2,
5000),
ok = logger:set_handler_config(?MODULE,formatter,{?MODULE,crash}),
- logger:info(M3=?msg,?domain),
+ logger:notice(M3=?msg,?domain),
Got3 = try_match_file(Log,
- escape(Got2)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M3,
+ escape(Got2)++"[0-9\\+\\-T:\\.]* notice: FORMATTER CRASH: .*"++M3,
5000),
ok = logger:set_handler_config(?MODULE,formatter,{?MODULE,bad_return}),
- logger:info(?msg,?domain),
+ logger:notice(?msg,?domain),
try_match_file(Log,
escape(Got3)++"FORMATTER ERROR: bad_return_value",
5000),
%% Check that handler is still alive and was never dead
- Pid = whereis(?MODULE),
- #{handlers:=HC2} = logger:i(),
- H = [Id || {Id,_,_} <- HC2],
+ Pid = whereis(h_proc_name()),
+ H = logger:get_handler_ids(),
ok.
@@ -283,41 +280,41 @@ formatter_fail(cleanup,_Config) ->
config_fail(_Config) ->
{error,{handler_not_added,{invalid_config,logger_std_h,{bad,bad}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{bad => bad},
+ #{config => #{bad => bad},
filter_default=>log,
formatter=>{?MODULE,self()}}),
{error,{handler_not_added,{invalid_config,logger_std_h,
{restart_type,bad}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{restart_type => bad},
+ #{config => #{restart_type => bad},
filter_default=>log,
formatter=>{?MODULE,self()}}),
{error,{handler_not_added,{invalid_levels,{_,1,_}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{drop_new_reqs_qlen=>1}}),
+ #{config => #{drop_mode_qlen=>1}}),
{error,{handler_not_added,{invalid_levels,{43,42,_}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{toggle_sync_qlen=>43,
- drop_new_reqs_qlen=>42}}),
+ #{config => #{sync_mode_qlen=>43,
+ drop_mode_qlen=>42}}),
{error,{handler_not_added,{invalid_levels,{_,43,42}}}} =
logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{drop_new_reqs_qlen=>43,
- flush_reqs_qlen=>42}}),
+ #{config => #{drop_mode_qlen=>43,
+ flush_qlen=>42}}),
ok = logger:add_handler(?MODULE,logger_std_h,
#{filter_default=>log,
formatter=>{?MODULE,self()}}),
{error,{illegal_config_change,_,_}} =
- logger:set_handler_config(?MODULE,logger_std_h,
+ logger:set_handler_config(?MODULE,config,
#{type=>{file,"file"}}),
{error,{illegal_config_change,_,_}} =
logger:set_handler_config(?MODULE,id,bad),
{error,{invalid_levels,_}} =
- logger:set_handler_config(?MODULE,logger_std_h,
- #{toggle_sync_qlen=>100,
- flush_reqs_qlen=>99}),
+ logger:set_handler_config(?MODULE,config,
+ #{sync_mode_qlen=>100,
+ flush_qlen=>99}),
{error,{invalid_config,logger_std_h,{filesync_rep_int,2000}}} =
- logger:set_handler_config(?MODULE, logger_std_h,
+ logger:set_handler_config(?MODULE, config,
#{filesync_rep_int => 2000}),
ok.
@@ -329,7 +326,7 @@ crash_std_h_to_file(Config) ->
Log = filename:join(Dir,lists:concat([?MODULE,"_",?FUNCTION_NAME,".log"])),
crash_std_h(Config,?FUNCTION_NAME,
[{handler,default,logger_std_h,
- #{ logger_std_h => #{ type => {file, Log} }}}],
+ #{ config => #{ type => {file, Log} }}}],
file, Log).
crash_std_h_to_file(cleanup,_Config) ->
crash_std_h(cleanup).
@@ -339,7 +336,7 @@ crash_std_h_to_disk_log(Config) ->
Log = filename:join(Dir,lists:concat([?MODULE,"_",?FUNCTION_NAME,".log"])),
crash_std_h(Config,?FUNCTION_NAME,
[{handler,default,logger_disk_log_h,
- #{ disk_log_opts => #{ file => Log }}}],
+ #{ config => #{ file => Log }}}],
disk_log,Log).
crash_std_h_to_disk_log(cleanup,_Config) ->
crash_std_h(cleanup).
@@ -354,7 +351,12 @@ crash_std_h(Config,Func,Var,Type,Log) ->
ct:pal("Starting ~p with ~tp", [Name,Args]),
%% Start a node which prints kernel logs to the destination specified by Type
{ok,Node} = test_server:start_node(Name, peer, [{args, Args}]),
- Pid = rpc:call(Node,erlang,whereis,[?STANDARD_HANDLER]),
+ HProcName =
+ case Type of
+ file -> ?name_to_reg_name(logger_std_h,?STANDARD_HANDLER);
+ disk_log -> ?name_to_reg_name(logger_disk_log_h,?STANDARD_HANDLER)
+ end,
+ Pid = rpc:call(Node,erlang,whereis,[HProcName]),
ok = rpc:call(Node,logger,set_handler_config,[?STANDARD_HANDLER,formatter,
{?MODULE,self()}]),
ok = log_on_remote_node(Node,"dummy1"),
@@ -367,7 +369,7 @@ crash_std_h(Config,Func,Var,Type,Log) ->
%% Wait a bit, then check that it is gone
timer:sleep(2000),
- undefined = rpc:call(Node,erlang,whereis,[?STANDARD_HANDLER]),
+ undefined = rpc:call(Node,erlang,whereis,[HProcName]),
%% Check that file is not empty
{ok,Bin2} = sync_and_read(Node,Type,Log),
@@ -381,7 +383,7 @@ crash_std_h(Config,Func,Var,Type,Log) ->
log_on_remote_node(Node,Msg) ->
_ = spawn_link(Node,
fun() -> erlang:group_leader(whereis(user),self()),
- logger:info(Msg)
+ logger:notice(Msg)
end),
ok.
@@ -391,7 +393,7 @@ crash_std_h(cleanup) ->
[test_server:stop_node(Node) || Node <- Nodes].
sync_and_read(Node,disk_log,Log) ->
- rpc:call(Node,logger_disk_log_h,disk_log_sync,[?STANDARD_HANDLER]),
+ rpc:call(Node,logger_disk_log_h,sync,[?STANDARD_HANDLER]),
case file:read_file(Log ++ ".1") of
{ok,<<>>} ->
timer:sleep(5000),
@@ -400,7 +402,7 @@ sync_and_read(Node,disk_log,Log) ->
Ok
end;
sync_and_read(Node,file,Log) ->
- rpc:call(Node,logger_std_h,filesync,[?STANDARD_HANDLER]),
+ rpc:call(Node,logger_std_h,sync,[?STANDARD_HANDLER]),
case file:read_file(Log) of
{ok,<<>>} ->
timer:sleep(5000),
@@ -410,7 +412,7 @@ sync_and_read(Node,file,Log) ->
end.
bad_input(_Config) ->
- {error,{badarg,{filesync,["BadType"]}}} = logger_std_h:filesync("BadType"),
+ {error,{badarg,{sync,["BadType"]}}} = logger_std_h:sync("BadType"),
{error,{badarg,{info,["BadType"]}}} = logger_std_h:info("BadType"),
{error,{badarg,{reset,["BadType"]}}} = logger_std_h:reset("BadType").
@@ -423,51 +425,51 @@ reconfig(Config) ->
Dir = ?config(priv_dir,Config),
ok = logger:add_handler(?MODULE,
logger_std_h,
- #{logger_std_h => #{type => standard_io},
+ #{config => #{type => standard_io},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}}),
#{id := ?MODULE,
type := standard_io,
file_ctrl_pid := FileCtrlPid,
- toggle_sync_qlen := ?TOGGLE_SYNC_QLEN,
- drop_new_reqs_qlen := ?DROP_NEW_REQS_QLEN,
- flush_reqs_qlen := ?FLUSH_REQS_QLEN,
- enable_burst_limit := ?ENABLE_BURST_LIMIT,
- burst_limit_size := ?BURST_LIMIT_SIZE,
- burst_window_time := ?BURST_WINDOW_TIME,
- enable_kill_overloaded := ?ENABLE_KILL_OVERLOADED,
- handler_overloaded_qlen := ?HANDLER_OVERLOADED_QLEN,
- handler_overloaded_mem := ?HANDLER_OVERLOADED_MEM,
- handler_restart_after := ?HANDLER_RESTART_AFTER,
+ sync_mode_qlen := ?SYNC_MODE_QLEN,
+ drop_mode_qlen := ?DROP_MODE_QLEN,
+ flush_qlen := ?FLUSH_QLEN,
+ burst_limit_enable := ?BURST_LIMIT_ENABLE,
+ burst_limit_max_count := ?BURST_LIMIT_MAX_COUNT,
+ burst_limit_window_time := ?BURST_LIMIT_WINDOW_TIME,
+ overload_kill_enable := ?OVERLOAD_KILL_ENABLE,
+ overload_kill_qlen := ?OVERLOAD_KILL_QLEN,
+ overload_kill_mem_size := ?OVERLOAD_KILL_MEM_SIZE,
+ overload_kill_restart_after := ?OVERLOAD_KILL_RESTART_AFTER,
filesync_repeat_interval := ?FILESYNC_REPEAT_INTERVAL} =
logger_std_h:info(?MODULE),
- ok = logger:set_handler_config(?MODULE, logger_std_h,
- #{toggle_sync_qlen => 1,
- drop_new_reqs_qlen => 2,
- flush_reqs_qlen => 3,
- enable_burst_limit => false,
- burst_limit_size => 10,
- burst_window_time => 10,
- enable_kill_overloaded => true,
- handler_overloaded_qlen => 100000,
- handler_overloaded_mem => 10000000,
- handler_restart_after => never,
+ ok = logger:set_handler_config(?MODULE, config,
+ #{sync_mode_qlen => 1,
+ drop_mode_qlen => 2,
+ flush_qlen => 3,
+ burst_limit_enable => false,
+ burst_limit_max_count => 10,
+ burst_limit_window_time => 10,
+ overload_kill_enable => true,
+ overload_kill_qlen => 100000,
+ overload_kill_mem_size => 10000000,
+ overload_kill_restart_after => never,
filesync_repeat_interval => no_repeat}),
#{id := ?MODULE,
type := standard_io,
file_ctrl_pid := FileCtrlPid,
- toggle_sync_qlen := 1,
- drop_new_reqs_qlen := 2,
- flush_reqs_qlen := 3,
- enable_burst_limit := false,
- burst_limit_size := 10,
- burst_window_time := 10,
- enable_kill_overloaded := true,
- handler_overloaded_qlen := 100000,
- handler_overloaded_mem := 10000000,
- handler_restart_after := never,
+ sync_mode_qlen := 1,
+ drop_mode_qlen := 2,
+ flush_qlen := 3,
+ burst_limit_enable := false,
+ burst_limit_max_count := 10,
+ burst_limit_window_time := 10,
+ overload_kill_enable := true,
+ overload_kill_qlen := 100000,
+ overload_kill_mem_size := 10000000,
+ overload_kill_restart_after := never,
filesync_repeat_interval := no_repeat} = logger_std_h:info(?MODULE),
ok.
@@ -482,19 +484,19 @@ file_opts(Config) ->
BadType = {file,Log,BadFileOpts},
{error,{handler_not_added,{{open_failed,Log,enoent},_}}} =
logger:add_handler(?MODULE, logger_std_h,
- #{logger_std_h => #{type => BadType}}),
+ #{config => #{type => BadType}}),
OkFileOpts = [raw,append],
OkType = {file,Log,OkFileOpts},
ok = logger:add_handler(?MODULE,
logger_std_h,
- #{logger_std_h => #{type => OkType},
+ #{config => #{type => OkType},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}}),
#{type := OkType} = logger_std_h:info(?MODULE),
- logger:info(M1=?msg,?domain),
+ logger:notice(M1=?msg,?domain),
?check(M1),
B1 = ?bin(M1),
try_read_file(Log, {ok,B1}, ?FILESYNC_REP_INT),
@@ -503,13 +505,13 @@ file_opts(cleanup, _Config) ->
logger:remove_handler(?MODULE).
-filesync(Config) ->
+sync(Config) ->
Dir = ?config(priv_dir,Config),
Log = filename:join(Dir, lists:concat([?FUNCTION_NAME,".log"])),
Type = {file,Log},
ok = logger:add_handler(?MODULE,
logger_std_h,
- #{logger_std_h => #{type => Type},
+ #{config => #{type => Type},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,nl}}),
@@ -522,7 +524,7 @@ filesync(Config) ->
{logger_std_h, sync_dev},
{file,datasync}]),
- logger:info("first", ?domain),
+ logger:notice("first", ?domain),
%% wait for automatic filesync
check_tracer(?FILESYNC_REP_INT*2),
@@ -535,16 +537,16 @@ filesync(Config) ->
{file,datasync},
{no_more,500}
]),
- logger:info("second", ?domain),
- %% do explicit filesync
- logger_std_h:filesync(?MODULE),
- %% a second filesync should be ignored
- logger_std_h:filesync(?MODULE),
+ logger:notice("second", ?domain),
+ %% do explicit sync
+ logger_std_h:sync(?MODULE),
+ %% a second sync should be ignored
+ logger_std_h:sync(?MODULE),
check_tracer(100),
%% check that if there's no repeated filesync active,
%% a filesync is still performed when handler goes idle
- logger:set_handler_config(?MODULE, logger_std_h,
+ logger:set_handler_config(?MODULE, config,
#{filesync_repeat_interval => no_repeat}),
no_repeat = maps:get(filesync_repeat_interval, logger_std_h:info(?MODULE)),
%% The following timer is to make sure the time from last log
@@ -560,10 +562,10 @@ filesync(Config) ->
{logger_std_h, write_to_dev, <<"fourth\n">>},
{logger_std_h, sync_dev},
{file,datasync}]),
- logger:info("third", ?domain),
+ logger:notice("third", ?domain),
%% wait for automatic filesync
timer:sleep(?IDLE_DETECT_TIME_MSEC*2),
- logger:info("fourth", ?domain),
+ logger:notice("fourth", ?domain),
%% wait for automatic filesync
check_tracer(?IDLE_DETECT_TIME_MSEC*2),
@@ -575,15 +577,15 @@ filesync(Config) ->
start_tracer([{logger_std_h,handle_cast,2}],
[OneSync || _ <- lists:seq(1, 1 + trunc(WaitT/SyncInt))]),
- logger:set_handler_config(?MODULE, logger_std_h,
+ logger:set_handler_config(?MODULE, config,
#{filesync_repeat_interval => SyncInt}),
SyncInt = maps:get(filesync_repeat_interval, logger_std_h:info(?MODULE)),
timer:sleep(WaitT),
- logger:set_handler_config(?MODULE, logger_std_h,
+ logger:set_handler_config(?MODULE, config,
#{filesync_repeat_interval => no_repeat}),
check_tracer(100),
ok.
-filesync(cleanup, _Config) ->
+sync(cleanup, _Config) ->
dbg:stop_clear(),
logger:remove_handler(?MODULE).
@@ -598,7 +600,7 @@ write_failure(Config) ->
rpc:call(Node, ?MODULE, set_result, [file_write,ok]),
ok = log_on_remote_node(Node, "Logged1"),
- rpc:call(Node, logger_std_h, filesync, [?STANDARD_HANDLER]),
+ rpc:call(Node, logger_std_h, sync, [?STANDARD_HANDLER]),
?check_no_log,
try_read_file(Log, {ok,<<"Logged1\n">>}, ?FILESYNC_REP_INT),
@@ -616,7 +618,7 @@ write_failure(Config) ->
rpc:call(Node, ?MODULE, set_result, [file_write,ok]),
ok = log_on_remote_node(Node, "Logged2"),
- rpc:call(Node, logger_std_h, filesync, [?STANDARD_HANDLER]),
+ rpc:call(Node, logger_std_h, sync, [?STANDARD_HANDLER]),
?check_no_log,
try_read_file(Log, {ok,<<"Logged1\nLogged2\n">>}, ?FILESYNC_REP_INT),
ok.
@@ -636,7 +638,7 @@ sync_failure(Config) ->
SyncInt = 500,
ok = rpc:call(Node, logger, set_handler_config,
- [?STANDARD_HANDLER, logger_std_h,
+ [?STANDARD_HANDLER, config,
#{filesync_repeat_interval => SyncInt}]),
Info = rpc:call(Node, logger_std_h, info, [?STANDARD_HANDLER]),
SyncInt = maps:get(filesync_repeat_interval, Info),
@@ -647,14 +649,14 @@ sync_failure(Config) ->
rpc:call(Node, ?MODULE, set_result, [file_datasync,{error,terminated}]),
ok = log_on_remote_node(Node, "Cause simple error printout"),
- ?check({error,{?STANDARD_HANDLER,filesync,Log,{error,terminated}}}),
+ ?check({error,{?STANDARD_HANDLER,sync,Log,{error,terminated}}}),
ok = log_on_remote_node(Node, "No second error printout"),
?check_no_log,
rpc:call(Node, ?MODULE, set_result, [file_datasync,{error,eacces}]),
ok = log_on_remote_node(Node, "Cause simple error printout"),
- ?check({error,{?STANDARD_HANDLER,filesync,Log,{error,eacces}}}),
+ ?check({error,{?STANDARD_HANDLER,sync,Log,{error,eacces}}}),
rpc:call(Node, ?MODULE, set_result, [file_datasync,ok]),
ok = log_on_remote_node(Node, "Logged2"),
@@ -669,7 +671,7 @@ start_std_h_on_new_node(Config, Log) ->
logger_test_lib:setup(
Config,
[{logger,[{handler,default,logger_std_h,
- #{ logger_std_h => #{ type => {file,Log}}}}]}]),
+ #{ config => #{ type => {file,Log}}}}]}]),
ok = rpc:call(Node,logger,set_handler_config,[?STANDARD_HANDLER,formatter,
{?MODULE,nl}]),
Node.
@@ -697,15 +699,15 @@ op_switch_to_sync_file(Config) ->
{Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NumOfReqs = 500,
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{toggle_sync_qlen => 2,
- drop_new_reqs_qlen => NumOfReqs+1,
- flush_reqs_qlen => 2*NumOfReqs,
- enable_burst_limit => false}},
+ HConfig#{config => StdHConfig#{sync_mode_qlen => 2,
+ drop_mode_qlen => NumOfReqs+1,
+ flush_qlen => 2*NumOfReqs,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
%% TRecvPid = start_op_trace(),
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Lines = count_lines(Log),
- ok = file:delete(Log),
+ ok = file_delete(Log),
%% true = analyse_trace(TRecvPid,
%% fun(Events) -> find_mode(async,Events) end),
%% true = analyse_trace(TRecvPid,
@@ -726,12 +728,12 @@ op_switch_to_sync_tty(Config) ->
{HConfig,StdHConfig} = start_handler(?MODULE, standard_io, Config),
NumOfReqs = 500,
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{toggle_sync_qlen => 3,
- drop_new_reqs_qlen => NumOfReqs+1,
- flush_reqs_qlen => 2*NumOfReqs,
- enable_burst_limit => false}},
+ HConfig#{config => StdHConfig#{sync_mode_qlen => 3,
+ drop_mode_qlen => NumOfReqs+1,
+ flush_qlen => 2*NumOfReqs,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
ok.
op_switch_to_sync_tty(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -747,22 +749,22 @@ op_switch_to_drop_file(Config) ->
Procs = 2,
Bursts = 10,
NewHConfig =
- HConfig#{logger_std_h =>
- StdHConfig#{toggle_sync_qlen => 1,
- drop_new_reqs_qlen => 2,
- flush_reqs_qlen =>
+ HConfig#{config =>
+ StdHConfig#{sync_mode_qlen => 1,
+ drop_mode_qlen => 2,
+ flush_qlen =>
Procs*NumOfReqs*Bursts,
- enable_burst_limit => false}},
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
%% It sometimes happens that the handler gets the
%% requests in a slow enough pace so that dropping
%% never occurs. Therefore, lets generate a number of
%% bursts to increase the chance of message buildup.
- [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info) ||
+ [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice) ||
_ <- lists:seq(1, Bursts)],
Logged = count_lines(Log),
ok = stop_handler(?MODULE),
- _ = file:delete(Log),
+ _ = file_delete(Log),
ct:pal("Number of messages dropped = ~w (~w)",
[Procs*NumOfReqs*Bursts-Logged,Procs*NumOfReqs*Bursts]),
true = (Logged < (Procs*NumOfReqs*Bursts)),
@@ -785,19 +787,19 @@ op_switch_to_drop_tty(Config) ->
NumOfReqs = 300,
Procs = 2,
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{toggle_sync_qlen => 1,
- drop_new_reqs_qlen => 2,
- flush_reqs_qlen =>
- Procs*NumOfReqs+1,
- enable_burst_limit => false}},
+ HConfig#{config => StdHConfig#{sync_mode_qlen => 1,
+ drop_mode_qlen => 2,
+ flush_qlen =>
+ Procs*NumOfReqs+1,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
- send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info),
+ send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice),
ok.
op_switch_to_drop_tty(cleanup, _Config) ->
ok = stop_handler(?MODULE).
op_switch_to_flush_file() ->
- [{timetrap,{minutes,3}}].
+ [{timetrap,{minutes,5}}].
op_switch_to_flush_file(Config) ->
Test =
fun() ->
@@ -809,12 +811,12 @@ op_switch_to_flush_file(Config) ->
%% (verify with coverage of flush_log_requests/2)
NewHConfig =
- HConfig#{logger_std_h =>
- StdHConfig#{toggle_sync_qlen => 2,
+ HConfig#{config =>
+ StdHConfig#{sync_mode_qlen => 2,
%% disable drop mode
- drop_new_reqs_qlen => 300,
- flush_reqs_qlen => 300,
- enable_burst_limit => false}},
+ drop_mode_qlen => 300,
+ flush_qlen => 300,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 1500,
Procs = 10,
@@ -826,11 +828,11 @@ op_switch_to_flush_file(Config) ->
%% sync messages gets tested). Therefore, lets
%% generate a number of bursts to increase the chance
%% of message buildup in some random fashion.
- [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info) ||
+ [send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice) ||
_ <- lists:seq(1,Bursts)],
Logged = count_lines(Log),
ok = stop_handler(?MODULE),
- _ = file:delete(Log),
+ _ = file_delete(Log),
ct:pal("Number of messages flushed/dropped = ~w (~w)",
[NumOfReqs*Procs*Bursts-Logged,NumOfReqs*Procs*Bursts]),
true = (Logged < (NumOfReqs*Procs*Bursts)),
@@ -848,6 +850,8 @@ op_switch_to_flush_file(Config) ->
op_switch_to_flush_file(cleanup, _Config) ->
_ = stop_handler(?MODULE).
+op_switch_to_flush_tty() ->
+ [{timetrap,{minutes,5}}].
op_switch_to_flush_tty(Config) ->
{HConfig,StdHConfig} = start_handler(?MODULE, standard_io, Config),
@@ -855,15 +859,15 @@ op_switch_to_flush_tty(Config) ->
%% when the flush happens (verify with coverage of flush_log_requests/2)
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{toggle_sync_qlen => 2,
- %% disable drop mode
- drop_new_reqs_qlen => 100,
- flush_reqs_qlen => 100,
- enable_burst_limit => false}},
+ HConfig#{config => StdHConfig#{sync_mode_qlen => 2,
+ %% disable drop mode
+ drop_mode_qlen => 100,
+ flush_qlen => 100,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 1000,
Procs = 100,
- send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info),
+ send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice),
ok.
op_switch_to_flush_tty(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -871,17 +875,17 @@ op_switch_to_flush_tty(cleanup, _Config) ->
limit_burst_disabled(Config) ->
{Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{enable_burst_limit => false,
- burst_limit_size => 10,
- burst_window_time => 2000,
- drop_new_reqs_qlen => 200,
- flush_reqs_qlen => 300}},
+ HConfig#{config => StdHConfig#{burst_limit_enable => false,
+ burst_limit_max_count => 10,
+ burst_limit_window_time => 2000,
+ drop_mode_qlen => 200,
+ flush_qlen => 300}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 100,
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages logged = ~w", [Logged]),
- ok = file:delete(Log),
+ ok = file_delete(Log),
NumOfReqs = Logged.
limit_burst_disabled(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -890,17 +894,17 @@ limit_burst_enabled_one(Config) ->
{Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
ReqLimit = 10,
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{enable_burst_limit => true,
- burst_limit_size => ReqLimit,
- burst_window_time => 2000,
- drop_new_reqs_qlen => 200,
- flush_reqs_qlen => 300}},
+ HConfig#{config => StdHConfig#{burst_limit_enable => true,
+ burst_limit_max_count => ReqLimit,
+ burst_limit_window_time => 2000,
+ drop_mode_qlen => 200,
+ flush_qlen => 300}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 100,
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages logged = ~w", [Logged]),
- ok = file:delete(Log),
+ ok = file_delete(Log),
ReqLimit = Logged.
limit_burst_enabled_one(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -910,19 +914,19 @@ limit_burst_enabled_period(Config) ->
ReqLimit = 10,
BurstTWin = 1000,
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{enable_burst_limit => true,
- burst_limit_size => ReqLimit,
- burst_window_time => BurstTWin,
- drop_new_reqs_qlen => 20000,
- flush_reqs_qlen => 20001}},
+ HConfig#{config => StdHConfig#{burst_limit_enable => true,
+ burst_limit_max_count => ReqLimit,
+ burst_limit_window_time => BurstTWin,
+ drop_mode_qlen => 20000,
+ flush_qlen => 20001}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
Windows = 3,
- Sent = send_burst({t,BurstTWin*Windows}, seq, {chars,79}, info),
+ Sent = send_burst({t,BurstTWin*Windows}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages sent = ~w~nNumber of messages logged = ~w",
[Sent,Logged]),
- ok = file:delete(Log),
+ ok = file_delete(Log),
true = (Logged > (ReqLimit*Windows)) andalso
(Logged < (ReqLimit*(Windows+2))).
limit_burst_enabled_period(cleanup, _Config) ->
@@ -931,36 +935,36 @@ limit_burst_enabled_period(cleanup, _Config) ->
kill_disabled(Config) ->
{Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig =
- HConfig#{logger_std_h=>StdHConfig#{enable_kill_overloaded=>false,
- handler_overloaded_qlen=>10,
- handler_overloaded_mem=>100}},
+ HConfig#{config=>StdHConfig#{overload_kill_enable=>false,
+ overload_kill_qlen=>10,
+ overload_kill_mem_size=>100}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
NumOfReqs = 100,
- send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
Logged = count_lines(Log),
ct:pal("Number of messages logged = ~w", [Logged]),
- ok = file:delete(Log),
- true = is_pid(whereis(?MODULE)),
+ ok = file_delete(Log),
+ true = is_pid(whereis(h_proc_name())),
ok.
kill_disabled(cleanup, _Config) ->
ok = stop_handler(?MODULE).
qlen_kill_new(Config) ->
{_Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
- Pid0 = whereis(?MODULE),
+ Pid0 = whereis(h_proc_name()),
{_,Mem0} = process_info(Pid0, memory),
- RestartAfter = ?HANDLER_RESTART_AFTER,
+ RestartAfter = ?OVERLOAD_KILL_RESTART_AFTER,
NewHConfig =
- HConfig#{logger_std_h=>StdHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>10,
- handler_overloaded_mem=>Mem0+50000,
- handler_restart_after=>RestartAfter}},
+ HConfig#{config=>StdHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>10,
+ overload_kill_mem_size=>Mem0+50000,
+ overload_kill_restart_after=>RestartAfter}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
MRef = erlang:monitor(process, Pid0),
NumOfReqs = 100,
Procs = 2,
- send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info),
- %% send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice),
+ %% send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
receive
{'DOWN', MRef, _, _, Info} ->
case Info of
@@ -970,7 +974,7 @@ qlen_kill_new(Config) ->
ct:pal("Slow shutdown, handler process was killed!", [])
end,
timer:sleep(RestartAfter + 2000),
- true = is_pid(whereis(?MODULE)),
+ true = is_pid(whereis(h_proc_name())),
ok
after
5000 ->
@@ -990,28 +994,28 @@ qlen_kill_std(_Config) ->
%% Log = filename:join(Dir, File),
%% Node = start_std_h_on_new_node(Config, ?FUNCTION_NAME, Log),
%% ok = rpc:call(Node, logger, set_handler_config,
- %% [?STANDARD_HANDLER, logger_std_h,
- %% #{enable_kill_overloaded=>true,
- %% handler_overloaded_qlen=>10,
- %% handler_overloaded_mem=>100000}]),
+ %% [?STANDARD_HANDLER, config,
+ %% #{overload_kill_enable=>true,
+ %% overload_kill_qlen=>10,
+ %% overload_kill_mem_size=>100000}]),
{skip,"Not done yet"}.
mem_kill_new(Config) ->
{_Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
- Pid0 = whereis(?MODULE),
+ Pid0 = whereis(h_proc_name()),
{_,Mem0} = process_info(Pid0, memory),
- RestartAfter = ?HANDLER_RESTART_AFTER,
+ RestartAfter = ?OVERLOAD_KILL_RESTART_AFTER,
NewHConfig =
- HConfig#{logger_std_h=>StdHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>50000,
- handler_overloaded_mem=>Mem0+500,
- handler_restart_after=>RestartAfter}},
+ HConfig#{config=>StdHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>50000,
+ overload_kill_mem_size=>Mem0+500,
+ overload_kill_restart_after=>RestartAfter}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
MRef = erlang:monitor(process, Pid0),
NumOfReqs = 100,
Procs = 2,
- send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, info),
- %% send_burst({n,NumOfReqs}, seq, {chars,79}, info),
+ send_burst({n,NumOfReqs}, {spawn,Procs,0}, {chars,79}, notice),
+ %% send_burst({n,NumOfReqs}, seq, {chars,79}, notice),
receive
{'DOWN', MRef, _, _, Info} ->
case Info of
@@ -1021,7 +1025,7 @@ mem_kill_new(Config) ->
ct:pal("Slow shutdown, handler process was killed!", [])
end,
timer:sleep(RestartAfter * 3),
- true = is_pid(whereis(?MODULE)),
+ true = is_pid(whereis(h_proc_name())),
ok
after
5000 ->
@@ -1040,17 +1044,17 @@ mem_kill_std(_Config) ->
restart_after(Config) ->
{Log,HConfig,StdHConfig} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig1 =
- HConfig#{logger_std_h=>StdHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>10,
- handler_restart_after=>never}},
+ HConfig#{config=>StdHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>10,
+ overload_kill_restart_after=>never}},
ok = logger:set_handler_config(?MODULE, NewHConfig1),
- MRef1 = erlang:monitor(process, whereis(?MODULE)),
+ MRef1 = erlang:monitor(process, whereis(h_proc_name())),
%% kill handler
- send_burst({n,100}, {spawn,2,0}, {chars,79}, info),
+ send_burst({n,100}, {spawn,2,0}, {chars,79}, notice),
receive
{'DOWN', MRef1, _, _, _Info1} ->
- timer:sleep(?HANDLER_RESTART_AFTER + 1000),
- undefined = whereis(?MODULE),
+ timer:sleep(?OVERLOAD_KILL_RESTART_AFTER + 1000),
+ undefined = whereis(h_proc_name()),
ok
after
5000 ->
@@ -1058,20 +1062,20 @@ restart_after(Config) ->
end,
{Log,_,_} = start_handler(?MODULE, ?FUNCTION_NAME, Config),
- RestartAfter = ?HANDLER_RESTART_AFTER,
+ RestartAfter = ?OVERLOAD_KILL_RESTART_AFTER,
NewHConfig2 =
- HConfig#{logger_std_h=>StdHConfig#{enable_kill_overloaded=>true,
- handler_overloaded_qlen=>10,
- handler_restart_after=>RestartAfter}},
+ HConfig#{config=>StdHConfig#{overload_kill_enable=>true,
+ overload_kill_qlen=>10,
+ overload_kill_restart_after=>RestartAfter}},
ok = logger:set_handler_config(?MODULE, NewHConfig2),
- Pid0 = whereis(?MODULE),
+ Pid0 = whereis(h_proc_name()),
MRef2 = erlang:monitor(process, Pid0),
%% kill handler
- send_burst({n,100}, {spawn,2,0}, {chars,79}, info),
+ send_burst({n,100}, {spawn,2,0}, {chars,79}, notice),
receive
{'DOWN', MRef2, _, _, _Info2} ->
timer:sleep(RestartAfter + 2000),
- Pid1 = whereis(?MODULE),
+ Pid1 = whereis(h_proc_name()),
true = is_pid(Pid1),
false = (Pid1 == Pid0),
ok
@@ -1083,7 +1087,7 @@ restart_after(Config) ->
restart_after(cleanup, _Config) ->
ok = stop_handler(?MODULE).
-%% send handler requests (filesync, info, reset, change_config)
+%% send handler requests (sync, info, reset, change_config)
%% during high load to verify that sync, dropping and flushing is
%% handled correctly.
handler_requests_under_load() ->
@@ -1092,17 +1096,17 @@ handler_requests_under_load(Config) ->
{Log,HConfig,StdHConfig} =
start_handler(?MODULE, ?FUNCTION_NAME, Config),
NewHConfig =
- HConfig#{logger_std_h => StdHConfig#{toggle_sync_qlen => 2,
- drop_new_reqs_qlen => 1000,
- flush_reqs_qlen => 2000,
- enable_burst_limit => false}},
+ HConfig#{config => StdHConfig#{sync_mode_qlen => 2,
+ drop_mode_qlen => 1000,
+ flush_qlen => 2000,
+ burst_limit_enable => false}},
ok = logger:set_handler_config(?MODULE, NewHConfig),
- Pid = spawn_link(fun() -> send_requests(?MODULE, 1, [{filesync,[]},
+ Pid = spawn_link(fun() -> send_requests(?MODULE, 1, [{sync,[]},
{info,[]},
{reset,[]},
{change_config,[]}])
end),
- Sent = send_burst({t,10000}, seq, {chars,79}, info),
+ Sent = send_burst({t,10000}, seq, {chars,79}, notice),
Pid ! {self(),finish},
ReqResult = receive {Pid,Result} -> Result end,
Logged = count_lines(Log),
@@ -1115,7 +1119,7 @@ handler_requests_under_load(Config) ->
Errors = [{Req,FindError(Res)} || {Req,Res} <- ReqResult],
NoOfReqs = lists:foldl(fun({_,Res}, N) -> N + length(Res) end, 0, ReqResult),
ct:pal("~w requests made. Errors: ~n~p", [NoOfReqs,Errors]),
- ok = file:delete(Log).
+ ok = file_delete(Log).
handler_requests_under_load(cleanup, _Config) ->
ok = stop_handler(?MODULE).
@@ -1128,8 +1132,8 @@ send_requests(HName, TO, Reqs = [{Req,Res}|Rs]) ->
Result =
case Req of
change_config ->
- logger:set_handler_config(HName, logger_std_h,
- #{enable_kill_overloaded =>
+ logger:set_handler_config(HName, config,
+ #{overload_kill_enable =>
false});
Func ->
logger_std_h:Func(HName)
@@ -1144,12 +1148,11 @@ start_handler(Name, TTY, Config) when TTY == standard_io;
TTY == standard_error->
ok = logger:add_handler(Name,
logger_std_h,
- #{logger_std_h => #{type => TTY},
+ #{config => #{type => TTY},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([Name]),
formatter=>{?MODULE,op}}),
- {ok,{_,HConfig = #{logger_std_h := StdHConfig}}} =
- logger:get_handler_config(Name),
+ {ok,HConfig = #{config := StdHConfig}} = logger:get_handler_config(Name),
{HConfig,StdHConfig};
start_handler(Name, FuncName, Config) ->
@@ -1159,12 +1162,11 @@ start_handler(Name, FuncName, Config) ->
Type = {file,Log},
ok = logger:add_handler(Name,
logger_std_h,
- #{logger_std_h => #{type => Type},
+ #{config => #{type => Type},
filter_default=>log,
filters=>?DEFAULT_HANDLER_FILTERS([Name]),
formatter=>{?MODULE,op}}),
- {ok,{_,HConfig = #{logger_std_h := StdHConfig}}} =
- logger:get_handler_config(Name),
+ {ok,HConfig = #{config := StdHConfig}} = logger:get_handler_config(Name),
{Log,HConfig,StdHConfig}.
stop_handler(Name) ->
@@ -1192,17 +1194,21 @@ wait_until_written(File, Sz) ->
end.
count_lines1(File) ->
- Counter = fun Cnt(Dev,LC) ->
- case file:read_line(Dev) of
- eof -> LC;
- _ -> Cnt(Dev,LC+1)
- end
- end,
{_,Dev} = file:open(File, [read]),
- Lines = Counter(Dev, 0),
+ Lines = count_lines2(Dev, 0),
file:close(Dev),
Lines.
+count_lines2(Dev, LC) ->
+ case file:read_line(Dev) of
+ {ok,"Handler logger_std_h_SUITE " ++_} ->
+ %% Not counting handler info
+ count_lines2(Dev,LC);
+ {ok,_} ->
+ count_lines2(Dev,LC+1);
+ eof -> LC
+ end.
+
send_burst(NorT, Type, {chars,Sz}, Class) ->
Text = [34 + rand:uniform(126-34) || _ <- lists:seq(1,Sz)],
case NorT of
@@ -1271,9 +1277,11 @@ format(#{msg:={report,#{label:={gen_server,terminate}}}},op) ->
"";
format(#{msg:={report,#{label:={proc_lib,crash}}}},op) ->
"";
-format(#{msg:={F,A}},Pid) when is_list(F), is_list(A) ->
+format(#{msg:={F,A}},OpOrPid) when is_list(F), is_list(A) ->
String = lists:flatten(io_lib:format(F,A)),
- Pid ! {log,String},
+ if is_pid(OpOrPid) -> OpOrPid ! {log,String};
+ true -> ok
+ end,
String++"\n";
format(#{msg:={string,String0}},Pid) ->
String = unicode:characters_to_list(String0),
@@ -1282,21 +1290,21 @@ format(#{msg:={string,String0}},Pid) ->
add_remove_instance_nofile(Type) ->
ok = logger:add_handler(?MODULE,logger_std_h,
- #{logger_std_h => #{type => Type},
+ #{config => #{type => Type},
filter_default=>stop,
filters=>?DEFAULT_HANDLER_FILTERS([?MODULE]),
formatter=>{?MODULE,self()}}),
- Pid = whereis(?MODULE),
+ Pid = whereis(h_proc_name()),
true = is_pid(Pid),
group_leader(group_leader(),Pid), % to get printouts in test log
- logger:info(M1=?msg,?domain),
+ logger:notice(M1=?msg,?domain),
?check(M1),
- %% check that filesync doesn't do damage even if not relevant
- ok = logger_std_h:filesync(?MODULE),
+ %% check that sync doesn't do damage even if not relevant
+ ok = logger_std_h:sync(?MODULE),
ok = logger:remove_handler(?MODULE),
timer:sleep(500),
- undefined = whereis(?MODULE),
- logger:info(?msg,?domain),
+ undefined = whereis(h_proc_name()),
+ logger:notice(?msg,?domain),
?check_no_log,
ok.
@@ -1379,7 +1387,7 @@ start_op_trace() ->
TRecvPid = spawn_link(fun() -> trace_receiver(5000) end),
{ok,_} = dbg:tracer(process, {TraceFun, TRecvPid}),
- {ok,_} = dbg:p(whereis(?MODULE), [c]),
+ {ok,_} = dbg:p(whereis(h_proc_name()), [c]),
{ok,_} = dbg:p(self(), [c]),
MS1 = dbg:fun2ms(fun([_]) -> return_trace() end),
@@ -1459,7 +1467,7 @@ start_tracer(Trace,Expected) ->
Pid = self(),
FileCtrlPid = maps:get(file_ctrl_pid, logger_std_h:info(?MODULE)),
dbg:tracer(process,{fun tracer/2,{Pid,Expected}}),
- dbg:p(whereis(?MODULE),[c]),
+ dbg:p(whereis(h_proc_name()),[c]),
dbg:p(FileCtrlPid,[c]),
tpl(Trace),
ok.
@@ -1525,3 +1533,11 @@ escape([H|T]) ->
[H|escape(T)];
escape([]) ->
[].
+
+h_proc_name() ->
+ h_proc_name(?MODULE).
+h_proc_name(Name) ->
+ ?name_to_reg_name(logger_std_h,Name).
+
+file_delete(Log) ->
+ file:delete(Log).
diff --git a/lib/kernel/test/logger_test_lib.erl b/lib/kernel/test/logger_test_lib.erl
index 4ac05e6480..9097453c10 100644
--- a/lib/kernel/test/logger_test_lib.erl
+++ b/lib/kernel/test/logger_test_lib.erl
@@ -37,7 +37,7 @@ setup(Config,Vars) ->
" -boot start_sasl -kernel start_timer true "
"-config ",ConfigFileName]}]) of
{ok, Node} ->
- L = rpc:call(Node, logger, i, []),
+ L = rpc:call(Node, logger, get_config, []),
ct:log("~p",[L]),
{ok, L, Node};
{error, Reason} ->
@@ -52,10 +52,10 @@ log(Node, M, F, A) ->
rpc:call(Node, M, F, A ++ [MD]).
sync_and_read(Node,disk_log,Log) ->
- rpc:call(Node,logger_disk_log_h,disk_log_sync,[?STANDARD_HANDLER]),
+ rpc:call(Node,logger_disk_log_h,sync,[?STANDARD_HANDLER]),
file:read_file(Log ++ ".1");
sync_and_read(Node, file,Log) ->
- ok = rpc:call(Node,logger_std_h,filesync,[?STANDARD_HANDLER]),
+ ok = rpc:call(Node,logger_std_h,sync,[?STANDARD_HANDLER]),
file:read_file(Log).
diff --git a/lib/public_key/doc/src/public_key.xml b/lib/public_key/doc/src/public_key.xml
index 5d57109140..524869df16 100644
--- a/lib/public_key/doc/src/public_key.xml
+++ b/lib/public_key/doc/src/public_key.xml
@@ -969,35 +969,76 @@ fun(#'DistributionPoint'{}, #'CertificateList'{},
</type>
<desc>
<p>This function checks that the <i>Presented Identifier</i> (e.g hostname) in a peer certificate
- is in agreement with the <i>Reference Identifier</i> that the client expects to be connected to.
+ is in agreement with at least one of the <i>Reference Identifier</i> that the client expects to be connected to.
The function is intended to be added as an extra client check of the peer certificate when performing
<seealso marker="public_key:public_key#pkix_path_validation-3">public_key:pkix_path_validation/3</seealso>
</p>
<p>See <url href="https://tools.ietf.org/html/rfc6125">RFC 6125</url>
for detailed information about hostname verification.
- The <seealso marker="using_public_key#verify_hostname">User's Manual</seealso>
+ The <seealso marker="using_public_key#verify_hostname">User's Guide</seealso>
and
<seealso marker="using_public_key#verify_hostname_examples">code examples</seealso>
describes this function more detailed.
</p>
<p>The <c>{OtherRefId,term()}</c> is defined by the user and is passed to the <c>match_fun</c>, if defined.
- If that term is a binary, it will be converted to a string.
+ If the term in <c>OtherRefId</c> is a binary, it will be converted to a string.
</p>
<p>The <c>ip</c> Reference ID takes an <seealso marker="inet:inet#type-ip_address">inet:ip_address()</seealso>
or an ip address in string format (E.g "10.0.1.1" or "1234::5678:9012") as second element.
</p>
- <p>See <seealso marker="#pkix_verify_hostname_match_fun-1">pkix_verify_hostname_match_fun/1</seealso> for a
- function that return a fun suitable for this option.
- </p>
+ <p>The options are:</p>
+ <taglist>
+ <tag><c>match_fun</c></tag>
+ <item>
+ The <c>fun/2</c> in this option replaces the default host name matching rules. The fun should return a
+ boolean to tell if the Reference ID and Presented ID matches or not. The fun can also return a third
+ value, the atom <c>default</c>, if the default matching rules shall apply.
+ This makes it possible to augment the tests with a special case:
+ <code>
+fun(....) -> true; % My special case
+ (_, _) -> default % all others falls back to the inherit tests
+end
+ </code>
+ <br/>See <seealso marker="#pkix_verify_hostname_match_fun-1">pkix_verify_hostname_match_fun/1</seealso> for a
+ function that takes a protocol name as argument and returns a <c>fun/2</c> suitable for this option and
+ <seealso marker="using_public_key#redefining_match_op">Re-defining the match operation</seealso>
+ in the User's Guide for an example.
+ </item>
+
+ <tag><c>fail_callback</c></tag>
+ <item>If a matching fails, there could be circumstances when the certificate should be accepted anyway. Think for
+ example of a web browser where you choose to accept an outdated certificate. This option enables implementation
+ of such a function. This <c>fun/1</c> is called when no <c>ReferenceID</c> matches. The return value of the fun
+ (a <c>boolean()</c>) decides the outcome. If <c>true</c> the the certificate is accepted otherwise
+ it is rejected. See
+ <seealso marker="using_public_key#-pinning--a-certificate">"Pinning" a Certificate</seealso>
+ in the User's Guide.
+ </item>
+
+ <tag><c>fqdn_fun</c></tag>
+ <item>This option augments the host name extraction from URIs and other Reference IDs. It could for example be
+ a very special URI that is not standardised. The fun takes a Reference ID as argument and returns one of:
+ <list>
+ <item>the hostname</item>
+ <item>the atom <c>default</c>: the default host name extract function will be used</item>
+ <item>the atom <c>undefined</c>: a host name could not be extracted. The pkix_verify_hostname/3
+ will return <c>false</c>.</item>
+ </list>
+ <br/>For an example, see
+ <seealso marker="using_public_key#hostname_extraction">Hostname extraction</seealso>
+ in the User's Guide.
+ </item>
+ </taglist>
+
</desc>
</func>
<func>
- <name>pkix_verify_hostname_match_fun(Alg) -> fun(RefId | FQDN::string(), PresentedID) -> boolean() | default</name>
+ <name>pkix_verify_hostname_match_fun(Protcol) -> fun(RefId | FQDN::string(), PresentedID) -> boolean() | default</name>
<fsummary>Returns a fun that is intendended as argument to the match_fun option in pkix_verify_hostname/3.
</fsummary>
<type>
- <v>Alg = https</v>
+ <v>Protocol = https</v>
<d>The algorithm for wich the fun should implement the special matching rules</d>
<v>RefId</v>
<d>See <seealso marker="#pkix_verify_hostname-3">pkix_verify_hostname/3</seealso>.</d>
diff --git a/lib/public_key/doc/src/using_public_key.xml b/lib/public_key/doc/src/using_public_key.xml
index 417d479da3..b936b7fcb5 100644
--- a/lib/public_key/doc/src/using_public_key.xml
+++ b/lib/public_key/doc/src/using_public_key.xml
@@ -570,6 +570,7 @@ true = public_key:verify(Digest, none, Signature, PublicKey),</code>
<c>fqdn_fun</c> and <c>match_fun</c>.
</p>
<section>
+ <marker id="hostname_extraction"></marker>
<title>Hostname extraction</title>
<p>The <c>fqdn_fun</c> extracts hostnames (Fully Qualified Domain Names) from uri_id
or other ReferenceIDs that are not pre-defined in the public_key function.
@@ -595,7 +596,8 @@ true = public_key:verify(Digest, none, Signature, PublicKey),</code>
</code>
</section>
<section>
- <title>Re-defining the match operations</title>
+ <marker id="redefining_match_op"></marker>
+ <title>Re-defining the match operation</title>
<p>The default matching handles dns_id and uri_id. In an uri_id the value is tested for
equality with a value from the <c>Subject Alternate Name</c>. If som other kind of matching
is needed, use the <c>match_fun</c> option.
diff --git a/lib/sasl/doc/src/error_logging.xml b/lib/sasl/doc/src/error_logging.xml
index 8731b73599..356b1f98e9 100644
--- a/lib/sasl/doc/src/error_logging.xml
+++ b/lib/sasl/doc/src/error_logging.xml
@@ -33,8 +33,8 @@
<file>error_logging.xml</file>
</header>
<note>
- <p>The SASL error logging concept desribed in this section is
- deprecated since OTP-21, when the
+ <p>The SASL error logging concept described in this section is
+ deprecated since Erlang/OTP 21.0, when the
new <seealso marker="kernel:logger_chapter">logging
API</seealso> was introduced.</p>
<p>The new default behaviour is that the SASL application no
@@ -45,9 +45,10 @@
which is setup by
Kernel. <seealso marker="#progress_report">Progress
reports</seealso> are by default not logged, but can be enabled
- by setting the Kernel configuration
- parameter <seealso marker="kernel:kernel_app#logger_progress_reports">
- <c>logger_progress_reports</c></seealso> to <c>log</c>.</p>
+ by setting the primary log level to <c>info</c>, for example by
+ using the Kernel configuration
+ parameter <seealso marker="kernel:kernel_app#logger_level">
+ <c>logger_level</c></seealso>.</p>
<p>The old SASL error logging behaviour can be re-enabled by setting the
Kernel configuration
parameter <seealso marker="kernel:kernel_app#logger_sasl_compatible">
@@ -70,10 +71,10 @@
<item>Progress report</item>
<item>Crash report</item>
</list>
- <p>When the SASL application is started, it adds a logger handler
+ <p>When the SASL application is started, it adds a Logger handler
that formats and writes these reports, as specified in
the <seealso marker="sasl_app#deprecated_error_logger_config">configuration
- parameters for SASL</seealso></p>
+ parameters for SASL</seealso>.</p>
<section>
<marker id="supervisor_report"/>
diff --git a/lib/sasl/doc/src/sasl_app.xml b/lib/sasl/doc/src/sasl_app.xml
index be275879ee..6f3b4fd7b0 100644
--- a/lib/sasl/doc/src/sasl_app.xml
+++ b/lib/sasl/doc/src/sasl_app.xml
@@ -102,10 +102,11 @@
reports</em>, <em>crash reports</em>, and <em>progress
reports</em>. These reports are now also printed by the default
logger handler started by the Kernel application. Progress
- reports are by default stopped by a filter, but can be
- added by setting the Kernel configuration
- parameter <seealso marker="kernel:kernel_app#logger_progress_reports">
- <c>logger_progress_reports</c></seealso> to <c>log</c>.</p>
+ reports are by default stopped by the primary log level, but can
+ be enabled by setting this level to <c>info</c>, for example by
+ using the Kernel configuration
+ parameter <seealso marker="kernel:kernel_app#logger_level">
+ <c>logger_level</c></seealso>.</p>
<p>If the old error logger event handlers are still desired, they
must be added by
calling <c>error_logger:add_report_handler/1,2</c>.</p>
@@ -131,14 +132,13 @@
</taglist>
<p>A similar behaviour, but still using the new logger API, can be
obtained by setting the Kernel application environment
- variable <seealso marker="kernel:kernel_app#logger_sasl_compatible"><c>logger_sasl_compatible=true</c></seealso>. This will add a
- second instance of the standard logger handler
- named <c>sasl</c>, which will only print the SASL reports. No
- SASL reports will then be printed by the Kernel logger
- handler.</p>
- <p>The <c>sasl</c> handler will be configured according to the
- values of the following SASL application environment
- variables.</p>
+ variable <seealso marker="kernel:kernel_app#logger_sasl_compatible">
+ <c>logger_sasl_compatible</c></seealso> to <c>true</c>. This
+ adds a second instance of the standard Logger handler,
+ named <c>sasl</c>, which only prints the SASL reports. No SASL
+ reports are then printed by the Kernel logger handler.</p>
+ <p>The <c>sasl</c> handler is configured according to the values
+ of the following SASL application environment variables.</p>
<taglist>
<tag><c><![CDATA[sasl_error_logger = Value ]]></c></tag>
<item>
diff --git a/lib/sasl/src/sasl.erl b/lib/sasl/src/sasl.erl
index 92b80694d7..5db3d75cfb 100644
--- a/lib/sasl/src/sasl.erl
+++ b/lib/sasl/src/sasl.erl
@@ -131,6 +131,10 @@ add_sasl_logger(std, undefined) -> ok;
add_sasl_logger(Dest, Level) ->
FC = #{legacy_header=>true,
single_line=>false},
+ case Level of
+ info -> allow_progress();
+ _ -> ok
+ end,
ok = logger:add_handler(sasl,logger_std_h,
#{level=>Level,
filter_default=>stop,
@@ -139,8 +143,8 @@ add_sasl_logger(Dest, Level) ->
{fun logger_filters:remote_gl/2,stop}},
{sasl_domain,
{fun logger_filters:domain/2,
- {log,equal,[beam,erlang,otp,sasl]}}}],
- logger_std_h=>#{type=>Dest},
+ {log,equal,[otp,sasl]}}}],
+ config=>#{type=>Dest},
formatter=>{logger_formatter,FC}}).
delete_sasl_logger(undefined) -> ok;
@@ -151,6 +155,7 @@ delete_sasl_logger(_Type) ->
add_error_logger_mf(undefined) -> ok;
add_error_logger_mf({Dir, MaxB, MaxF}) ->
+ allow_progress(),
error_logger:add_report_handler(
log_mf_h, log_mf_h:init(Dir, MaxB, MaxF, fun pred/1)).
@@ -161,6 +166,13 @@ delete_error_logger_mf(_) ->
pred({_Type, GL, _Msg}) when node(GL) =/= node() -> false;
pred(_) -> true.
+allow_progress() ->
+ #{level:=PL} = logger:get_primary_config(),
+ case logger:compare_levels(info,PL) of
+ lt -> ok = logger:set_primary_config(level,info);
+ _ -> ok
+ end.
+
%%%-----------------------------------------------------------------
%%% supervisor functionality
%%%-----------------------------------------------------------------
diff --git a/lib/sasl/test/sasl_report_SUITE.erl b/lib/sasl/test/sasl_report_SUITE.erl
index 72ee2f0a10..c3e0fdd63b 100644
--- a/lib/sasl/test/sasl_report_SUITE.erl
+++ b/lib/sasl/test/sasl_report_SUITE.erl
@@ -82,7 +82,7 @@ do_gen_server_crash(Config, Encoding) ->
application:set_env(kernel, error_logger_format_depth, 30),
error_logger:logfile({open,KernelLog}),
application:start(sasl),
- logger:i(print),
+ ct:log("Logger config:~n~p",[logger:get_config()]),
ct:log("error_logger handlers: ~p",[error_logger:which_report_handlers()]),
crash_me(),
diff --git a/lib/snmp/src/compile/snmpc.erl b/lib/snmp/src/compile/snmpc.erl
index 4416626a4c..7f627d66d9 100644
--- a/lib/snmp/src/compile/snmpc.erl
+++ b/lib/snmp/src/compile/snmpc.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -456,6 +456,7 @@ compile_parsed_data(#pdata{mib_name = MibName,
RelChk = get_relaxed_row_name_assign_check(Opts),
Data = #dldata{deprecated = Deprecated,
relaxed_row_name_assign_check = RelChk},
+ mc_new_type_loop(Definitions),
put(augmentations, false),
definitions_loop(Definitions, Data),
MibName.
@@ -481,7 +482,40 @@ do_update_imports([{{Mib, ImportsFromMib0},_Line}|Imports], Acc) ->
update_status(Name, Status) ->
#cdata{status_ets = Ets} = get(cdata),
ets:insert(Ets, {Name, Status}).
-
+
+
+mc_new_type_loop(
+ [{#mc_new_type{
+ name = NewTypeName,
+ macro = Macro,
+ syntax = OldType,
+ display_hint = DisplayHint},Line}|T]) ->
+ ?vlog2("typeloop -> new_type:"
+ "~n Macro: ~p"
+ "~n NewTypeName: ~p"
+ "~n OldType: ~p"
+ "~n DisplayHint: ~p",
+ [Macro, NewTypeName, OldType, DisplayHint], Line),
+ ensure_macro_imported(Macro,Line),
+ Types = (get(cdata))#cdata.asn1_types,
+ case lists:keysearch(NewTypeName, #asn1_type.aliasname, Types) of
+ {value,_} ->
+ snmpc_lib:print_error("Type ~w already defined.",
+ [NewTypeName],Line);
+ false ->
+ %% NameOfOldType = element(2,OldType),
+ ASN1 = snmpc_lib:make_ASN1type(OldType),
+ snmpc_lib:add_cdata(#cdata.asn1_types,
+ [ASN1#asn1_type{aliasname = NewTypeName,
+ imported = false,
+ display_hint = DisplayHint}])
+ end,
+ mc_new_type_loop(T);
+mc_new_type_loop([_|T]) ->
+ mc_new_type_loop(T);
+mc_new_type_loop([]) ->
+ ok.
+
%% A deprecated object
definitions_loop([{#mc_object_type{name = ObjName, status = deprecated},
@@ -745,32 +779,8 @@ definitions_loop([{#mc_object_type{name = NameOfTable,
ColMEs]),
definitions_loop(RestObjs, Data);
-definitions_loop([{#mc_new_type{name = NewTypeName,
- macro = Macro,
- syntax = OldType,
- display_hint = DisplayHint},Line}|T],
- Data) ->
- ?vlog2("defloop -> new_type:"
- "~n Macro: ~p"
- "~n NewTypeName: ~p"
- "~n OldType: ~p"
- "~n DisplayHint: ~p",
- [Macro, NewTypeName, OldType, DisplayHint], Line),
- ensure_macro_imported(Macro,Line),
- Types = (get(cdata))#cdata.asn1_types,
- case lists:keysearch(NewTypeName, #asn1_type.aliasname, Types) of
- {value,_} ->
- snmpc_lib:print_error("Type ~w already defined.",
- [NewTypeName],Line);
- false ->
- %% NameOfOldType = element(2,OldType),
- ASN1 = snmpc_lib:make_ASN1type(OldType),
- snmpc_lib:add_cdata(#cdata.asn1_types,
- [ASN1#asn1_type{aliasname = NewTypeName,
- imported = false,
- display_hint = DisplayHint}])
- end,
- definitions_loop(T, Data);
+definitions_loop([{#mc_new_type{},_}|T], Data) ->
+ definitions_loop(T, Data);
%% Plain variable
definitions_loop([{#mc_object_type{name = NewVarName,
diff --git a/lib/snmp/test/snmp_compiler_test.erl b/lib/snmp/test/snmp_compiler_test.erl
index 2b6bba4ee6..0a7b729d1f 100644
--- a/lib/snmp/test/snmp_compiler_test.erl
+++ b/lib/snmp/test/snmp_compiler_test.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2003-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2003-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -58,7 +58,8 @@
otp_10799/1,
otp_10808/1,
otp_14145/1,
- otp_13014/1
+ otp_13014/1,
+ otp_14196/1
]).
%%----------------------------------------------------------------------
@@ -138,7 +139,7 @@ all() ->
groups() ->
[{tickets, [],
[otp_6150, otp_8574, otp_8595, otp_10799, otp_10808, otp_14145,
- otp_13014]}].
+ otp_13014, otp_14196]}].
init_per_group(_GroupName, Config) ->
Config.
@@ -489,6 +490,22 @@ otp_13014(Config) when is_list(Config) ->
TableInfo,
ok.
+%%======================================================================
+
+otp_14196(suite) ->
+ [];
+otp_14196(Config) when is_list(Config) ->
+ put(tname, otp14196),
+ p("starting with Config: ~p~n", [Config]),
+
+ Dir = ?config(case_top_dir, Config),
+ MibDir = ?config(mib_dir, Config),
+ MibFile = join(MibDir, "OTP14196-MIB.mib"),
+ ?line {ok, Mib} =
+ snmpc:compile(MibFile, [{outdir, Dir}, {verbosity, trace}]),
+ p("Mib: ~n~p~n", [Mib]),
+ ok.
+
%%======================================================================
diff --git a/lib/snmp/test/snmp_test_data/OTP14196-MIB.mib b/lib/snmp/test/snmp_test_data/OTP14196-MIB.mib
new file mode 100644
index 0000000000..0b3c718a02
--- /dev/null
+++ b/lib/snmp/test/snmp_test_data/OTP14196-MIB.mib
@@ -0,0 +1,47 @@
+OTP14196-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY, OBJECT-TYPE, snmpModules, mib-2
+ FROM SNMPv2-SMI
+ TEXTUAL-CONVENTION
+ FROM SNMPv2-TC
+ OBJECT-GROUP
+ FROM SNMPv2-CONF
+ ;
+
+otp14196MIB MODULE-IDENTITY
+ LAST-UPDATED "1004210000Z"
+ ORGANIZATION ""
+ CONTACT-INFO
+ ""
+ DESCRIPTION
+ "Test mib for OTP-14196"
+ ::= { snmpModules 1 }
+
+testCompliances OBJECT IDENTIFIER ::= { otp14196MIB 1 }
+test OBJECT IDENTIFIER ::= { mib-2 15 }
+
+typeA OBJECT-TYPE
+ SYNTAX TypeAType
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Test type for OTP-14196"
+ ::= { test 4711 }
+
+TypeAType ::= TEXTUAL-CONVENTION
+ STATUS current
+ DESCRIPTION
+ ""
+ SYNTAX INTEGER
+
+testGroups OBJECT IDENTIFIER ::= { testCompliances 1 }
+
+testGroupA OBJECT-GROUP
+ OBJECTS { typeA }
+ STATUS current
+ DESCRIPTION
+ ""
+ ::= { testGroups 17 }
+
+END
diff --git a/lib/ssl/doc/src/ssl.xml b/lib/ssl/doc/src/ssl.xml
index 825bf46459..adf4fb9ba4 100644
--- a/lib/ssl/doc/src/ssl.xml
+++ b/lib/ssl/doc/src/ssl.xml
@@ -1501,6 +1501,18 @@ fun(srp, Username :: string(), UserState :: term()) ->
</func>
<func>
+ <name>suite_to_str(CipherSuite) -> String</name>
+ <fsummary>Returns the string representation of a cipher suite.</fsummary>
+ <type>
+ <v>CipherSuite = erl_cipher_suite()</v>
+ <v>String = string()</v>
+ </type>
+ <desc>
+ <p>Returns the string representation of a cipher suite.</p>
+ </desc>
+ </func>
+
+ <func>
<name>transport_accept(ListenSocket) -></name>
<name>transport_accept(ListenSocket, Timeout) ->
{ok, NewSocket} | {error, Reason}</name>
diff --git a/lib/ssl/src/ssl.erl b/lib/ssl/src/ssl.erl
index 565cc9e1bc..eb5b351dd3 100644
--- a/lib/ssl/src/ssl.erl
+++ b/lib/ssl/src/ssl.erl
@@ -55,7 +55,7 @@
format_error/1, renegotiate/1, prf/5, negotiated_protocol/1,
connection_information/1, connection_information/2]).
%% Misc
--export([handle_options/2, tls_version/1, new_ssl_options/3]).
+-export([handle_options/2, tls_version/1, new_ssl_options/3, suite_to_str/1]).
-deprecated({ssl_accept, 1, eventually}).
-deprecated({ssl_accept, 2, eventually}).
@@ -772,6 +772,16 @@ tls_version({3, _} = Version) ->
tls_version({254, _} = Version) ->
dtls_v1:corresponding_tls_version(Version).
+
+%%--------------------------------------------------------------------
+-spec suite_to_str(ssl_cipher:erl_cipher_suite()) -> string().
+%%
+%% Description: Return the string representation of a cipher suite.
+%%--------------------------------------------------------------------
+suite_to_str(Cipher) ->
+ ssl_cipher:suite_to_str(Cipher).
+
+
%%%--------------------------------------------------------------
%%% Internal functions
%%%--------------------------------------------------------------------
diff --git a/lib/ssl/src/ssl_cipher.erl b/lib/ssl/src/ssl_cipher.erl
index 3f8b9a8a9b..c5b5b76f05 100644
--- a/lib/ssl/src/ssl_cipher.erl
+++ b/lib/ssl/src/ssl_cipher.erl
@@ -43,7 +43,7 @@
filter/3, filter_suites/1, filter_suites/2,
hash_algorithm/1, sign_algorithm/1, is_acceptable_hash/2, is_fallback/1,
random_bytes/1, calc_mac_hash/4,
- is_stream_ciphersuite/1]).
+ is_stream_ciphersuite/1, suite_to_str/1]).
-export_type([cipher_suite/0,
erl_cipher_suite/0, old_erl_cipher_suite/0, openssl_cipher_suite/0,
@@ -1877,6 +1877,32 @@ suite(#{key_exchange := dhe_rsa,
prf := sha256}) ->
?TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256.
+
+%%--------------------------------------------------------------------
+-spec suite_to_str(erl_cipher_suite()) -> string().
+%%
+%% Description: Return the string representation of a cipher suite.
+%%--------------------------------------------------------------------
+suite_to_str(#{key_exchange := null,
+ cipher := null,
+ mac := null,
+ prf := null}) ->
+ "TLS_EMPTY_RENEGOTIATION_INFO_SCSV";
+suite_to_str(#{key_exchange := Kex,
+ cipher := Cipher,
+ mac := aead,
+ prf := PRF}) ->
+ "TLS_" ++ string:to_upper(atom_to_list(Kex)) ++
+ "_WITH_" ++ string:to_upper(atom_to_list(Cipher)) ++
+ "_" ++ string:to_upper(atom_to_list(PRF));
+suite_to_str(#{key_exchange := Kex,
+ cipher := Cipher,
+ mac := Mac}) ->
+ "TLS_" ++ string:to_upper(atom_to_list(Kex)) ++
+ "_WITH_" ++ string:to_upper(atom_to_list(Cipher)) ++
+ "_" ++ string:to_upper(atom_to_list(Mac)).
+
+
%%--------------------------------------------------------------------
-spec openssl_suite(openssl_cipher_suite()) -> cipher_suite().
%%
diff --git a/lib/ssl/test/ssl_basic_SUITE.erl b/lib/ssl/test/ssl_basic_SUITE.erl
index 162c63850f..e8fb25e0e4 100644
--- a/lib/ssl/test/ssl_basic_SUITE.erl
+++ b/lib/ssl/test/ssl_basic_SUITE.erl
@@ -108,7 +108,8 @@ basic_tests() ->
clear_pem_cache,
defaults,
fallback,
- cipher_format
+ cipher_format,
+ suite_to_str
].
basic_tests_tls() ->
@@ -1227,7 +1228,27 @@ cipher_format(Config) when is_list(Config) ->
ssl:close(Socket1),
{ok, Socket2} = ssl:listen(0, [{ciphers, ssl:cipher_suites(openssl)}]),
ssl:close(Socket2).
-
+
+%%--------------------------------------------------------------------
+suite_to_str() ->
+ [{doc, "Test that the suite_to_str API works"}].
+suite_to_str(Config) when is_list(Config) ->
+ "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" =
+ ssl:suite_to_str(#{key_exchange => null,
+ cipher => null,
+ mac => null,
+ prf => null}),
+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" =
+ ssl:suite_to_str(#{key_exchange => ecdhe_ecdsa,
+ cipher => aes_128_gcm,
+ mac => aead,
+ prf => sha256}),
+ "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" =
+ ssl:suite_to_str(#{key_exchange => ecdh_rsa,
+ cipher => aes_128_cbc,
+ mac => sha256,
+ prf => sha256}).
+
%%--------------------------------------------------------------------
peername() ->
diff --git a/lib/stdlib/doc/src/io.xml b/lib/stdlib/doc/src/io.xml
index f1037ec76b..d4a2713840 100644
--- a/lib/stdlib/doc/src/io.xml
+++ b/lib/stdlib/doc/src/io.xml
@@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
- <year>1996</year><year>2017</year>
+ <year>1996</year><year>2018</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
@@ -332,11 +332,22 @@ Here T = [{attributes,[[{id,age,1.5},
{tag,{'PRIVATE',3}},
{mode,implicit}]
ok</pre>
+
+ <p>As from Erlang/OTP 21.0, a field width of value
+ <c>0</c> can be used for specifying that a line is
+ infinitely long, which means that no line breaks
+ are inserted. For example:</p>
+
+ <pre>
+5> <input>io:fwrite("~0p~n", [lists:seq(1, 30)]).</input>
+[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
+ok</pre>
+
<p>When the modifier <c>l</c> is specified, no detection of
printable character lists takes place, for example:</p>
<pre>
-5> <input>S = [{a,"a"}, {b, "b"}].</input>
-6> <input>io:fwrite("~15p~n", [S]).</input>
+6> <input>S = [{a,"a"}, {b, "b"}],
+ io:fwrite("~15p~n", [S]).</input>
[{a,"a"},
{b,"b"}]
ok
diff --git a/lib/stdlib/src/gen_event.erl b/lib/stdlib/src/gen_event.erl
index 3ee2031d02..8213282867 100644
--- a/lib/stdlib/src/gen_event.erl
+++ b/lib/stdlib/src/gen_event.erl
@@ -589,7 +589,7 @@ server_update(Handler1, Func, Event, SName) ->
?LOG_WARNING(#{label=>{gen_event,no_handle_info},
module=>Mod1,
message=>Event},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_event:format_log/1,
error_logger=>#{tag=>warning_msg}}), % warningmap??
{ok, Handler1};
@@ -751,7 +751,7 @@ report_error(Handler, Reason, State, LastIn, SName) ->
state=>format_status(terminate,Handler#handler.module,
get(),State),
reason=>Reason},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_event:format_log/1,
error_logger=>#{tag=>error}}).
diff --git a/lib/stdlib/src/gen_fsm.erl b/lib/stdlib/src/gen_fsm.erl
index 1646186761..caaaf8fa2e 100644
--- a/lib/stdlib/src/gen_fsm.erl
+++ b/lib/stdlib/src/gen_fsm.erl
@@ -505,7 +505,7 @@ handle_msg(Msg, Parent, Name, StateName, StateData, Mod, _Time, HibernateAfterTi
?LOG_WARNING(#{label=>{gen_fsm,no_handle_info},
module=>Mod,
message=>Msg},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_fsm:format_log/1,
error_logger=>#{tag=>warning_msg}}),
loop(Parent, Name, StateName, StateData, Mod, infinity, HibernateAfterTimeout, []);
@@ -616,7 +616,7 @@ error_info(Reason, Name, Msg, StateName, StateData, Debug) ->
state_name=>StateName,
state_data=>StateData,
reason=>Reason},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_fsm:format_log/1,
error_logger=>#{tag=>error}}),
sys:print_log(Debug),
diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl
index 09f77c0810..342cc2a8e3 100644
--- a/lib/stdlib/src/gen_server.erl
+++ b/lib/stdlib/src/gen_server.erl
@@ -645,7 +645,7 @@ try_dispatch(Mod, Func, Msg, State) ->
#{label=>{gen_server,no_handle_info},
module=>Mod,
message=>Msg},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_server:format_log/1,
error_logger=>#{tag=>warning_msg}}),
{ok, {noreply, State}};
@@ -891,7 +891,7 @@ error_info(Reason, Name, From, Msg, Mod, State, Debug) ->
state=>format_status(terminate, Mod, get(), State),
reason=>Reason,
client_info=>client_stacktrace(From)},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_server:format_log/1,
error_logger=>#{tag=>error}}),
sys:print_log(Debug),
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index b36b8cd5a5..faa43fbc1e 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -1448,13 +1448,13 @@ loop_event_done(
[?sys_debug(
Debug_0,
{S#state.name,State},
- {postpone,Event_0,State}),
+ {postpone,Event_0,NextState}),
Event_0|P_0];
false ->
[?sys_debug(
Debug_0,
{S#state.name,State},
- {consume,Event_0,State})|P_0]
+ {consume,Event_0,NextState})|P_0]
end,
{Events_2,P_2,Timers_2} =
%% Move all postponed events to queue,
@@ -1900,7 +1900,7 @@ error_info(
state_enter=>StateEnter,
state=>format_status(terminate, get(), S),
reason=>{Class,Reason,Stacktrace}},
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
report_cb=>fun gen_statem:format_log/1,
error_logger=>#{tag=>error}}).
diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl
index 3d5a979b3e..dca1b37ef3 100644
--- a/lib/stdlib/src/io_lib_pretty.erl
+++ b/lib/stdlib/src/io_lib_pretty.erl
@@ -131,6 +131,8 @@ print(Term, Col, Ll, D, M0, T, RecDefFun, Enc, Str) when is_tuple(Term);
%% use Len as CHAR_MAX if M0 = -1
M = max_cs(M0, Len),
if
+ Ll =:= 0 ->
+ write(If);
Len < Ll - Col, Len =< M ->
%% write the whole thing on a single line when there is room
write(If);
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl
index a13f340709..a1634547f3 100644
--- a/lib/stdlib/src/maps.erl
+++ b/lib/stdlib/src/maps.erl
@@ -249,7 +249,7 @@ fold(Fun,Init,Map) when is_function(Fun,3), is_map(Map) ->
fold(Fun,Init,Iterator) when is_function(Fun,3), ?IS_ITERATOR(Iterator) ->
fold_1(Fun,Init,Iterator);
fold(Fun,Init,Map) ->
- erlang:error(error_type(Map),[Fun,Init,Map]).
+ erlang:error(error_type_iter(Map),[Fun,Init,Map]).
fold_1(Fun, Acc, Iter) ->
case next(Iter) of
@@ -272,7 +272,7 @@ map(Fun,Map) when is_function(Fun, 2), is_map(Map) ->
map(Fun,Iterator) when is_function(Fun, 2), ?IS_ITERATOR(Iterator) ->
maps:from_list(map_1(Fun, Iterator));
map(Fun,Map) ->
- erlang:error(error_type(Map),[Fun,Map]).
+ erlang:error(error_type_iter(Map),[Fun,Map]).
map_1(Fun, Iter) ->
case next(Iter) of
@@ -342,5 +342,8 @@ with(Ks,M) ->
erlang:error(error_type(M),[Ks,M]).
-error_type(M) when is_map(M); ?IS_ITERATOR(M) -> badarg;
+error_type(M) when is_map(M) -> badarg;
error_type(V) -> {badmap, V}.
+
+error_type_iter(M) when is_map(M); ?IS_ITERATOR(M) -> badarg;
+error_type_iter(V) -> {badmap, V}.
diff --git a/lib/stdlib/src/proc_lib.erl b/lib/stdlib/src/proc_lib.erl
index 5f14e78f91..cca1628aba 100644
--- a/lib/stdlib/src/proc_lib.erl
+++ b/lib/stdlib/src/proc_lib.erl
@@ -508,7 +508,7 @@ crash_report(Class, Reason, StartF, Stacktrace) ->
?LOG_ERROR(#{label=>{proc_lib,crash},
report=>[my_info(Class, Reason, StartF, Stacktrace),
linked_info(self())]},
- #{domain=>[beam,erlang,otp,sasl],
+ #{domain=>[otp,sasl],
report_cb=>fun proc_lib:report_cb/1,
logger_formatter=>#{title=>"CRASH REPORT"},
error_logger=>#{tag=>error_report,type=>crash_report}}).
diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl
index eb46ac611a..9b6c2a5f0b 100644
--- a/lib/stdlib/src/supervisor.erl
+++ b/lib/stdlib/src/supervisor.erl
@@ -43,7 +43,7 @@
{errorContext,Error},
{reason,Reason},
{offender,extract_child(Child)}]},
- #{domain=>[beam,erlang,otp,sasl],
+ #{domain=>[otp,sasl],
report_cb=>fun logger:format_otp_report/1,
logger_formatter=>#{title=>"SUPERVISOR REPORT"},
error_logger=>#{tag=>error_report,
@@ -580,7 +580,7 @@ handle_info({'EXIT', Pid, Reason}, State) ->
handle_info(Msg, State) ->
?LOG_ERROR("Supervisor received unexpected message: ~tp~n",[Msg],
- #{domain=>[beam,erlang,otp],
+ #{domain=>[otp],
error_logger=>#{tag=>error}}),
{noreply, State}.
@@ -1419,7 +1419,7 @@ report_progress(Child, SupName) ->
?LOG_INFO(#{label=>{supervisor,progress},
report=>[{supervisor,SupName},
{started,extract_child(Child)}]},
- #{domain=>[beam,erlang,otp,sasl],
+ #{domain=>[otp,sasl],
report_cb=>fun logger:format_otp_report/1,
logger_formatter=>#{title=>"PROGRESS REPORT"},
error_logger=>#{tag=>info_report,type=>progress}}).
diff --git a/lib/stdlib/src/supervisor_bridge.erl b/lib/stdlib/src/supervisor_bridge.erl
index 39372935fa..2db0a895d6 100644
--- a/lib/stdlib/src/supervisor_bridge.erl
+++ b/lib/stdlib/src/supervisor_bridge.erl
@@ -135,7 +135,7 @@ report_progress(Pid, Mod, StartArgs, SupName) ->
report=>[{supervisor, SupName},
{started, [{pid, Pid},
{mfa, {Mod, init, [StartArgs]}}]}]},
- #{domain=>[beam,erlang,otp,sasl],
+ #{domain=>[otp,sasl],
report_cb=>fun logger:format_otp_report/1,
logger_formatter=>#{title=>"PROGRESS REPORT"},
error_logger=>#{tag=>info_report,type=>progress}}).
@@ -146,7 +146,7 @@ report_error(Error, Reason, #state{name = Name, pid = Pid, mod = Mod}) ->
{errorContext, Error},
{reason, Reason},
{offender, [{pid, Pid}, {mod, Mod}]}]},
- #{domain=>[beam,erlang,otp,sasl],
+ #{domain=>[otp,sasl],
report_cb=>fun logger:format_otp_report/1,
logger_formatter=>#{title=>"SUPERVISOR REPORT"},
error_logger=>#{tag=>error_report,type=>supervisor_report}}).
diff --git a/lib/stdlib/src/uri_string.erl b/lib/stdlib/src/uri_string.erl
index 28d36ea229..48cce90d68 100644
--- a/lib/stdlib/src/uri_string.erl
+++ b/lib/stdlib/src/uri_string.erl
@@ -297,7 +297,10 @@
NormalizedURI :: uri_string()
| error().
normalize(URIMap) ->
- normalize(URIMap, []).
+ try normalize(URIMap, [])
+ catch
+ throw:{error, Atom, RestData} -> {error, Atom, RestData}
+ end.
-spec normalize(URI, Options) -> NormalizedURI when
@@ -523,34 +526,34 @@ parse_relative_part(?STRING_REST("//", Rest), URI) ->
{T, URI1} ->
Userinfo = calculate_parsed_userinfo(Rest, T),
URI2 = maybe_add_path(URI1),
- URI2#{userinfo => decode_userinfo(Userinfo)}
+ URI2#{userinfo => Userinfo}
catch
throw:{_,_,_} ->
{T, URI1} = parse_host(Rest, URI),
Host = calculate_parsed_host_port(Rest, T),
URI2 = maybe_add_path(URI1),
- URI2#{host => decode_host(remove_brackets(Host))}
+ URI2#{host => remove_brackets(Host)}
end;
parse_relative_part(?STRING_REST($/, Rest), URI) ->
{T, URI1} = parse_segment(Rest, URI), % path-absolute
Path = calculate_parsed_part(Rest, T),
- URI1#{path => decode_path(?STRING_REST($/, Path))};
+ URI1#{path => ?STRING_REST($/, Path)};
parse_relative_part(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
URI2 = maybe_add_path(URI1),
- URI2#{query => decode_query(Query)};
+ URI2#{query => Query};
parse_relative_part(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
URI2 = maybe_add_path(URI1),
- URI2#{fragment => decode_fragment(Fragment)};
+ URI2#{fragment => Fragment};
parse_relative_part(?STRING_REST(Char, Rest), URI) ->
case is_segment_nz_nc(Char) of
true ->
{T, URI1} = parse_segment_nz_nc(Rest, URI), % path-noscheme
Path = calculate_parsed_part(Rest, T),
- URI1#{path => decode_path(?STRING_REST(Char, Path))};
+ URI1#{path => ?STRING_REST(Char, Path)};
false -> throw({error,invalid_uri,[Char]})
end.
@@ -593,11 +596,11 @@ parse_segment(?STRING_REST($/, Rest), URI) ->
parse_segment(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_segment(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI),
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_segment(?STRING_REST(Char, Rest), URI) ->
case is_pchar(Char) of
true -> parse_segment(Rest, URI);
@@ -616,11 +619,11 @@ parse_segment_nz_nc(?STRING_REST($/, Rest), URI) ->
parse_segment_nz_nc(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_segment_nz_nc(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI),
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_segment_nz_nc(?STRING_REST(Char, Rest), URI) ->
case is_segment_nz_nc(Char) of
true -> parse_segment_nz_nc(Rest, URI);
@@ -709,31 +712,31 @@ parse_hier(?STRING_REST("//", Rest), URI) ->
try parse_userinfo(Rest, URI) of
{T, URI1} ->
Userinfo = calculate_parsed_userinfo(Rest, T),
- {Rest, URI1#{userinfo => decode_userinfo(Userinfo)}}
+ {Rest, URI1#{userinfo => Userinfo}}
catch
throw:{_,_,_} ->
{T, URI1} = parse_host(Rest, URI),
Host = calculate_parsed_host_port(Rest, T),
- {Rest, URI1#{host => decode_host(remove_brackets(Host))}}
+ {Rest, URI1#{host => remove_brackets(Host)}}
end;
parse_hier(?STRING_REST($/, Rest), URI) ->
{T, URI1} = parse_segment(Rest, URI), % path-absolute
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST($/, Path))}};
+ {Rest, URI1#{path => ?STRING_REST($/, Path)}};
parse_hier(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_hier(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_hier(?STRING_REST(Char, Rest), URI) -> % path-rootless
case is_pchar(Char) of
true -> % segment_nz
{T, URI1} = parse_segment(Rest, URI),
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST(Char, Path))}};
+ {Rest, URI1#{path => ?STRING_REST(Char, Path)}};
false -> throw({error,invalid_uri,[Char]})
end;
parse_hier(?STRING_EMPTY, URI) ->
@@ -770,7 +773,7 @@ parse_userinfo(?CHAR($@), URI) ->
parse_userinfo(?STRING_REST($@, Rest), URI) ->
{T, URI1} = parse_host(Rest, URI),
Host = calculate_parsed_host_port(Rest, T),
- {Rest, URI1#{host => decode_host(remove_brackets(Host))}};
+ {Rest, URI1#{host => remove_brackets(Host)}};
parse_userinfo(?STRING_REST(Char, Rest), URI) ->
case is_userinfo(Char) of
true -> parse_userinfo(Rest, URI);
@@ -836,20 +839,25 @@ parse_host(?STRING_REST($:, Rest), URI) ->
parse_host(?STRING_REST($/, Rest), URI) ->
{T, URI1} = parse_segment(Rest, URI), % path-abempty
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST($/, Path))}};
+ {Rest, URI1#{path => ?STRING_REST($/, Path)}};
parse_host(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_host(?STRING_REST($[, Rest), URI) ->
parse_ipv6_bin(Rest, [], URI);
parse_host(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_host(?STRING_REST(Char, Rest), URI) ->
case is_digit(Char) of
- true -> parse_ipv4_bin(Rest, [Char], URI);
+ true ->
+ try parse_ipv4_bin(Rest, [Char], URI)
+ catch
+ throw:{_,_,_} ->
+ parse_reg_name(?STRING_REST(Char, Rest), URI)
+ end;
false -> parse_reg_name(?STRING_REST(Char, Rest), URI)
end;
parse_host(?STRING_EMPTY, URI) ->
@@ -865,15 +873,15 @@ parse_reg_name(?STRING_REST($:, Rest), URI) ->
parse_reg_name(?STRING_REST($/, Rest), URI) ->
{T, URI1} = parse_segment(Rest, URI), % path-abempty
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST($/, Path))}};
+ {Rest, URI1#{path => ?STRING_REST($/, Path)}};
parse_reg_name(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_reg_name(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_reg_name(?STRING_REST(Char, Rest), URI) ->
case is_reg_name(Char) of
true -> parse_reg_name(Rest, URI);
@@ -899,17 +907,17 @@ parse_ipv4_bin(?STRING_REST($/, Rest), Acc, URI) ->
_ = validate_ipv4_address(lists:reverse(Acc)),
{T, URI1} = parse_segment(Rest, URI), % path-abempty
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST($/, Path))}};
+ {Rest, URI1#{path => ?STRING_REST($/, Path)}};
parse_ipv4_bin(?STRING_REST($?, Rest), Acc, URI) ->
_ = validate_ipv4_address(lists:reverse(Acc)),
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_ipv4_bin(?STRING_REST($#, Rest), Acc, URI) ->
_ = validate_ipv4_address(lists:reverse(Acc)),
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_ipv4_bin(?STRING_REST(Char, Rest), Acc, URI) ->
case is_ipv4(Char) of
true -> parse_ipv4_bin(Rest, [Char|Acc], URI);
@@ -961,15 +969,15 @@ parse_ipv6_bin_end(?STRING_REST($:, Rest), URI) ->
parse_ipv6_bin_end(?STRING_REST($/, Rest), URI) ->
{T, URI1} = parse_segment(Rest, URI), % path-abempty
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST($/, Path))}};
+ {Rest, URI1#{path => ?STRING_REST($/, Path)}};
parse_ipv6_bin_end(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_ipv6_bin_end(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_ipv6_bin_end(?STRING_REST(Char, Rest), URI) ->
case is_ipv6(Char) of
true -> parse_ipv6_bin_end(Rest, URI);
@@ -999,15 +1007,15 @@ validate_ipv6_address(Addr) ->
parse_port(?STRING_REST($/, Rest), URI) ->
{T, URI1} = parse_segment(Rest, URI), % path-abempty
Path = calculate_parsed_part(Rest, T),
- {Rest, URI1#{path => decode_path(?STRING_REST($/, Path))}};
+ {Rest, URI1#{path => ?STRING_REST($/, Path)}};
parse_port(?STRING_REST($?, Rest), URI) ->
{T, URI1} = parse_query(Rest, URI), % path-empty ?query
Query = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{query => decode_query(Query)}};
+ {Rest, URI1#{query => Query}};
parse_port(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI), % path-empty
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_port(?STRING_REST(Char, Rest), URI) ->
case is_digit(Char) of
true -> parse_port(Rest, URI);
@@ -1033,7 +1041,7 @@ parse_port(?STRING_EMPTY, URI) ->
parse_query(?STRING_REST($#, Rest), URI) ->
{T, URI1} = parse_fragment(Rest, URI),
Fragment = calculate_parsed_query_fragment(Rest, T),
- {Rest, URI1#{fragment => decode_fragment(Fragment)}};
+ {Rest, URI1#{fragment => Fragment}};
parse_query(?STRING_REST(Char, Rest), URI) ->
case is_query(Char) of
true -> parse_query(Rest, URI);
@@ -1088,6 +1096,31 @@ is_fragment(Char) -> is_pchar(Char).
%%
%%-------------------------------------------------------------------------
+%% Return true if input char is reserved.
+-spec is_reserved(char()) -> boolean().
+is_reserved($:) -> true;
+is_reserved($/) -> true;
+is_reserved($?) -> true;
+is_reserved($#) -> true;
+is_reserved($[) -> true;
+is_reserved($]) -> true;
+is_reserved($@) -> true;
+
+is_reserved($!) -> true;
+is_reserved($$) -> true;
+is_reserved($&) -> true;
+is_reserved($') -> true;
+is_reserved($() -> true;
+is_reserved($)) -> true;
+
+is_reserved($*) -> true;
+is_reserved($+) -> true;
+is_reserved($,) -> true;
+is_reserved($;) -> true;
+is_reserved($=) -> true;
+is_reserved(_) -> false.
+
+
%% Check if char is sub-delim.
-spec is_sub_delim(char()) -> boolean().
is_sub_delim($!) -> true;
@@ -1276,36 +1309,6 @@ byte_size_exl_head(Binary) -> byte_size(Binary) + 1.
%%
%% pct-encoded = "%" HEXDIG HEXDIG
%%-------------------------------------------------------------------------
--spec decode_userinfo(binary()) -> binary().
-decode_userinfo(Cs) ->
- check_utf8(decode(Cs, fun is_userinfo/1, <<>>)).
-
--spec decode_host(binary()) -> binary().
-decode_host(Cs) ->
- check_utf8(decode(Cs, fun is_host/1, <<>>)).
-
--spec decode_path(binary()) -> binary().
-decode_path(Cs) ->
- check_utf8(decode(Cs, fun is_path/1, <<>>)).
-
--spec decode_query(binary()) -> binary().
-decode_query(Cs) ->
- check_utf8(decode(Cs, fun is_query/1, <<>>)).
-
--spec decode_fragment(binary()) -> binary().
-decode_fragment(Cs) ->
- check_utf8(decode(Cs, fun is_fragment/1, <<>>)).
-
-
-%% Returns Cs if it is utf8 encoded.
-check_utf8(Cs) ->
- case unicode:characters_to_list(Cs) of
- {incomplete,_,_} ->
- throw({error,invalid_utf8,Cs});
- {error,_,_} ->
- throw({error,invalid_utf8,Cs});
- _ -> Cs
- end.
%%-------------------------------------------------------------------------
%% Percent-encode
@@ -1351,20 +1354,56 @@ encode_fragment(Cs) ->
%%-------------------------------------------------------------------------
%% Helper funtions for percent-decode
%%-------------------------------------------------------------------------
-decode(<<$%,C0,C1,Cs/binary>>, Fun, Acc) ->
+
+-spec decode(list()|binary()) -> list() | binary().
+decode(Cs) ->
+ decode(Cs, <<>>).
+%%
+decode(L, Acc) when is_list(L) ->
+ B0 = unicode:characters_to_binary(L),
+ B1 = decode(B0, Acc),
+ unicode:characters_to_list(B1);
+decode(<<$%,C0,C1,Cs/binary>>, Acc) ->
case is_hex_digit(C0) andalso is_hex_digit(C1) of
true ->
B = ?HEX2DEC(C0)*16+?HEX2DEC(C1),
- decode(Cs, Fun, <<Acc/binary, B>>);
+ case is_reserved(B) of
+ true ->
+ %% [2.2] Characters in the reserved set are protected from
+ %% normalization.
+ %% [2.1] For consistency, URI producers and normalizers should
+ %% use uppercase hexadecimal digits for all percent-
+ %% encodings.
+ H0 = hex_to_upper(C0),
+ H1 = hex_to_upper(C1),
+ decode(Cs, <<Acc/binary,$%,H0,H1>>);
+ false ->
+ decode(Cs, <<Acc/binary, B>>)
+ end;
false -> throw({error,invalid_percent_encoding,<<$%,C0,C1>>})
end;
-decode(<<C,Cs/binary>>, Fun, Acc) ->
- case Fun(C) of
- true -> decode(Cs, Fun, <<Acc/binary, C>>);
- false -> throw({error,invalid_percent_encoding,<<C,Cs/binary>>})
- end;
-decode(<<>>, _Fun, Acc) ->
- Acc.
+decode(<<C,Cs/binary>>, Acc) ->
+ decode(Cs, <<Acc/binary, C>>);
+decode(<<>>, Acc) ->
+ check_utf8(Acc).
+
+%% Returns Cs if it is utf8 encoded.
+check_utf8(Cs) ->
+ case unicode:characters_to_list(Cs) of
+ {incomplete,_,_} ->
+ throw({error,invalid_utf8,Cs});
+ {error,_,_} ->
+ throw({error,invalid_utf8,Cs});
+ _ -> Cs
+ end.
+
+%% Convert hex digit to uppercase form
+hex_to_upper(H) when $a =< H, H =< $f ->
+ H - 32;
+hex_to_upper(H) when $0 =< H, H =< $9;$A =< H, H =< $F->
+ H;
+hex_to_upper(H) ->
+ throw({error,invalid_input, H}).
%% Check if char is allowed in host
-spec is_host(char()) -> boolean().
@@ -1925,9 +1964,10 @@ base10_decode_unicode(<<H,_/binary>>, _, _) ->
%%-------------------------------------------------------------------------
normalize_map(URIMap) ->
- normalize_path_segment(
- normalize_scheme_based(
- normalize_case(URIMap))).
+ normalize_path_segment(
+ normalize_scheme_based(
+ normalize_percent_encoding(
+ normalize_case(URIMap)))).
%% 6.2.2.1. Case Normalization
@@ -1942,6 +1982,18 @@ normalize_case(#{} = Map) ->
Map.
+%% 6.2.2.2. Percent-Encoding Normalization
+normalize_percent_encoding(Map) ->
+ Fun = fun (K,V) when K =:= userinfo; K =:= host; K =:= path;
+ K =:= query; K =:= fragment ->
+ decode(V);
+ %% Handle port and scheme
+ (_,V) ->
+ V
+ end,
+ maps:map(Fun, Map).
+
+
to_lower(Cs) when is_list(Cs) ->
B = convert_to_binary(Cs, utf8, utf8),
convert_to_list(to_lower(B), utf8);
diff --git a/lib/stdlib/test/Makefile b/lib/stdlib/test/Makefile
index ae2e3d0e2b..bbe3cefa42 100644
--- a/lib/stdlib/test/Makefile
+++ b/lib/stdlib/test/Makefile
@@ -88,6 +88,7 @@ MODULES= \
unicode_SUITE \
unicode_util_SUITE \
uri_string_SUITE \
+ uri_string_property_test_SUITE \
win32reg_SUITE \
y2k_SUITE \
select_SUITE \
@@ -152,6 +153,6 @@ release_tests_spec: make_emakefile
$(INSTALL_DATA) stdlib.spec stdlib_bench.spec $(EMAKEFILE) \
$(ERL_FILES) $(COVERFILE) "$(RELSYSDIR)"
chmod -R u+w "$(RELSYSDIR)"
- @tar cf - *_SUITE_data | (cd "$(RELSYSDIR)"; tar xf -)
+ @tar cf - *_SUITE_data property_test | (cd "$(RELSYSDIR)"; tar xf -)
release_docs_spec:
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl
index 13f2cbd27b..91fe1133f6 100644
--- a/lib/stdlib/test/io_SUITE.erl
+++ b/lib/stdlib/test/io_SUITE.erl
@@ -31,7 +31,7 @@
otp_10836/1, io_lib_width_too_small/1,
io_with_huge_message_queue/1, format_string/1,
maps/1, coverage/1, otp_14178_unicode_atoms/1, otp_14175/1,
- otp_14285/1, limit_term/1, otp_14983/1]).
+ otp_14285/1, limit_term/1, otp_14983/1, otp_15103/1]).
-export([pretty/2, trf/3]).
@@ -63,7 +63,7 @@ all() ->
io_lib_print_binary_depth_one, otp_10302, otp_10755, otp_10836,
io_lib_width_too_small, io_with_huge_message_queue,
format_string, maps, coverage, otp_14178_unicode_atoms, otp_14175,
- otp_14285, limit_term, otp_14983].
+ otp_14285, limit_term, otp_14983, otp_15103].
%% Error cases for output.
error_1(Config) when is_list(Config) ->
@@ -2615,3 +2615,21 @@ trf(Format, Args, T) ->
trf(Format, Args, T, Opts) ->
lists:flatten(io_lib:format(Format, Args, [{chars_limit, T}|Opts])).
+
+otp_15103(_Config) ->
+ T = lists:duplicate(5, {a,b,c}),
+
+ S1 = io_lib:format("~0p", [T]),
+ "[{a,b,c},{a,b,c},{a,b,c},{a,b,c},{a,b,c}]" = lists:flatten(S1),
+ S2 = io_lib:format("~-0p", [T]),
+ "[{a,b,c},{a,b,c},{a,b,c},{a,b,c},{a,b,c}]" = lists:flatten(S2),
+ S3 = io_lib:format("~1p", [T]),
+ "[{a,\n b,\n c},\n {a,\n b,\n c},\n {a,\n b,\n c},\n {a,\n b,\n"
+ " c},\n {a,\n b,\n c}]" = lists:flatten(S3),
+
+ S4 = io_lib:format("~0P", [T, 5]),
+ "[{a,b,c},{a,b,...},{a,...},{...}|...]" = lists:flatten(S4),
+ S5 = io_lib:format("~1P", [T, 5]),
+ "[{a,\n b,\n c},\n {a,\n b,...},\n {a,...},\n {...}|...]" =
+ lists:flatten(S5),
+ ok.
diff --git a/lib/stdlib/test/maps_SUITE.erl b/lib/stdlib/test/maps_SUITE.erl
index a75751b31d..6374daa1d3 100644
--- a/lib/stdlib/test/maps_SUITE.erl
+++ b/lib/stdlib/test/maps_SUITE.erl
@@ -108,6 +108,8 @@ t_without_2(_Config) ->
%% error case
?badmap(a,without,[[a,b],a]) = (catch maps:without([a,b],id(a))),
?badmap(a,without,[{a,b},a]) = (catch maps:without({a,b},id(a))),
+ ?badmap({0,<<>>,97},without,[[],{0,<<>>,97}]) = (catch maps:without([], {0,<<>>,97})),
+ ?badmap({0,<<>>,97},without,[[false, -20, -8],{0,<<>>,97}]) = (catch maps:without([false, -20, -8], {0, <<>>, 97})),
?badarg(without,[a,#{}]) = (catch maps:without(a,#{})),
ok.
@@ -120,6 +122,8 @@ t_with_2(_Config) ->
%% error case
?badmap(a,with,[[a,b],a]) = (catch maps:with([a,b],id(a))),
?badmap(a,with,[{a,b},a]) = (catch maps:with({a,b},id(a))),
+ ?badmap({0,<<>>,97},with,[[],{0,<<>>,97}]) = (catch maps:with([], {0,<<>>,97})),
+ ?badmap({0,<<>>,97},with,[[false, -20, -8],{0,<<>>,97}]) = (catch maps:with([false, -20, -8], {0, <<>>, 97})),
?badarg(with,[a,#{}]) = (catch maps:with(a,#{})),
ok.
diff --git a/lib/stdlib/test/proc_lib_SUITE.erl b/lib/stdlib/test/proc_lib_SUITE.erl
index 81bf9020b8..a283aa992f 100644
--- a/lib/stdlib/test/proc_lib_SUITE.erl
+++ b/lib/stdlib/test/proc_lib_SUITE.erl
@@ -542,13 +542,14 @@ system_terminate(Reason,_Parent,_Deb,_State) ->
t_format(_Config) ->
- logger:add_handler_filter(logger_std_h,stop_all,{fun(_,_) -> stop end,ok}),
+ {ok,#{level:=Level}} = logger:get_handler_config(default),
+ logger:set_handler_config(default,level,none),
error_logger:add_report_handler(?MODULE, self()),
try
t_format()
after
error_logger:delete_report_handler(?MODULE),
- logger:remove_handler_filter(logger_std_h,stop_all)
+ logger:set_handler_config(default,level,Level)
end,
ok.
@@ -585,11 +586,12 @@ t_format() ->
ok.
t_format_arbitrary(_Config) ->
- logger:add_handler_filter(logger_std_h,stop_all,{fun(_,_) -> stop end,ok}),
+ {ok,#{level:=Level}} = logger:get_handler_config(default),
+ logger:set_handler_config(default,level,none),
try
t_format_arbitrary()
after
- logger:remove_handler_filter(logger_std_h,stop_all)
+ logger:set_handler_config(default,level,Level)
end,
ok.
diff --git a/lib/stdlib/test/property_test/uri_string_recompose.erl b/lib/stdlib/test/property_test/uri_string_recompose.erl
index e51a671172..35b3a50b9c 100644
--- a/lib/stdlib/test/property_test/uri_string_recompose.erl
+++ b/lib/stdlib/test/property_test/uri_string_recompose.erl
@@ -65,15 +65,29 @@
-define(QUERY, {query, query_map()}).
-define(FRAGMENT, {fragment, fragment_map()}).
+%% Non-unicode
+-define(USER_NU, {userinfo, non_unicode()}).
+-define(HOST_NU, {host, host_map_nu()}).
+-define(PATH_ABE_NU, {path, path_abempty_map_nu()}).
+-define(PATH_ABS_NU, {path, path_absolute_map_nu()}).
+-define(PATH_NOS_NU, {path, path_noscheme_map_nu()}).
+-define(PATH_ROO_NU, {path, path_rootless_map_nu()}).
+-define(QUERY_NU, {query, query_map_nu()}).
+-define(FRAGMENT_NU, {fragment, fragment_map_nu()}).
%%%========================================================================
%%% Properties
%%%========================================================================
prop_recompose() ->
+ ?FORALL(Map, map_no_unicode(),
+ Map =:= uri_string:parse(uri_string:recompose(Map))).
+
+prop_normalize() ->
?FORALL(Map, map(),
- Map =:= uri_string:parse(uri_string:recompose(Map))
- ).
+ uri_string:normalize(Map, [return_map]) =:=
+ uri_string:normalize(uri_string:parse(uri_string:recompose(Map)),
+ [return_map])).
%% Stats
prop_map_key_length_collect() ->
@@ -96,6 +110,9 @@ prop_scheme_collect() ->
map() ->
?LET(Gen, comp_proplist(), proplist_to_map(Gen)).
+map_no_unicode() ->
+ ?LET(Gen, comp_proplist_nu(), proplist_to_map(Gen)).
+
comp_proplist() ->
frequency([
{2, [?SCHEME,?PATH_ABS]},
@@ -166,6 +183,76 @@ comp_proplist() ->
{2, [?USER,?HOST,?PORT,?PATH_ABE,?QUERY,?FRAGMENT]}
]).
+comp_proplist_nu() ->
+ frequency([
+ {2, [?SCHEME,?PATH_ABS_NU]},
+ {2, [?SCHEME,?PATH_ROO_NU]},
+ {2, [?SCHEME,?PATH_EMP]},
+ {2, [?SCHEME,?HOST_NU,?PATH_ABE_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PATH_ABE_NU]},
+ {2, [?SCHEME,?HOST_NU,?PORT,?PATH_ABE_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU]},
+
+ {2, [?PATH_ABS_NU]},
+ {2, [?PATH_NOS_NU]},
+ {2, [?PATH_EMP]},
+ {2, [?HOST_NU,?PATH_ABE_NU]},
+ {2, [?USER_NU,?HOST_NU,?PATH_ABE_NU]},
+ {2, [?HOST_NU,?PORT,?PATH_ABE_NU]},
+ {2, [?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU]},
+
+
+ {2, [?SCHEME,?PATH_ABS_NU,?QUERY_NU]},
+ {2, [?SCHEME,?PATH_ROO_NU,?QUERY_NU]},
+ {2, [?SCHEME,?PATH_EMP,?QUERY_NU]},
+ {2, [?SCHEME,?HOST_NU,?PATH_ABE_NU,?QUERY_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PATH_ABE_NU,?QUERY_NU]},
+ {2, [?SCHEME,?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU]},
+
+ {2, [?PATH_ABS_NU,?QUERY_NU]},
+ {2, [?PATH_NOS_NU,?QUERY_NU]},
+ {2, [?PATH_EMP,?QUERY_NU]},
+ {2, [?HOST_NU,?PATH_ABE_NU,?QUERY_NU]},
+ {2, [?USER_NU,?HOST_NU,?PATH_ABE_NU,?QUERY_NU]},
+ {2, [?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU]},
+ {2, [?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU]},
+
+
+ {2, [?SCHEME,?PATH_ABS_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?PATH_ROO_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?PATH_EMP,?FRAGMENT_NU]},
+ {2, [?SCHEME,?HOST_NU,?PATH_ABE_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PATH_ABE_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?HOST_NU,?PORT,?PATH_ABE_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU,?FRAGMENT_NU]},
+
+ {2, [?PATH_ABS_NU,?FRAGMENT_NU]},
+ {2, [?PATH_NOS_NU,?FRAGMENT_NU]},
+ {2, [?PATH_EMP,?FRAGMENT_NU]},
+ {2, [?HOST_NU,?PATH_ABE_NU,?FRAGMENT_NU]},
+ {2, [?USER_NU,?HOST_NU,?PATH_ABE_NU,?FRAGMENT_NU]},
+ {2, [?HOST_NU,?PORT,?PATH_ABE_NU,?FRAGMENT_NU]},
+ {2, [?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU,?FRAGMENT_NU]},
+
+
+ {2, [?SCHEME,?PATH_ABS_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?PATH_ROO_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?PATH_EMP,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?HOST_NU,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?SCHEME,?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+
+ {2, [?PATH_ABS_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?PATH_NOS_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?PATH_EMP,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?HOST_NU,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?USER_NU,?HOST_NU,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]},
+ {2, [?USER_NU,?HOST_NU,?PORT,?PATH_ABE_NU,?QUERY_NU,?FRAGMENT_NU]}
+ ]).
+
%%-------------------------------------------------------------------------
%% Path
@@ -174,6 +261,11 @@ path_abempty_map() ->
frequency([{90, path_abe_map()},
{10, path_empty_map()}]).
+path_abempty_map_nu() ->
+ frequency([{90, path_abe_map_nu()},
+ {10, path_empty_map()}]).
+
+
path_abe_map() ->
?SIZED(Length, path_abe_map(Length, [])).
%%
@@ -182,6 +274,14 @@ path_abe_map(0, Segments) ->
path_abe_map(N, Segments) ->
path_abe_map(N-1, [slash(),segment()|Segments]).
+path_abe_map_nu() ->
+ ?SIZED(Length, path_abe_map_nu(Length, [])).
+%%
+path_abe_map_nu(0, Segments) ->
+ ?LET(Gen, Segments, lists:append(Gen));
+path_abe_map_nu(N, Segments) ->
+ path_abe_map_nu(N-1, [slash(),segment_nu()|Segments]).
+
path_absolute_map() ->
?SIZED(Length, path_absolute_map(Length, [])).
@@ -191,6 +291,14 @@ path_absolute_map(0, Segments) ->
path_absolute_map(N, Segments) ->
path_absolute_map(N-1, [slash(),segment()|Segments]).
+path_absolute_map_nu() ->
+ ?SIZED(Length, path_absolute_map_nu(Length, [])).
+%%
+path_absolute_map_nu(0, Segments) ->
+ ?LET(Gen, [slash(),segment_nz_nu()|Segments], lists:append(Gen));
+path_absolute_map_nu(N, Segments) ->
+ path_absolute_map_nu(N-1, [slash(),segment_nu()|Segments]).
+
path_noscheme_map() ->
?SIZED(Length, path_noscheme_map(Length, [])).
@@ -200,6 +308,15 @@ path_noscheme_map(0, Segments) ->
path_noscheme_map(N, Segments) ->
path_noscheme_map(N-1, [slash(),segment()|Segments]).
+path_noscheme_map_nu() ->
+ ?SIZED(Length, path_noscheme_map_nu(Length, [])).
+%%
+path_noscheme_map_nu(0, Segments) ->
+ ?LET(Gen, [segment_nz_nc_nu()|Segments], lists:append(Gen));
+path_noscheme_map_nu(N, Segments) ->
+ path_noscheme_map_nu(N-1, [slash(),segment_nu()|Segments]).
+
+
path_rootless_map() ->
?SIZED(Length, path_rootless_map(Length, [])).
%%
@@ -208,24 +325,59 @@ path_rootless_map(0, Segments) ->
path_rootless_map(N, Segments) ->
path_rootless_map(N-1, [slash(),segment()|Segments]).
+path_rootless_map_nu() ->
+ ?SIZED(Length, path_rootless_map_nu(Length, [])).
+%%
+path_rootless_map_nu(0, Segments) ->
+ ?LET(Gen, [segment_nz_nu()|Segments], lists:append(Gen));
+path_rootless_map_nu(N, Segments) ->
+ path_rootless_map_nu(N-1, [slash(),segment_nu()|Segments]).
+
segment_nz() ->
non_empty(segment()).
-segment_nz_nc() ->
- non_empty(list(frequency([{30, unreserved()},
- {10, sub_delims()},
- {10, unicode_char()},
- {5, oneof([$@])}
- ]))).
+segment_nz_nu() ->
+ non_empty(segment_nu()).
+segment_nz_nc() ->
+ ?LET(Gen,
+ non_empty(list(frequency([{30, unreserved()},
+ {10, ptc_encoded_reserved()},
+ {10, sub_delims()},
+ {10, unicode_char()},
+ {5, oneof([$@])}
+ ]))),
+ lists:flatten(Gen)).
+
+segment_nz_nc_nu() ->
+ ?LET(Gen,
+ non_empty(list(frequency([{30, unreserved()},
+ {10, ptc_encoded_reserved()},
+ {10, sub_delims()},
+ {5, oneof([$@])}
+ ]))),
+ lists:flatten(Gen)).
+
segment() ->
- list(frequency([{30, unreserved()},
- {10, sub_delims()},
- {10, unicode_char()},
- {5, oneof([$:, $@])}
- ])).
+ ?LET(Gen,
+ list(frequency([{30, unreserved()},
+ {10, ptc_encoded_reserved()},
+ {10, sub_delims()},
+ {10, unicode_char()},
+ {5, oneof([$:, $@])}
+ ])),
+ lists:flatten(Gen)).
+
+segment_nu() ->
+ ?LET(Gen,
+ list(frequency([{30, unreserved()},
+ {10, ptc_encoded_reserved()},
+ {10, sub_delims()},
+ {5, oneof([$:, $@])}
+ ])),
+ lists:flatten(Gen)).
slash() ->
"/".
@@ -235,19 +387,35 @@ path_empty_map() ->
%%-------------------------------------------------------------------------
-%% Path
+%% Host
%%-------------------------------------------------------------------------
host_map() ->
frequency([{30, reg_name()},
{30, ip_address()}
]).
+host_map_nu() ->
+ frequency([{30, reg_name_nu()},
+ {30, ip_address()}
+ ]).
reg_name() ->
- list(frequency([{30, alpha()},
- {10, sub_delims()},
- {10, unicode_char()}
- ])).
+ ?LET(Gen,
+ list(frequency([{30, alpha()},
+ {10, sub_delims()},
+ {10, ptc_encoded_reserved()},
+ {10, unicode_char()}
+ ])),
+ lists:flatten(Gen)).
+
+reg_name_nu() ->
+ ?LET(Gen,
+ list(frequency([{30, alpha()},
+ {10, sub_delims()},
+ {10, ptc_encoded_reserved()}
+ ])),
+ lists:flatten(Gen)).
+
ip_address() ->
oneof(["127.0.0.1", "::127.0.0.1",
@@ -258,10 +426,13 @@ ip_address() ->
%% Generating only reg-names
host_uri() ->
- non_empty(list(frequency([{30, unreserved()},
- {10, sub_delims()},
- {10, pct_encoded()}
- ]))).
+ ?LET(Gen,
+ non_empty(list(frequency([{30, unreserved()},
+ {10, sub_delims()},
+ {10, ptc_encoded_reserved()},
+ {10, pct_encoded()}
+ ]))),
+ lists:flatten(Gen)).
%%-------------------------------------------------------------------------
%% Port, Query, Fragment
@@ -274,6 +445,9 @@ port() ->
query_map() ->
unicode().
+query_map_nu() ->
+ non_unicode().
+
query_uri() ->
[$?| non_empty(list(frequency([{20, pchar()},
@@ -283,6 +457,10 @@ query_uri() ->
fragment_map() ->
unicode().
+fragment_map_nu() ->
+ non_unicode().
+
+
fragment_uri() ->
[$?| non_empty(list(frequency([{20, pchar()},
{5, oneof([$/, $?])} % punctuation
@@ -311,9 +489,14 @@ scheme(N, L) ->
%%-------------------------------------------------------------------------
unicode() ->
list(frequency([{20, alpha()}, % alpha
- {10, digit()}, % digit
- {10, unicode_char()} % unicode
- ])).
+ {10, digit()}, % digit
+ {10, unicode_char()} % unicode
+ ])).
+
+non_unicode() ->
+ list(frequency([{20, alpha()}, % alpha
+ {10, digit()} % digit
+ ])).
scheme_char() ->
frequency([{20, alpha()}, % alpha
@@ -327,6 +510,7 @@ sub_delims() ->
pchar() ->
frequency([{20, unreserved()},
+ {5, ptc_encoded_reserved()},
{5, pct_encoded()},
{5, sub_delims()},
{1, oneof([$:, $@])} % punctuation
@@ -351,6 +535,22 @@ digit() ->
pct_encoded() ->
oneof(["%C3%A4", "%C3%A5", "%C3%B6"]).
+%%-------------------------------------------------------------------------
+%% [RFC 3986, Chapter 2.2. Reserved Characters]
+%%
+%% reserved = gen-delims / sub-delims
+%%
+%% gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
+%% 3A 2F 3F 23 5B 5D 40
+%% sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
+%% 21 24 26 27 28 29
+%% / "*" / "+" / "," / ";" / "="
+%% 2A 2B 2C 3B 3D
+%%-------------------------------------------------------------------------
+ptc_encoded_reserved() ->
+ oneof(["%3A","%2F","%3F","%23","%5B","%5D","%40",
+ "%21","%24","%26","%27","%28","%29",
+ "%2A","%2B","%2C","%3B","3D"]).
%%%========================================================================
%%% Helpers
@@ -359,3 +559,13 @@ proplist_to_map(L) ->
lists:foldl(fun({K,V},M) -> M#{K => V};
(_,M) -> M
end, #{}, L).
+
+map_scheme_host_to_lower(Map) ->
+ Fun = fun (scheme,V) ->
+ string:to_lower(V);
+ (host,V) ->
+ string:to_lower(V);
+ (_,V) ->
+ V
+ end,
+ maps:map(Fun, Map).
diff --git a/lib/stdlib/test/uri_string_SUITE.erl b/lib/stdlib/test/uri_string_SUITE.erl
index 92f8bb3292..2aa399525d 100644
--- a/lib/stdlib/test/uri_string_SUITE.erl
+++ b/lib/stdlib/test/uri_string_SUITE.erl
@@ -23,6 +23,12 @@
-export([all/0, suite/0,groups/0,
normalize/1, normalize_map/1, normalize_return_map/1, normalize_negative/1,
+ normalize_binary_pct_encoded_userinfo/1,
+ normalize_binary_pct_encoded_query/1,
+ normalize_binary_pct_encoded_fragment/1,
+ normalize_pct_encoded_userinfo/1,
+ normalize_pct_encoded_query/1,
+ normalize_pct_encoded_fragment/1,
parse_binary_fragment/1, parse_binary_host/1, parse_binary_host_ipv4/1,
parse_binary_host_ipv6/1,
parse_binary_path/1, parse_binary_pct_encoded_fragment/1, parse_binary_pct_encoded_query/1,
@@ -41,7 +47,8 @@
transcode_basic/1, transcode_options/1, transcode_mixed/1, transcode_negative/1,
compose_query/1, compose_query_latin1/1, compose_query_negative/1,
dissect_query/1, dissect_query_negative/1,
- interop_query_latin1/1, interop_query_utf8/1
+ interop_query_latin1/1, interop_query_utf8/1,
+ regression_parse/1, regression_recompose/1, regression_normalize/1
]).
@@ -71,6 +78,12 @@ all() ->
normalize_map,
normalize_return_map,
normalize_negative,
+ normalize_binary_pct_encoded_userinfo,
+ normalize_binary_pct_encoded_query,
+ normalize_binary_pct_encoded_fragment,
+ normalize_pct_encoded_userinfo,
+ normalize_pct_encoded_query,
+ normalize_pct_encoded_fragment,
parse_binary_scheme,
parse_binary_userinfo,
parse_binary_pct_encoded_userinfo,
@@ -120,7 +133,10 @@ all() ->
dissect_query,
dissect_query_negative,
interop_query_latin1,
- interop_query_utf8
+ interop_query_utf8,
+ regression_parse,
+ regression_recompose,
+ regression_normalize
].
groups() ->
@@ -338,20 +354,23 @@ parse_binary_userinfo(_Config) ->
uri_string:parse(<<"foo://user:password@localhost">>).
parse_binary_pct_encoded_userinfo(_Config) ->
- #{scheme := <<"user">>, path := <<"合@気道"/utf8>>} =
+ #{scheme := <<"user">>, path := <<"%E5%90%88@%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"user:%E5%90%88@%E6%B0%97%E9%81%93">>),
- #{path := <<"合気道@"/utf8>>} = uri_string:parse(<<"%E5%90%88%E6%B0%97%E9%81%93@">>),
- #{path := <<"/合気道@"/utf8>>} = uri_string:parse(<<"/%E5%90%88%E6%B0%97%E9%81%93@">>),
- #{path := <<"合@気道"/utf8>>} = uri_string:parse(<<"%E5%90%88@%E6%B0%97%E9%81%93">>),
- #{userinfo := <<"合"/utf8>>, host := <<"気道"/utf8>>} =
+ #{path := <<"%E5%90%88%E6%B0%97%E9%81%93@">>} =
+ uri_string:parse(<<"%E5%90%88%E6%B0%97%E9%81%93@">>),
+ #{path := <<"/%E5%90%88%E6%B0%97%E9%81%93@">>} =
+ uri_string:parse(<<"/%E5%90%88%E6%B0%97%E9%81%93@">>),
+ #{path := <<"%E5%90%88@%E6%B0%97%E9%81%93">>} =
+ uri_string:parse(<<"%E5%90%88@%E6%B0%97%E9%81%93">>),
+ #{userinfo := <<"%E5%90%88">>, host := <<"%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"//%E5%90%88@%E6%B0%97%E9%81%93">>),
- #{userinfo := <<"合:気"/utf8>>, host := <<"道"/utf8>>} =
+ #{userinfo := <<"%E5%90%88:%E6%B0%97">>, host := <<"%E9%81%93">>} =
uri_string:parse(<<"//%E5%90%88:%E6%B0%97@%E9%81%93">>),
- #{scheme := <<"foo">>, path := <<"/合気道@"/utf8>>} =
+ #{scheme := <<"foo">>, path := <<"/%E5%90%88%E6%B0%97%E9%81%93@">>} =
uri_string:parse(<<"foo:/%E5%90%88%E6%B0%97%E9%81%93@">>),
- #{scheme := <<"foo">>, userinfo := <<"合"/utf8>>, host := <<"気道"/utf8>>} =
+ #{scheme := <<"foo">>, userinfo := <<"%E5%90%88">>, host := <<"%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"foo://%E5%90%88@%E6%B0%97%E9%81%93">>),
- #{scheme := <<"foo">>, userinfo := <<"合:気"/utf8>>, host := <<"道"/utf8>>} =
+ #{scheme := <<"foo">>, userinfo := <<"%E5%90%88:%E6%B0%97">>, host := <<"%E9%81%93">>} =
uri_string:parse(<<"foo://%E5%90%88:%E6%B0%97@%E9%81%93">>),
{error,invalid_uri,"@"} = uri_string:parse(<<"//%E5%90%88@%E6%B0%97%E9%81%93@">>),
{error,invalid_uri,":"} = uri_string:parse(<<"foo://%E5%90%88@%E6%B0%97%E9%81%93@">>).
@@ -369,8 +388,8 @@ parse_binary_host_ipv4(_Config) ->
#{host := <<"127.0.0.1">>, query := <<"name=ferret">>} =
uri_string:parse(<<"//127.0.0.1?name=ferret">>),
#{host := <<"127.0.0.1">>, fragment := <<"nose">>} = uri_string:parse(<<"//127.0.0.1#nose">>),
- {error,invalid_uri,"x"} = uri_string:parse(<<"//127.0.0.x">>),
- {error,invalid_uri,"1227.0.0.1"} = uri_string:parse(<<"//1227.0.0.1">>).
+ #{host := <<"127.0.0.x">>,path := <<>>} = uri_string:parse(<<"//127.0.0.x">>),
+ #{host := <<"1227.0.0.1">>,path := <<>>} = uri_string:parse(<<"//1227.0.0.1">>).
parse_binary_host_ipv6(_Config) ->
#{host := <<"::127.0.0.1">>} = uri_string:parse(<<"//[::127.0.0.1]">>),
@@ -439,9 +458,9 @@ parse_binary_query(_Config) ->
parse_binary_pct_encoded_query(_Config) ->
#{scheme := <<"foo">>, host := <<"example.com">>, path := <<"/">>,
- query := <<"name=合気道"/utf8>>} =
+ query := <<"name=%E5%90%88%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"foo://example.com/?name=%E5%90%88%E6%B0%97%E9%81%93">>),
- #{host := <<"example.com">>, path := <<"/">>, query := <<"name=合気道"/utf8>>} =
+ #{host := <<"example.com">>, path := <<"/">>, query := <<"name=%E5%90%88%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"//example.com/?name=%E5%90%88%E6%B0%97%E9%81%93">>).
parse_binary_fragment(_Config) ->
@@ -472,9 +491,11 @@ parse_binary_fragment(_Config) ->
uri_string:parse(<<"//example.com/#nose">>).
parse_binary_pct_encoded_fragment(_Config) ->
- #{scheme := <<"foo">>, host := <<"example.com">>, fragment := <<"合気道"/utf8>>} =
+ #{scheme := <<"foo">>, host := <<"example.com">>,
+ fragment := <<"%E5%90%88%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"foo://example.com#%E5%90%88%E6%B0%97%E9%81%93">>),
- #{host := <<"example.com">>, path := <<"/">>, fragment := <<"合気道"/utf8>>} =
+ #{host := <<"example.com">>, path := <<"/">>,
+ fragment := <<"%E5%90%88%E6%B0%97%E9%81%93">>} =
uri_string:parse(<<"//example.com/#%E5%90%88%E6%B0%97%E9%81%93">>).
parse_scheme(_Config) ->
@@ -506,25 +527,27 @@ parse_userinfo(_Config) ->
uri_string:parse("foo://user:password@localhost").
parse_pct_encoded_userinfo(_Config) ->
- #{scheme := "user", path := "合@気道"} =
+ #{scheme := "user", path := "%E5%90%88@%E6%B0%97%E9%81%93"} =
uri_string:parse("user:%E5%90%88@%E6%B0%97%E9%81%93"),
- #{path := "合気道@"} = uri_string:parse("%E5%90%88%E6%B0%97%E9%81%93@"),
- #{path := "/合気道@"} = uri_string:parse("/%E5%90%88%E6%B0%97%E9%81%93@"),
- #{path := "合@気道"} = uri_string:parse("%E5%90%88@%E6%B0%97%E9%81%93"),
- #{userinfo := "合", host := "気道"} =
+ #{path := "%E5%90%88%E6%B0%97%E9%81%93@"} =
+ uri_string:parse("%E5%90%88%E6%B0%97%E9%81%93@"),
+ #{path := "/%E5%90%88%E6%B0%97%E9%81%93@"} =
+ uri_string:parse("/%E5%90%88%E6%B0%97%E9%81%93@"),
+ #{path := "%E5%90%88@%E6%B0%97%E9%81%93"} =
+ uri_string:parse("%E5%90%88@%E6%B0%97%E9%81%93"),
+ #{userinfo := "%E5%90%88", host := "%E6%B0%97%E9%81%93"} =
uri_string:parse("//%E5%90%88@%E6%B0%97%E9%81%93"),
- #{userinfo := "合:気", host := "道"} =
+ #{userinfo := "%E5%90%88:%E6%B0%97", host := "%E9%81%93"} =
uri_string:parse("//%E5%90%88:%E6%B0%97@%E9%81%93"),
- #{scheme := "foo", path := "/合気道@"} =
+ #{scheme := "foo", path := "/%E5%90%88%E6%B0%97%E9%81%93@"} =
uri_string:parse("foo:/%E5%90%88%E6%B0%97%E9%81%93@"),
- #{scheme := "foo", userinfo := "合", host := "気道"} =
+ #{scheme := "foo", userinfo := "%E5%90%88", host := "%E6%B0%97%E9%81%93"} =
uri_string:parse("foo://%E5%90%88@%E6%B0%97%E9%81%93"),
- #{scheme := "foo", userinfo := "合:気", host := "道"} =
+ #{scheme := "foo", userinfo := "%E5%90%88:%E6%B0%97", host := "%E9%81%93"} =
uri_string:parse("foo://%E5%90%88:%E6%B0%97@%E9%81%93"),
{error,invalid_uri,"@"} = uri_string:parse("//%E5%90%88@%E6%B0%97%E9%81%93@"),
{error,invalid_uri,":"} = uri_string:parse("foo://%E5%90%88@%E6%B0%97%E9%81%93@").
-
parse_host(_Config) ->
#{host := "hostname"} = uri_string:parse("//hostname"),
#{host := "hostname",scheme := "foo"} = uri_string:parse("foo://hostname"),
@@ -538,8 +561,8 @@ parse_host_ipv4(_Config) ->
#{host := "127.0.0.1", path := "/over/there"} = uri_string:parse("//127.0.0.1/over/there"),
#{host := "127.0.0.1", query := "name=ferret"} = uri_string:parse("//127.0.0.1?name=ferret"),
#{host := "127.0.0.1", fragment := "nose"} = uri_string:parse("//127.0.0.1#nose"),
- {error,invalid_uri,"x"} = uri_string:parse("//127.0.0.x"),
- {error,invalid_uri,"1227.0.0.1"} = uri_string:parse("//1227.0.0.1").
+ #{host := "127.0.0.x",path := []} = uri_string:parse("//127.0.0.x"),
+ #{host := "1227.0.0.1",path := []} = uri_string:parse("//1227.0.0.1").
parse_host_ipv6(_Config) ->
#{host := "::127.0.0.1"} = uri_string:parse("//[::127.0.0.1]"),
@@ -602,9 +625,9 @@ parse_query(_Config) ->
parse_pct_encoded_query(_Config) ->
#{scheme := "foo", host := "example.com", path := "/",
- query := "name=合気道"} =
+ query := "name=%E5%90%88%E6%B0%97%E9%81%93"} =
uri_string:parse("foo://example.com/?name=%E5%90%88%E6%B0%97%E9%81%93"),
- #{host := "example.com", path := "/", query := "name=合気道"} =
+ #{host := "example.com", path := "/", query := "name=%E5%90%88%E6%B0%97%E9%81%93"} =
uri_string:parse("//example.com/?name=%E5%90%88%E6%B0%97%E9%81%93").
parse_fragment(_Config) ->
@@ -635,9 +658,11 @@ parse_fragment(_Config) ->
uri_string:parse("//example.com/#nose").
parse_pct_encoded_fragment(_Config) ->
- #{scheme := "foo", host := "example.com", fragment := "合気道"} =
+ #{scheme := "foo", host := "example.com",
+ fragment := "%E5%90%88%E6%B0%97%E9%81%93"} =
uri_string:parse("foo://example.com#%E5%90%88%E6%B0%97%E9%81%93"),
- #{host := "example.com", path := "/", fragment := "合気道"} =
+ #{host := "example.com", path := "/",
+ fragment := "%E5%90%88%E6%B0%97%E9%81%93"} =
uri_string:parse("//example.com/#%E5%90%88%E6%B0%97%E9%81%93").
parse_list(_Config) ->
@@ -711,9 +736,7 @@ parse_negative(_Config) ->
{error,invalid_uri,":"} = uri_string:parse("foo://usär@host"),
{error,invalid_uri,"ö"} = uri_string:parse("//host/path?foö=bar"),
{error,invalid_uri,"ö"} = uri_string:parse("//host/path#foö"),
- {error,invalid_uri,"127.256.0.1"} = uri_string:parse("//127.256.0.1"),
{error,invalid_uri,":::127.0.0.1"} = uri_string:parse("//[:::127.0.0.1]"),
- {error,invalid_utf8,<<0,0,0,246>>} = uri_string:parse("//%00%00%00%F6"),
{error,invalid_uri,"A"} = uri_string:parse("//localhost:A8").
@@ -913,7 +936,9 @@ normalize(_Config) ->
<<"sftp://localhost">> =
uri_string:normalize(<<"sftp://localhost:22">>),
<<"tftp://localhost">> =
- uri_string:normalize(<<"tftp://localhost:69">>).
+ uri_string:normalize(<<"tftp://localhost:69">>),
+ <<"/foo/%2F/bar">> =
+ uri_string:normalize(<<"/foo/%2f/%62ar">>).
normalize_map(_Config) ->
"/a/g" = uri_string:normalize(#{path => "/a/b/c/./../../g"}),
@@ -942,7 +967,9 @@ normalize_map(_Config) ->
host => <<"localhost">>}),
<<"tftp://localhost">> =
uri_string:normalize(#{scheme => <<"tftp">>,port => 69,path => <<>>,
- host => <<"localhost">>}).
+ host => <<"localhost">>}),
+ "/foo/%2F/bar" =
+ uri_string:normalize(#{path => "/foo/%2f/%62ar"}).
normalize_return_map(_Config) ->
#{scheme := "http",path := "/a/g",host := "localhost-örebro"} =
@@ -963,7 +990,82 @@ normalize_negative(_Config) ->
{error,invalid_uri,":"} =
uri_string:normalize("http://[192.168.0.1]", [return_map]),
{error,invalid_uri,":"} =
- uri_string:normalize(<<"http://[192.168.0.1]">>, [return_map]).
+ uri_string:normalize(<<"http://[192.168.0.1]">>, [return_map]),
+ {error,invalid_utf8,<<0,0,0,246>>} = uri_string:normalize("//%00%00%00%F6").
+
+normalize_binary_pct_encoded_userinfo(_Config) ->
+ #{scheme := <<"user">>, path := <<"合@気道"/utf8>>} =
+ uri_string:normalize(<<"user:%E5%90%88@%E6%B0%97%E9%81%93">>, [return_map]),
+ #{path := <<"合気道@"/utf8>>} =
+ uri_string:normalize(<<"%E5%90%88%E6%B0%97%E9%81%93@">>, [return_map]),
+ #{path := <<"/合気道@"/utf8>>} =
+ uri_string:normalize(<<"/%E5%90%88%E6%B0%97%E9%81%93@">>, [return_map]),
+ #{path := <<"合@気道"/utf8>>} =
+ uri_string:normalize(<<"%E5%90%88@%E6%B0%97%E9%81%93">>, [return_map]),
+ #{userinfo := <<"合"/utf8>>, host := <<"気道"/utf8>>} =
+ uri_string:normalize(<<"//%E5%90%88@%E6%B0%97%E9%81%93">>, [return_map]),
+ #{userinfo := <<"合:気"/utf8>>, host := <<"道"/utf8>>} =
+ uri_string:normalize(<<"//%E5%90%88:%E6%B0%97@%E9%81%93">>, [return_map]),
+ #{scheme := <<"foo">>, path := <<"/合気道@"/utf8>>} =
+ uri_string:normalize(<<"foo:/%E5%90%88%E6%B0%97%E9%81%93@">>, [return_map]),
+ #{scheme := <<"foo">>, userinfo := <<"合"/utf8>>, host := <<"気道"/utf8>>} =
+ uri_string:normalize(<<"foo://%E5%90%88@%E6%B0%97%E9%81%93">>, [return_map]),
+ #{scheme := <<"foo">>, userinfo := <<"合:気"/utf8>>, host := <<"道"/utf8>>} =
+ uri_string:normalize(<<"foo://%E5%90%88:%E6%B0%97@%E9%81%93">>, [return_map]),
+ {error,invalid_uri,"@"} =
+ uri_string:normalize(<<"//%E5%90%88@%E6%B0%97%E9%81%93@">>, [return_map]),
+ {error,invalid_uri,":"} =
+ uri_string:normalize(<<"foo://%E5%90%88@%E6%B0%97%E9%81%93@">>, [return_map]).
+
+normalize_binary_pct_encoded_query(_Config) ->
+ #{scheme := <<"foo">>, host := <<"example.com">>, path := <<"/">>,
+ query := <<"name=合気道"/utf8>>} =
+ uri_string:normalize(<<"foo://example.com/?name=%E5%90%88%E6%B0%97%E9%81%93">>, [return_map]),
+ #{host := <<"example.com">>, path := <<"/">>, query := <<"name=合気道"/utf8>>} =
+ uri_string:normalize(<<"//example.com/?name=%E5%90%88%E6%B0%97%E9%81%93">>, [return_map]).
+
+normalize_binary_pct_encoded_fragment(_Config) ->
+ #{scheme := <<"foo">>, host := <<"example.com">>, fragment := <<"合気道"/utf8>>} =
+ uri_string:normalize(<<"foo://example.com#%E5%90%88%E6%B0%97%E9%81%93">>, [return_map]),
+ #{host := <<"example.com">>, path := <<"/">>, fragment := <<"合気道"/utf8>>} =
+ uri_string:normalize(<<"//example.com/#%E5%90%88%E6%B0%97%E9%81%93">>, [return_map]).
+
+normalize_pct_encoded_userinfo(_Config) ->
+ #{scheme := "user", path := "合@気道"} =
+ uri_string:normalize("user:%E5%90%88@%E6%B0%97%E9%81%93", [return_map]),
+ #{path := "合気道@"} =
+ uri_string:normalize("%E5%90%88%E6%B0%97%E9%81%93@", [return_map]),
+ #{path := "/合気道@"} =
+ uri_string:normalize("/%E5%90%88%E6%B0%97%E9%81%93@", [return_map]),
+ #{path := "合@気道"} =
+ uri_string:normalize("%E5%90%88@%E6%B0%97%E9%81%93", [return_map]),
+ #{userinfo := "合", host := "気道"} =
+ uri_string:normalize("//%E5%90%88@%E6%B0%97%E9%81%93", [return_map]),
+ #{userinfo := "合:気", host := "道"} =
+ uri_string:normalize("//%E5%90%88:%E6%B0%97@%E9%81%93", [return_map]),
+ #{scheme := "foo", path := "/合気道@"} =
+ uri_string:normalize("foo:/%E5%90%88%E6%B0%97%E9%81%93@", [return_map]),
+ #{scheme := "foo", userinfo := "合", host := "気道"} =
+ uri_string:normalize("foo://%E5%90%88@%E6%B0%97%E9%81%93", [return_map]),
+ #{scheme := "foo", userinfo := "合:気", host := "道"} =
+ uri_string:normalize("foo://%E5%90%88:%E6%B0%97@%E9%81%93", [return_map]),
+ {error,invalid_uri,"@"} =
+ uri_string:normalize("//%E5%90%88@%E6%B0%97%E9%81%93@", [return_map]),
+ {error,invalid_uri,":"} =
+ uri_string:normalize("foo://%E5%90%88@%E6%B0%97%E9%81%93@", [return_map]).
+
+normalize_pct_encoded_query(_Config) ->
+ #{scheme := "foo", host := "example.com", path := "/",
+ query := "name=合気道"} =
+ uri_string:normalize("foo://example.com/?name=%E5%90%88%E6%B0%97%E9%81%93", [return_map]),
+ #{host := "example.com", path := "/", query := "name=合気道"} =
+ uri_string:normalize("//example.com/?name=%E5%90%88%E6%B0%97%E9%81%93", [return_map]).
+
+normalize_pct_encoded_fragment(_Config) ->
+ #{scheme := "foo", host := "example.com", fragment := "合気道"} =
+ uri_string:normalize("foo://example.com#%E5%90%88%E6%B0%97%E9%81%93", [return_map]),
+ #{host := "example.com", path := "/", fragment := "合気道"} =
+ uri_string:normalize("//example.com/#%E5%90%88%E6%B0%97%E9%81%93", [return_map]).
interop_query_utf8(_Config) ->
Q = uri_string:compose_query([{"foo bar","1"}, {"合", "2"}]),
@@ -977,3 +1079,86 @@ interop_query_latin1(_Config) ->
Uri1 = uri_string:transcode(Uri, [{in_encoding, latin1}]),
#{query := Q1} = uri_string:parse(Uri1),
[{"foo bar","1"}, {"合", "2"}] = uri_string:dissect_query(Q1).
+
+regression_parse(_Config) ->
+ #{host := "Bar",path := [],scheme := "FOo"} =
+ uri_string:parse("FOo://Bar"),
+ #{host := "bar",path := [],scheme := "foo"} =
+ uri_string:parse("foo://bar"),
+ #{host := "A%2f",path := "/%62ar",scheme := "foo"} =
+ uri_string:parse("foo://A%2f/%62ar"),
+ #{host := "a%2F",path := "/bar",scheme := "foo"} =
+ uri_string:parse("foo://a%2F/bar"),
+ #{host := "%C3%B6",path := [],scheme := "FOo"} =
+ uri_string:parse("FOo://%C3%B6").
+
+regression_recompose(_Config) ->
+ "FOo://Bar" =
+ uri_string:recompose(#{host => "Bar",path => [],scheme => "FOo"}),
+ "foo://bar" =
+ uri_string:recompose(#{host => "bar",path => [],scheme => "foo"}),
+ "foo://A%2f/%62ar" =
+ uri_string:recompose(#{host => "A%2f",path => "/%62ar",scheme => "foo"}),
+ "foo://a%2F/bar" =
+ uri_string:recompose(#{host => "a%2F",path => "/bar",scheme => "foo"}),
+ "FOo://%C3%B6" =
+ uri_string:recompose(#{host => "%C3%B6",path => [],scheme => "FOo"}),
+ "FOo://%C3%B6" =
+ uri_string:recompose(#{host => "ö",path => [],scheme => "FOo"}).
+
+regression_normalize(_Config) ->
+ "foo://bar" =
+ uri_string:normalize("FOo://Bar"),
+ #{host := "bar",path := [],scheme := "foo"} =
+ uri_string:normalize("FOo://Bar", [return_map]),
+
+ "foo://bar" =
+ uri_string:normalize("foo://bar"),
+ #{host := "bar",path := [],scheme := "foo"} =
+ uri_string:normalize("foo://bar", [return_map]),
+
+ "foo://a%2F/bar" =
+ uri_string:normalize("foo://A%2f/%62ar"),
+ #{host := "a%2F",path := "/bar",scheme := "foo"} =
+ uri_string:normalize("foo://A%2f/%62ar", [return_map]),
+
+ "foo://a%2F/bar" =
+ uri_string:normalize("foo://a%2F/bar"),
+ #{host := "a%2F",path := "/bar",scheme := "foo"} =
+ uri_string:normalize("foo://a%2F/bar", [return_map]),
+
+ "foo://%C3%B6" =
+ uri_string:normalize("FOo://%C3%B6"),
+ #{host := "ö",path := [],scheme := "foo"} =
+ uri_string:normalize("FOo://%C3%B6", [return_map]),
+
+
+ "foo://bar" =
+ uri_string:normalize(#{host => "Bar",path => [],scheme => "FOo"}),
+ #{host := "bar",path := [],scheme := "foo"} =
+ uri_string:normalize(#{host => "Bar",path => [],scheme => "FOo"}, [return_map]),
+
+ "foo://bar" =
+ uri_string:normalize(#{host => "bar",path => [],scheme => "foo"}),
+ #{host := "bar",path := [],scheme := "foo"} =
+ uri_string:normalize(#{host => "bar",path => [],scheme => "foo"}, [return_map]),
+
+ "foo://a%2F/bar" =
+ uri_string:normalize(#{host => "A%2f",path => "/%62ar",scheme => "foo"}),
+ #{host := "a%2F",path := "/bar",scheme := "foo"} =
+ uri_string:normalize(#{host => "A%2f",path => "/%62ar",scheme => "foo"}, [return_map]),
+
+ "foo://a%2F/bar" =
+ uri_string:normalize(#{host => "a%2F",path => "/bar",scheme => "foo"}),
+ #{host := "a%2F",path := "/bar",scheme := "foo"} =
+ uri_string:normalize(#{host => "a%2F",path => "/bar",scheme => "foo"}, [return_map]),
+
+ "foo://%C3%B6" =
+ uri_string:normalize(#{host => "%C3%B6",path => [],scheme => "FOo"}),
+ #{host := "ö",path := [],scheme := "foo"} =
+ uri_string:normalize(#{host => "%C3%B6",path => [],scheme => "FOo"}, [return_map]),
+
+ "foo://%C3%B6" =
+ uri_string:normalize(#{host => "ö",path => [],scheme => "FOo"}),
+ #{host := "ö",path := [],scheme := "foo"} =
+ uri_string:normalize(#{host => "ö",path => [],scheme => "FOo"}, [return_map]).
diff --git a/lib/stdlib/test/uri_string_property_test_SUITE.erl b/lib/stdlib/test/uri_string_property_test_SUITE.erl
index ae2c61c7aa..b01dd9bf65 100644
--- a/lib/stdlib/test/uri_string_property_test_SUITE.erl
+++ b/lib/stdlib/test/uri_string_property_test_SUITE.erl
@@ -22,7 +22,7 @@
-include_lib("common_test/include/ct.hrl").
-compile(export_all).
-all() -> [recompose].
+all() -> [recompose, normalize].
init_per_suite(Config) ->
ct_property_test:init_per_suite(Config).
@@ -37,3 +37,8 @@ recompose(Config) ->
ct_property_test:quickcheck(
uri_string_recompose:prop_recompose(),
Config).
+
+normalize(Config) ->
+ ct_property_test:quickcheck(
+ uri_string_recompose:prop_normalize(),
+ Config).