aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kernel')
-rw-r--r--lib/kernel/src/logger.erl12
-rw-r--r--lib/kernel/src/logger_config.erl8
-rw-r--r--lib/kernel/src/logger_internal.hrl8
-rw-r--r--lib/kernel/src/logger_server.erl2
-rw-r--r--lib/kernel/test/logger_SUITE.erl55
-rw-r--r--lib/kernel/test/logger_env_var_SUITE.erl36
6 files changed, 85 insertions, 36 deletions
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 395ec448ff..f18f101930 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -96,7 +96,7 @@
-type filter_arg() :: term().
-type filter_return() :: stop | ignore | log_event().
-type config() :: #{id => handler_id(),
- level => level(),
+ level => level() | all | none,
filter_default => log | stop,
filters => [{filter_id(),filter()}],
formatter => {module(),formatter_config()},
@@ -412,7 +412,7 @@ update_formatter_config(HandlerId,Key,Value) ->
-spec set_module_level(Modules,Level) -> ok | {error,term()} when
Modules :: [module()] | module(),
- Level :: level().
+ Level :: level() | all | none.
set_module_level(Module,Level) when is_atom(Module) ->
set_module_level([Module],Level);
set_module_level(Modules,Level) ->
@@ -432,7 +432,7 @@ unset_module_level() ->
-spec get_module_level(Modules) -> [{Module,Level}] when
Modules :: [Module] | Module,
Module :: module(),
- Level :: level().
+ Level :: level() | all | none.
get_module_level(Module) when is_atom(Module) ->
get_module_level([Module]);
get_module_level(Modules) when is_list(Modules) ->
@@ -441,7 +441,7 @@ get_module_level(Modules) when is_list(Modules) ->
-spec get_module_level() -> [{Module,Level}] when
Module :: module(),
- Level :: level().
+ Level :: level() | all | none.
get_module_level() ->
logger_config:get_module_level(?LOGGER_TABLE).
@@ -494,13 +494,13 @@ unset_process_metadata() ->
-spec i() -> #{logger=>config(),
handlers=>[{handler_id(),module(),config()}],
- module_levels=>[{module(),level()}]}.
+ module_levels=>[{module(),level() | all | none}]}.
i() ->
i(term).
-spec i(term) -> #{logger=>config(),
handlers=>[{handler_id(),module(),config()}],
- module_levels=>[{module(),level()}]};
+ module_levels=>[{module(),level() | all | none}]};
(print) -> ok;
(string) -> iolist().
i(_Action = print) ->
diff --git a/lib/kernel/src/logger_config.erl b/lib/kernel/src/logger_config.erl
index 8d05648109..113c8140cf 100644
--- a/lib/kernel/src/logger_config.erl
+++ b/lib/kernel/src/logger_config.erl
@@ -136,6 +136,7 @@ get(Tid) ->
Modules = get_module_level(Tid),
{Logger,Handlers,Modules}.
+level_to_int(none) -> ?LOG_NONE;
level_to_int(emergency) -> ?EMERGENCY;
level_to_int(alert) -> ?ALERT;
level_to_int(critical) -> ?CRITICAL;
@@ -143,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;
@@ -152,7 +155,8 @@ 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
diff --git a/lib/kernel/src/logger_internal.hrl b/lib/kernel/src/logger_internal.hrl
index 1325e38f74..a6648d2b2c 100644
--- a/lib/kernel/src/logger_internal.hrl
+++ b/lib/kernel/src/logger_internal.hrl
@@ -54,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).
@@ -70,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 164e193fa0..adbb2bc009 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -361,7 +361,7 @@ default_config(logger) ->
filter_default=>log};
default_config(Id) ->
#{id=>Id,
- level=>debug,
+ level=>all,
filters=>[],
filter_default=>log,
formatter=>{?DEFAULT_FORMATTER,#{}}}.
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),