aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2018-06-05 20:50:01 +0200
committerSiri Hansen <[email protected]>2018-06-08 14:47:07 +0200
commit2ab3e91a44032cab2b173efc33b5d9589eec4864 (patch)
treea03c932a74f029a7d6a8e9dd5d348127e2975aed /lib
parent35c311607ed5b5a9ddea8c9a9be7c3b41845c737 (diff)
downloadotp-2ab3e91a44032cab2b173efc33b5d9589eec4864.tar.gz
otp-2ab3e91a44032cab2b173efc33b5d9589eec4864.tar.bz2
otp-2ab3e91a44032cab2b173efc33b5d9589eec4864.zip
[logger] Add more functions for reading configuration
Added: * logger:get_config() - replaces i(), returns all Logger configuration, i.e. primary and handler config, and module levels * logger:get_handler_ids() -> [HandlerId] * logger:get_handler_config() -> [{HandlerId,Module,Config}] Removed: * logger:i/1, will probably be replaced in a later release.
Diffstat (limited to 'lib')
-rw-r--r--lib/kernel/src/logger.erl105
-rw-r--r--lib/kernel/test/logger_SUITE.erl44
-rw-r--r--lib/kernel/test/logger_bench_SUITE.erl2
-rw-r--r--lib/kernel/test/logger_disk_log_h_SUITE.erl4
-rw-r--r--lib/kernel/test/logger_simple_h_SUITE.erl2
-rw-r--r--lib/kernel/test/logger_std_h_SUITE.erl6
-rw-r--r--lib/kernel/test/logger_test_lib.erl2
-rw-r--r--lib/sasl/test/sasl_report_SUITE.erl2
8 files changed, 56 insertions, 111 deletions
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 9f96a537bc..b251b21bff 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -45,6 +45,7 @@
update_primary_config/1, update_handler_config/2,
update_formatter_config/2, update_formatter_config/3,
get_primary_config/0, get_handler_config/1,
+ get_handler_config/0, get_handler_ids/0, get_config/0,
add_handlers/1]).
%% Private configuration
@@ -54,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]).
@@ -382,11 +382,11 @@ update_primary_config(Config) ->
update_handler_config(HandlerId,Config) ->
logger_server:update_config(HandlerId,Config).
--spec get_primary_config() -> {ok,Config} when
+-spec get_primary_config() -> Config when
Config :: config().
get_primary_config() ->
{ok,Config} = logger_config:get(?LOGGER_TABLE,primary),
- {ok,maps:remove(handlers,Config)}.
+ maps:remove(handlers,Config).
-spec get_handler_config(HandlerId) -> {ok,{Module,Config}} | {error,term()} when
HandlerId :: handler_id(),
@@ -395,6 +395,22 @@ get_primary_config() ->
get_handler_config(HandlerId) ->
logger_config:get(?LOGGER_TABLE,HandlerId).
+-spec get_handler_config() -> [{HandlerId,Module,Config}] when
+ HandlerId :: handler_id(),
+ Module :: module(),
+ Config :: config().
+get_handler_config() ->
+ [begin
+ {ok,{Module,Config}} = get_handler_config(HandlerId),
+ {HandlerId,Module,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(),
@@ -492,82 +508,13 @@ unset_process_metadata() ->
_ = erase(?LOGGER_META_KEY),
ok.
--spec i() -> #{primary=>config(),
- handlers=>[{handler_id(),module(),config()}],
- module_levels=>[{module(),level() | all | none}]}.
-i() ->
- i(term).
-
--spec i(term) -> #{primary=>config(),
- handlers=>[{handler_id(),module(),config()}],
- module_levels=>[{module(),level() | all | none}]};
- (print) -> ok;
- (string) -> iolist().
-i(_Action = print) ->
- io:put_chars(i(string));
-i(_Action = string) ->
- #{primary := #{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) ->
- {Primary, Handlers, Modules} = logger_config:get(?LOGGER_TABLE),
- #{primary=>maps:remove(handlers,Primary),
- 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=>config(),
+ handlers=>[{handler_id(),module(),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
diff --git a/lib/kernel/test/logger_SUITE.erl b/lib/kernel/test/logger_SUITE.erl
index bbf60cad74..c24738718e 100644
--- a/lib/kernel/test/logger_SUITE.erl
+++ b/lib/kernel/test/logger_SUITE.erl
@@ -63,8 +63,8 @@ end_per_group(_Group, _Config) ->
ok.
init_per_testcase(_TestCase, Config) ->
- {ok,LC} = logger:get_primary_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])
@@ -106,11 +106,11 @@ 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(),
+ Hs = logger:get_handler_config(),
{value,_,Hs0} = lists:keytake(h1,1,Hs),
{ok,{?MODULE,#{level:=all,filters:=[],filter_default:=log}}} = % defaults
logger:get_handler_config(h1),
@@ -125,7 +125,7 @@ add_remove_handler(_Config) ->
ok = check_logged(info,"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",[]),
@@ -242,37 +242,37 @@ change_config(_Config) ->
C4 = C3#{custom:=new_custom},
%% Change primary config: Single key
- {ok,LConfig0} = logger:get_primary_config(),
+ PConfig0 = logger:get_primary_config(),
ok = logger:set_primary_config(level,warning),
- {ok,LConfig1} = logger:get_primary_config(),
- LConfig1 = LConfig0#{level:=warning},
+ PConfig1 = logger:get_primary_config(),
+ PConfig1 = PConfig0#{level:=warning},
%% Change primary config: Map
ok = logger:update_primary_config(#{level=>error}),
- {ok,LConfig2} = logger:get_primary_config(),
- LConfig2 = LConfig1#{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}),
- {ok,#{level:=info,filters:=[],filter_default:=stop}=LC1} =
+ #{level:=info,filters:=[],filter_default:=stop}=PC1 =
logger:get_primary_config(),
- 3 = maps:size(LC1),
+ 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,primary),
+ MS = [{{{?HANDLER_KEY,'$1'},'_','_','_'},[],['$1']}],
+ HIds1 = ets:select(?LOGGER_TABLE,MS), % dirty, checking internal data
+ HIds2 = logger:get_handler_ids(),
HIds1 = lists:sort(HIds2),
%% Cleanup
- ok = logger:set_primary_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_primary_config(LC),
+ PC = ?config(logger_config,Config),
+ logger:set_primary_config(PC),
ok.
set_formatter(_Config) ->
@@ -470,13 +470,13 @@ filter_failed(_Config) ->
{error,{invalid_filter,_}} =
logger:add_primary_filter(lf,{fun(_) -> ok end,args}),
ok = logger:add_primary_filter(lf,{fun(_,_) -> a=b end,args}),
- {ok,#{filters:=[_]}} = logger:get_primary_config(),
+ #{filters:=[_]} = logger:get_primary_config(),
ok = logger:info(M1=?map_rep),
ok = check_logged(info,M1,#{}),
{error,{not_found,lf}} = logger:remove_primary_filter(lf),
ok = logger:add_primary_filter(lf,{fun(_,_) -> faulty_return end,args}),
- {ok,#{filters:=[_]}} = logger:get_primary_config(),
+ #{filters:=[_]} = logger:get_primary_config(),
ok = logger:info(M2=?map_rep),
ok = check_logged(info,M2,#{}),
{error,{not_found,lf}} = logger:remove_primary_filter(lf),
@@ -519,7 +519,7 @@ handler_failed(_Config) ->
{error,{invalid_handler,_}} = logger:add_handler(h1,nomodule,#{filter_default=>log}),
logger:info(?map_rep),
check_no_log(),
- #{handlers:=H1} = logger:i(),
+ H1 = logger:get_handler_config(),
false = lists:keymember(h1,1,H1),
{error,{not_found,h1}} = logger:remove_handler(h1),
@@ -529,7 +529,7 @@ handler_failed(_Config) ->
logger:info(?map_rep),
[remove] = test_server:messages_get(),
- #{handlers:=H2} = logger:i(),
+ H2 = logger:get_handler_config(),
false = lists:keymember(h2,1,H2),
{error,{not_found,h2}} = logger:remove_handler(h2),
diff --git a/lib/kernel/test/logger_bench_SUITE.erl b/lib/kernel/test/logger_bench_SUITE.erl
index 63fd4191af..5ac0ace41b 100644
--- a/lib/kernel/test/logger_bench_SUITE.erl
+++ b/lib/kernel/test/logger_bench_SUITE.erl
@@ -365,7 +365,7 @@ calc_and_report(Config,Tag,MSecs,Times) ->
{save_config,[{bench,[{Tag,IOPS,MSecs}|Bench]}]}.
remove_all_handlers() ->
- #{handlers:=Hs} = logger:i(),
+ Hs = logger:get_handler_config(),
[logger:remove_handler(Id) || {Id,_,_} <- Hs],
Hs.
diff --git a/lib/kernel/test/logger_disk_log_h_SUITE.erl b/lib/kernel/test/logger_disk_log_h_SUITE.erl
index b2aa8fa51f..4fada8ab3a 100644
--- a/lib/kernel/test/logger_disk_log_h_SUITE.erl
+++ b/lib/kernel/test/logger_disk_log_h_SUITE.erl
@@ -328,7 +328,7 @@ formatter_fail(Config) ->
logger:add_handler(Name, logger_disk_log_h, HConfig),
Pid = whereis(h_proc_name(Name)),
true = is_pid(Pid),
- #{handlers:=HC1} = logger:i(),
+ HC1 = logger:get_handler_config(),
H = [Id || {Id,_,_} <- HC1],
true = lists:member(Name,H),
@@ -358,7 +358,7 @@ formatter_fail(Config) ->
%% Check that handler is still alive and was never dead
Pid = whereis(h_proc_name(Name)),
- #{handlers:=HC2} = logger:i(),
+ HC2 = logger:get_handler_config(),
H = [Id || {Id,_,_} <- HC2],
ok.
diff --git a/lib/kernel/test/logger_simple_h_SUITE.erl b/lib/kernel/test/logger_simple_h_SUITE.erl
index 271a2126de..264cddb069 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)} ||
diff --git a/lib/kernel/test/logger_std_h_SUITE.erl b/lib/kernel/test/logger_std_h_SUITE.erl
index fa90be0fc8..332d58eac8 100644
--- a/lib/kernel/test/logger_std_h_SUITE.erl
+++ b/lib/kernel/test/logger_std_h_SUITE.erl
@@ -242,8 +242,7 @@ formatter_fail(Config) ->
filters=>?DEFAULT_HANDLER_FILTERS([?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
@@ -272,8 +271,7 @@ formatter_fail(Config) ->
%% Check that handler is still alive and was never dead
Pid = whereis(h_proc_name()),
- #{handlers:=HC2} = logger:i(),
- H = [Id || {Id,_,_} <- HC2],
+ H = logger:get_handler_ids(),
ok.
diff --git a/lib/kernel/test/logger_test_lib.erl b/lib/kernel/test/logger_test_lib.erl
index 5ad6336925..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} ->
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(),