aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/logger_formatter.erl
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2018-05-14 18:03:15 +0200
committerLukas Larsson <[email protected]>2018-05-21 17:43:53 +0200
commitc2c5e22e0c0f67d0c445113b7908dd07e4e8d4c4 (patch)
treedd7bf5cd023d5735fbff13e1525ba0d5203c262c /lib/kernel/src/logger_formatter.erl
parent033bcc2296d7d79c53d56798ab0ccf232f451574 (diff)
downloadotp-c2c5e22e0c0f67d0c445113b7908dd07e4e8d4c4.tar.gz
otp-c2c5e22e0c0f67d0c445113b7908dd07e4e8d4c4.tar.bz2
otp-c2c5e22e0c0f67d0c445113b7908dd07e4e8d4c4.zip
Improve santiy check of formatter config
Diffstat (limited to 'lib/kernel/src/logger_formatter.erl')
-rw-r--r--lib/kernel/src/logger_formatter.erl45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/kernel/src/logger_formatter.erl b/lib/kernel/src/logger_formatter.erl
index 624f523465..0d55244034 100644
--- a/lib/kernel/src/logger_formatter.erl
+++ b/lib/kernel/src/logger_formatter.erl
@@ -20,6 +20,7 @@
-module(logger_formatter).
-export([format/2]).
+-export([check_config/1]).
-include("logger_internal.hrl").
@@ -309,3 +310,47 @@ get_utc_config() ->
undefined -> false
end
end.
+
+check_config(Config) when is_map(Config) ->
+ do_check_config(maps:to_list(Config));
+check_config(Config) ->
+ {error,{invalid_formatter_config,?MODULE,Config}}.
+
+do_check_config([{Type,L}|Config]) when Type == chars_limit;
+ Type == depth;
+ Type == max_size ->
+ case check_limit(L) of
+ ok -> do_check_config(Config);
+ error -> {error,{invalid_formatter_config,?MODULE,{Type,L}}}
+ end;
+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([{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}}
+ end;
+do_check_config([{utc,Utc}|Config]) when is_boolean(Utc) ->
+ do_check_config(Config);
+do_check_config([C|_]) ->
+ {error,{invalid_formatter_config,?MODULE,C}};
+do_check_config([]) ->
+ ok.
+
+check_limit(L) when is_integer(L), L>0 ->
+ ok;
+check_limit(unlimited) ->
+ ok;
+check_limit(_) ->
+ error.