diff options
author | Siri Hansen <[email protected]> | 2018-06-08 17:53:47 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2018-06-11 15:01:42 +0200 |
commit | 4d3fe8ee8d5b079df6172232d4f6864286048028 (patch) | |
tree | c614ac05f176c42991ad367f933b2a19aa9b8224 /lib/kernel/src | |
parent | cca41722c8dc7b83500f14588643ccd82bf3020f (diff) | |
download | otp-4d3fe8ee8d5b079df6172232d4f6864286048028.tar.gz otp-4d3fe8ee8d5b079df6172232d4f6864286048028.tar.bz2 otp-4d3fe8ee8d5b079df6172232d4f6864286048028.zip |
[logger] Split config() in two: primary_config() and handler_config()
Diffstat (limited to 'lib/kernel/src')
-rw-r--r-- | lib/kernel/src/error_logger.erl | 8 | ||||
-rw-r--r-- | lib/kernel/src/logger.erl | 50 | ||||
-rw-r--r-- | lib/kernel/src/logger_disk_log_h.erl | 8 | ||||
-rw-r--r-- | lib/kernel/src/logger_h_common.erl | 2 | ||||
-rw-r--r-- | lib/kernel/src/logger_std_h.erl | 4 |
5 files changed, 38 insertions, 34 deletions
diff --git a/lib/kernel/src/error_logger.erl b/lib/kernel/src/error_logger.erl index a0bf87796b..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). diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl index e0832bf31c..7f10c27bae 100644 --- a/lib/kernel/src/logger.erl +++ b/lib/kernel/src/logger.erl @@ -95,21 +95,25 @@ filter_return()),filter_arg()}. -type filter_arg() :: term(). -type filter_return() :: stop | ignore | log_event(). --type config() :: #{id => handler_id(), - config => map(), - level => level() | all | none, - module => module(), - 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()}, + atom() => term()}. -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]). %%%----------------------------------------------------------------- @@ -340,7 +344,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). @@ -356,7 +360,7 @@ set_primary_config(Key,Value) -> logger_server:set_config(primary,Key,Value). -spec set_primary_config(Config) -> ok | {error,term()} when - Config :: config(). + Config :: primary_config(). set_primary_config(Config) -> logger_server:set_config(primary,Config). @@ -369,30 +373,30 @@ 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_primary_config(Config) -> ok | {error,term()} when - Config :: config(). + 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_primary_config() -> Config when - Config :: config(). + Config :: primary_config(). get_primary_config() -> {ok,Config} = logger_config:get(?LOGGER_TABLE,primary), maps:remove(handlers,Config). -spec get_handler_config(HandlerId) -> {ok,Config} | {error,term()} when HandlerId :: handler_id(), - Config :: config(). + Config :: handler_config(). get_handler_config(HandlerId) -> case logger_config:get(?LOGGER_TABLE,HandlerId) of {ok,{_,Config}} -> @@ -402,7 +406,7 @@ get_handler_config(HandlerId) -> end. -spec get_handler_config() -> [Config] when - Config :: config(). + Config :: handler_config(). get_handler_config() -> [begin {ok,Config} = get_handler_config(HandlerId), @@ -417,14 +421,14 @@ get_handler_ids() -> -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) -> @@ -512,8 +516,8 @@ unset_process_metadata() -> _ = erase(?LOGGER_META_KEY), ok. --spec get_config() -> #{primary=>config(), - handlers=>[config()], +-spec get_config() -> #{primary=>primary_config(), + handlers=>[handler_config()], module_levels=>[{module(),level() | all | none}]}. get_config() -> #{primary=>get_primary_config(), diff --git a/lib/kernel/src/logger_disk_log_h.erl b/lib/kernel/src/logger_disk_log_h.erl index e4b583c269..2676b50580 100644 --- a/lib/kernel/src/logger_disk_log_h.erl +++ b/lib/kernel/src/logger_disk_log_h.erl @@ -50,7 +50,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(). @@ -248,7 +248,7 @@ swap_buffer(Name, Buffer) -> %%% 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, config := #{handler_pid := HPid, @@ -484,8 +484,8 @@ 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 containing a sub map +%%% with any of the following associations: %%% %%% Config = #{disk_log_opts => #{file => file:filename(), %%% max_no_bytes => integer(), diff --git a/lib/kernel/src/logger_h_common.erl b/lib/kernel/src/logger_h_common.erl index b145043522..d556938f02 100644 --- a/lib/kernel/src/logger_h_common.erl +++ b/lib/kernel/src/logger_h_common.erl @@ -43,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); diff --git a/lib/kernel/src/logger_std_h.erl b/lib/kernel/src/logger_std_h.erl index e087178211..827503ddcf 100644 --- a/lib/kernel/src/logger_std_h.erl +++ b/lib/kernel/src/logger_std_h.erl @@ -51,7 +51,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(). @@ -230,7 +230,7 @@ swap_buffer(Name, Buffer) -> %%% 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, config := #{handler_pid := HPid, |