aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiri Hansen <[email protected]>2018-05-18 11:54:32 +0200
committerSiri Hansen <[email protected]>2018-05-23 11:11:13 +0200
commitbe959158a9ebe4b4ed8c336b969ac0c0e9399312 (patch)
tree1961fcf517dde4d42e7dd59a9803eaff89842d59
parenta9a6b803a60793d42a74e0f1693a7594dffb6bc3 (diff)
downloadotp-be959158a9ebe4b4ed8c336b969ac0c0e9399312.tar.gz
otp-be959158a9ebe4b4ed8c336b969ac0c0e9399312.tar.bz2
otp-be959158a9ebe4b4ed8c336b969ac0c0e9399312.zip
Set legacy_header=true for kernel's default handler only
-rw-r--r--lib/kernel/src/logger.erl10
-rw-r--r--lib/kernel/src/logger_h_common.erl2
-rw-r--r--lib/kernel/src/logger_internal.hrl3
-rw-r--r--lib/kernel/src/logger_server.erl2
-rw-r--r--lib/kernel/test/logger_disk_log_h_SUITE.erl15
-rw-r--r--lib/kernel/test/logger_env_var_SUITE.erl4
-rw-r--r--lib/kernel/test/logger_simple_SUITE.erl6
-rw-r--r--lib/kernel/test/logger_std_h_SUITE.erl17
8 files changed, 41 insertions, 18 deletions
diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl
index 281521ae6e..51743822af 100644
--- a/lib/kernel/src/logger.erl
+++ b/lib/kernel/src/logger.erl
@@ -677,7 +677,8 @@ init_default_config(Type) when Type==standard_io;
Type==standard_error;
element(1,Type)==file ->
Env = get_logger_env(),
- DefaultConfig = #{logger_std_h=>#{type=>Type}},
+ DefaultFormatter = #{formatter=>{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}},
+ DefaultConfig = DefaultFormatter#{logger_std_h=>#{type=>Type}},
NewLoggerEnv =
case lists:keyfind(default, 2, Env) of
{handler, default, Module, Config} ->
@@ -687,6 +688,13 @@ init_default_config(Type) when Type==standard_io;
%% if not configured by user AND the default
%% handler is still the logger_std_h.
{handler, default, Module, maps:merge(DefaultConfig,Config)};
+ ({handler, default, logger_disk_log_h, _}) ->
+ %% Add default formatter. The point of this
+ %% is to get the expected formatter config
+ %% for the default handler, since this
+ %% differs from the default values that
+ %% logger_formatter itself adds.
+ {handler, default, logger_disk_log_h, maps:merge(DefaultFormatter,Config)};
(Other) ->
Other
end, Env);
diff --git a/lib/kernel/src/logger_h_common.erl b/lib/kernel/src/logger_h_common.erl
index 901c4c0dad..70531c0e34 100644
--- a/lib/kernel/src/logger_h_common.erl
+++ b/lib/kernel/src/logger_h_common.erl
@@ -72,7 +72,7 @@ try_format(Log,Formatter,FormatterConfig) ->
{log,Log},
{reason,
{C,R,logger:filter_stacktrace(?MODULE,S)}}]),
- case {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG} of
+ case {?DEFAULT_FORMATTER,#{}} of
{Formatter,FormatterConfig} ->
"DEFAULT FORMATTER CRASHED";
{DefaultFormatter,DefaultConfig} ->
diff --git a/lib/kernel/src/logger_internal.hrl b/lib/kernel/src/logger_internal.hrl
index f9377259f3..97ef4abfa4 100644
--- a/lib/kernel/src/logger_internal.hrl
+++ b/lib/kernel/src/logger_internal.hrl
@@ -31,8 +31,7 @@
{no_domain,{fun logger_filters:domain/2,{log,no_domain,[]}}}]).
-define(DEFAULT_FORMATTER,logger_formatter).
-define(DEFAULT_FORMAT_CONFIG,#{legacy_header=>true,
- single_line=>false,
- template=>?DEFAULT_FORMAT_TEMPLATE_HEADER}).
+ single_line=>false}).
-define(DEFAULT_FORMAT_TEMPLATE_HEADER,
[{logger_formatter,header},"\n",msg,"\n"]).
-define(DEFAULT_FORMAT_TEMPLATE_SINGLE,
diff --git a/lib/kernel/src/logger_server.erl b/lib/kernel/src/logger_server.erl
index 275b9c476f..67befef156 100644
--- a/lib/kernel/src/logger_server.erl
+++ b/lib/kernel/src/logger_server.erl
@@ -328,7 +328,7 @@ default_config(_) ->
#{level=>info,
filters=>[],
filter_default=>log,
- formatter=>{?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}.
+ formatter=>{?DEFAULT_FORMATTER,#{}}}.
sanity_check(Owner,Key,Value) ->
sanity_check_1(Owner,[{Key,Value}]).
diff --git a/lib/kernel/test/logger_disk_log_h_SUITE.erl b/lib/kernel/test/logger_disk_log_h_SUITE.erl
index 3aa1c3557b..7a1736c814 100644
--- a/lib/kernel/test/logger_disk_log_h_SUITE.erl
+++ b/lib/kernel/test/logger_disk_log_h_SUITE.erl
@@ -336,24 +336,24 @@ formatter_fail(Config) ->
{ok,{_,#{formatter:={logger_formatter,_}}}} =
logger:get_handler_config(Name),
logger:info(M1=?msg,?domain),
- Got1 = try_match_file(?log_no(LogFile,1),"=INFO REPORT====.*\n"++M1,5000),
+ Got1 = try_match_file(?log_no(LogFile,1),"[0-9\\+\\-T:\\.]* info: "++M1,5000),
ok = logger:set_handler_config(Name,formatter,{nonexistingmodule,#{}}),
logger:info(M2=?msg,?domain),
Got2 = try_match_file(?log_no(LogFile,1),
- Got1++"=INFO REPORT====.*\nFORMATTER CRASH: .*"++M2,
+ escape(Got1)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M2,
5000),
ok = logger:set_handler_config(Name,formatter,{?MODULE,crash}),
logger:info(M3=?msg,?domain),
Got3 = try_match_file(?log_no(LogFile,1),
- Got2++"=INFO REPORT====.*\nFORMATTER CRASH: .*"++M3,
+ escape(Got2)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M3,
5000),
ok = logger:set_handler_config(Name,formatter,{?MODULE,bad_return}),
logger:info(?msg,?domain),
try_match_file(?log_no(LogFile,1),
- Got3++"FORMATTER ERROR: bad_return_value",
+ escape(Got3)++"FORMATTER ERROR: bad_return_value",
5000),
%% Check that handler is still alive and was never dead
@@ -1491,3 +1491,10 @@ check_tracer(T) ->
dbg:stop_clear(),
ct:fail({timeout,tracer})
end.
+
+escape([$+|Rest]) ->
+ [$\\,$+|escape(Rest)];
+escape([H|T]) ->
+ [H|escape(T)];
+escape([]) ->
+ [].
diff --git a/lib/kernel/test/logger_env_var_SUITE.erl b/lib/kernel/test/logger_env_var_SUITE.erl
index 764f443634..32612d616e 100644
--- a/lib/kernel/test/logger_env_var_SUITE.erl
+++ b/lib/kernel/test/logger_env_var_SUITE.erl
@@ -542,8 +542,8 @@ logger_many_handlers(Config, Env, LogErr, LogInfo, NumProgress) ->
ok = rpc:call(Node,logger_std_h,filesync,[info]),
{ok, Bin} = file:read_file(LogInfo),
ct:log("Log content:~n~s",[Bin]),
- match(Bin,<<"PROGRESS REPORT">>,NumProgress,info,info),
- match(Bin,<<"ALERT REPORT">>,0,alert,info),
+ match(Bin,<<"info:">>,NumProgress+1,info,info),
+ match(Bin,<<"alert:">>,0,alert,info),
ok.
diff --git a/lib/kernel/test/logger_simple_SUITE.erl b/lib/kernel/test/logger_simple_SUITE.erl
index 0d505b14f5..d7f9fa21cf 100644
--- a/lib/kernel/test/logger_simple_SUITE.erl
+++ b/lib/kernel/test/logger_simple_SUITE.erl
@@ -138,7 +138,8 @@ replace_file(Config) ->
ok = rpc:call(Node, logger, add_handlers,
[[{handler, default, logger_std_h,
- #{ logger_std_h => #{ type => {file, File} }}}]]),
+ #{ logger_std_h => #{ type => {file, File} },
+ formatter => {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}}]]),
{ok,Bin} = sync_and_read(Node, file, File),
Lines = [unicode:characters_to_list(L) ||
@@ -181,7 +182,8 @@ replace_disk_log(Config) ->
ok = rpc:call(Node, logger, add_handlers,
[[{handler, default, logger_disk_log_h,
- #{ disk_log_opts => #{ file => File }}}]]),
+ #{ disk_log_opts => #{ file => File },
+ formatter => {?DEFAULT_FORMATTER,?DEFAULT_FORMAT_CONFIG}}}]]),
{ok,Bin} = sync_and_read(Node, disk_log, File),
Lines = [unicode:characters_to_list(L) ||
L <- binary:split(Bin,<<"\n">>,[global,trim])],
diff --git a/lib/kernel/test/logger_std_h_SUITE.erl b/lib/kernel/test/logger_std_h_SUITE.erl
index fc59d393e0..5764abd063 100644
--- a/lib/kernel/test/logger_std_h_SUITE.erl
+++ b/lib/kernel/test/logger_std_h_SUITE.erl
@@ -250,24 +250,24 @@ formatter_fail(Config) ->
{ok,{_,#{formatter:={logger_formatter,_}}}} =
logger:get_handler_config(?MODULE),
logger:info(M1=?msg,?domain),
- Got1 = try_match_file(Log,"=INFO REPORT====.*\n"++M1,5000),
+ Got1 = try_match_file(Log,"[0-9\\+\\-T:\\.]* info: "++M1,5000),
ok = logger:set_handler_config(?MODULE,formatter,{nonexistingmodule,#{}}),
logger:info(M2=?msg,?domain),
Got2 = try_match_file(Log,
- Got1++"=INFO REPORT====.*\nFORMATTER CRASH: .*"++M2,
+ escape(Got1)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M2,
5000),
ok = logger:set_handler_config(?MODULE,formatter,{?MODULE,crash}),
logger:info(M3=?msg,?domain),
Got3 = try_match_file(Log,
- Got2++"=INFO REPORT====.*\nFORMATTER CRASH: .*"++M3,
+ escape(Got2)++"[0-9\\+\\-T:\\.]* info: FORMATTER CRASH: .*"++M3,
5000),
ok = logger:set_handler_config(?MODULE,formatter,{?MODULE,bad_return}),
logger:info(?msg,?domain),
try_match_file(Log,
- Got3++"FORMATTER ERROR: bad_return_value",
+ escape(Got3)++"FORMATTER ERROR: bad_return_value",
5000),
%% Check that handler is still alive and was never dead
@@ -1020,7 +1020,7 @@ mem_kill_new(Config) ->
killed ->
ct:pal("Slow shutdown, handler process was killed!", [])
end,
- timer:sleep(RestartAfter + 2000),
+ timer:sleep(RestartAfter * 3),
true = is_pid(whereis(?MODULE)),
ok
after
@@ -1518,3 +1518,10 @@ check_tracer(T,TimeoutFun) ->
dbg:stop_clear(),
TimeoutFun()
end.
+
+escape([$+|Rest]) ->
+ [$\\,$+|escape(Rest)];
+escape([H|T]) ->
+ [H|escape(T)];
+escape([]) ->
+ [].