diff options
author | Siri Hansen <[email protected]> | 2018-06-04 19:53:02 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2018-06-08 14:41:34 +0200 |
commit | 983a945b84e15f58c3205c37b7bfcad18537325c (patch) | |
tree | a1fdce539da80b497bffe3a2c5cba868cb6755d8 /lib/kernel/test | |
parent | e5bbcfd47088162a1c349eeb5aa3c37d8263d274 (diff) | |
download | otp-983a945b84e15f58c3205c37b7bfcad18537325c.tar.gz otp-983a945b84e15f58c3205c37b7bfcad18537325c.tar.bz2 otp-983a945b84e15f58c3205c37b7bfcad18537325c.zip |
[logger] Add configurable log levels 'all' and 'none'
New default for handlers is 'all'.
Diffstat (limited to 'lib/kernel/test')
-rw-r--r-- | lib/kernel/test/logger_SUITE.erl | 55 | ||||
-rw-r--r-- | lib/kernel/test/logger_env_var_SUITE.erl | 36 |
2 files changed, 66 insertions, 25 deletions
diff --git a/lib/kernel/test/logger_SUITE.erl b/lib/kernel/test/logger_SUITE.erl index a8769c450c..91aaceada5 100644 --- a/lib/kernel/test/logger_SUITE.erl +++ b/lib/kernel/test/logger_SUITE.erl @@ -82,6 +82,7 @@ all() -> add_remove_filter, change_config, set_formatter, + log_no_levels, log_all_levels_api, macros, set_level, @@ -111,7 +112,7 @@ add_remove_handler(_Config) -> [add] = test_server:messages_get(), #{handlers:=Hs} = logger:i(), {value,_,Hs0} = lists:keytake(h1,1,Hs), - {ok,{?MODULE,#{level:=debug,filters:=[],filter_default:=log}}} = % defaults + {ok,{?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(), @@ -215,7 +216,7 @@ change_config(_Config) -> register(callback_receiver,self()), ok = logger:set_handler_config(h1,#{filter_default=>stop}), [changing_config] = test_server:messages_get(), - {ok,{?MODULE,#{level:=debug,filter_default:=stop}=C2}} = + {ok,{?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}), @@ -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_logger_config(level,none), + [logger:Level(#{Level=>rep}) || Level <- Levels], + ok = check_no_log(), + + ok = logger:set_logger_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_logger_level(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_logger_config(level,all), + ok = logger:add_handler(h1,?MODULE,#{level=>all,filter_default=>log}), test_api(emergency), test_api(alert), test_api(critical), @@ -311,8 +353,7 @@ log_all_levels_api(cleanup,_Config) -> 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,7 +363,7 @@ 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), diff --git a/lib/kernel/test/logger_env_var_SUITE.erl b/lib/kernel/test/logger_env_var_SUITE.erl index 03827c9825..f7f293c7fe 100644 --- a/lib/kernel/test/logger_env_var_SUITE.erl +++ b/lib/kernel/test/logger_env_var_SUITE.erl @@ -80,7 +80,7 @@ all() -> default(Config) -> {ok,#{handlers:=Hs},_Node} = setup(Config,[]), {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), true = lists:keymember(stop_progress,1,StdFilters), @@ -92,7 +92,7 @@ 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), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,StdFilters), false = lists:keymember(stop_progress,1,StdFilters), @@ -103,7 +103,7 @@ default_sasl_compatible(Config) -> 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), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), true = lists:keymember(stop_progress,1,StdFilters), @@ -116,7 +116,7 @@ error_logger_tty_sasl_compatible(Config) -> [{error_logger,tty}, {logger_sasl_compatible,true}]), {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,StdFilters), false = lists:keymember(stop_progress,1,StdFilters), @@ -131,7 +131,7 @@ error_logger_false(Config) -> {logger_level,notice}]), false = lists:keymember(?STANDARD_HANDLER,1,Hs), {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs), - debug = maps:get(level,SimpleC), + all = maps:get(level,SimpleC), notice = maps:get(level,L), SimpleFilters = maps:get(filters,SimpleC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,SimpleFilters), @@ -147,7 +147,7 @@ error_logger_false_progress(Config) -> {logger_progress_reports,log}]), false = lists:keymember(?STANDARD_HANDLER,1,Hs), {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs), - debug = maps:get(level,SimpleC), + all = maps:get(level,SimpleC), notice = maps:get(level,L), SimpleFilters = maps:get(filters,SimpleC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,SimpleFilters), @@ -163,7 +163,7 @@ error_logger_false_sasl_compatible(Config) -> {logger_sasl_compatible,true}]), false = lists:keymember(?STANDARD_HANDLER,1,Hs), {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs), - debug = maps:get(level,SimpleC), + all = maps:get(level,SimpleC), notice = maps:get(level,L), SimpleFilters = maps:get(filters,SimpleC), {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,SimpleFilters), @@ -211,7 +211,7 @@ logger_file(Config) -> 0),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), true = lists:keymember(stop_progress,1,StdFilters), @@ -233,7 +233,7 @@ logger_file_sasl_compatible(Config) -> 0),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp]}}} = lists:keyfind(domain,1,StdFilters), false = lists:keymember(stop_progress,1,StdFilters), @@ -255,7 +255,7 @@ logger_file_log_progress(Config) -> 6),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), false = lists:keymember(stop_progress,1,StdFilters), @@ -277,7 +277,7 @@ logger_file_no_filter(Config) -> 6),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), [] = maps:get(filters,StdC), false = lists:keymember(simple,1,Hs), false = lists:keymember(sasl,1,Hs), @@ -319,7 +319,7 @@ logger_file_formatter(Config) -> 6),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), [] = maps:get(filters,StdC), false = lists:keymember(simple,1,Hs), false = lists:keymember(sasl,1,Hs), @@ -341,7 +341,7 @@ logger_filters(Config) -> 0),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), false = lists:keymember(stop_progress,1,StdFilters), @@ -369,7 +369,7 @@ logger_filters_stop(Config) -> notice), {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), [] = maps:get(filters,StdC), false = lists:keymember(simple,1,Hs), false = lists:keymember(sasl,1,Hs), @@ -393,7 +393,7 @@ logger_module_level(Config) -> 3),% progress in std logger {?STANDARD_HANDLER,logger_std_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), false = lists:keymember(stop_progress,1,StdFilters), @@ -414,7 +414,7 @@ logger_disk_log(Config) -> 0),% progress in std logger {?STANDARD_HANDLER,logger_disk_log_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), StdFilters = maps:get(filters,StdC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,StdFilters), true = lists:keymember(stop_progress,1,StdFilters), @@ -437,7 +437,7 @@ logger_disk_log_formatter(Config) -> 6),% progress in std logger {?STANDARD_HANDLER,logger_disk_log_h,StdC} = lists:keyfind(?STANDARD_HANDLER,1,Hs), - debug = maps:get(level,StdC), + all = maps:get(level,StdC), [] = maps:get(filters,StdC), false = lists:keymember(simple,1,Hs), false = lists:keymember(sasl,1,Hs), @@ -449,7 +449,7 @@ logger_undefined(Config) -> setup(Config,[{logger,[{handler,?STANDARD_HANDLER,undefined}]}]), false = lists:keymember(?STANDARD_HANDLER,1,Hs), {simple,logger_simple_h,SimpleC} = lists:keyfind(simple,1,Hs), - debug = maps:get(level,SimpleC), + all = maps:get(level,SimpleC), info = maps:get(level,L), SimpleFilters = maps:get(filters,SimpleC), {domain,{_,{log,super,[otp,sasl]}}} = lists:keyfind(domain,1,SimpleFilters), |