aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sasl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sasl')
-rw-r--r--lib/sasl/doc/src/sasl_app.xml12
-rw-r--r--lib/sasl/src/sasl_report.erl48
-rw-r--r--lib/sasl/test/Makefile4
-rw-r--r--lib/sasl/test/sasl_SUITE.erl97
-rw-r--r--lib/sasl/test/sasl_report_SUITE.erl141
-rw-r--r--lib/sasl/test/sasl_report_suite_supervisor.erl77
6 files changed, 359 insertions, 20 deletions
diff --git a/lib/sasl/doc/src/sasl_app.xml b/lib/sasl/doc/src/sasl_app.xml
index 7cdb3e2ca7..fe38e69ce3 100644
--- a/lib/sasl/doc/src/sasl_app.xml
+++ b/lib/sasl/doc/src/sasl_app.xml
@@ -57,11 +57,19 @@
<taglist>
<tag><c>sasl_report_tty_h</c></tag>
<item>
- <p>Formats and writes <em>supervisor reports</em>, <em>crash reports</em> and <em>progress reports</em> to <c>stdio</c>.</p>
+ <p>Formats and writes <em>supervisor reports</em>, <em>crash reports</em> and <em>progress reports</em> to <c>stdio</c>.
+ This error logger event handler will use
+ <seealso marker="kernel:kernel_app#error_logger_format_depth">error_logger_format_depth</seealso>
+ in the Kernel application to limit how much detail are printed to
+ for crash and supervisor reports.</p>
</item>
<tag><c>sasl_report_file_h</c></tag>
<item>
- <p>Formats and writes <em>supervisor reports</em>, <em>crash report</em> and <em>progress report</em> to a single file.</p>
+ <p>Formats and writes <em>supervisor reports</em>, <em>crash report</em> and <em>progress report</em> to a single file.
+ This error logger event handler will use
+ <seealso marker="kernel:kernel_app#error_logger_format_depth">error_logger_format_depth</seealso>
+ in the Kernel application to limit how much detail are printed to
+ for crash and supervisor reports.</p>
</item>
<tag><c>log_mf_h</c></tag>
<item>
diff --git a/lib/sasl/src/sasl_report.erl b/lib/sasl/src/sasl_report.erl
index 1b1d432352..0b8c4212d2 100644
--- a/lib/sasl/src/sasl_report.erl
+++ b/lib/sasl/src/sasl_report.erl
@@ -62,27 +62,53 @@ write_report2(IO, Fd, Head, supervisor_report, Report) ->
Context = sup_get(errorContext, Report),
Reason = sup_get(reason, Report),
Offender = sup_get(offender, Report),
- FmtString = " Supervisor: ~p~n Context: ~p~n Reason: "
- "~80.18p~n Offender: ~80.18p~n~n",
- write_report_action(IO, Fd, Head ++ FmtString,
- [Name,Context,Reason,Offender]);
+ {FmtString,Args} = supervisor_format([Name,Context,Reason,Offender]),
+ write_report_action(IO, Fd, Head, FmtString, Args);
write_report2(IO, Fd, Head, progress, Report) ->
Format = format_key_val(Report),
- write_report_action(IO, Fd, Head ++ "~s", [Format]);
+ write_report_action(IO, Fd, Head, "~s", [Format]);
write_report2(IO, Fd, Head, crash_report, Report) ->
- Format = proc_lib:format(Report),
- write_report_action(IO, Fd, Head ++ "~s", [Format]).
+ Depth = get_depth(),
+ Format = proc_lib:format(Report, latin1, Depth),
+ write_report_action(IO, Fd, Head, "~s", [Format]).
+
+supervisor_format(Args0) ->
+ case get_depth() of
+ unlimited ->
+ {" Supervisor: ~p~n"
+ " Context: ~p~n"
+ " Reason: ~80.18p~n"
+ " Offender: ~80.18p~n~n",
+ Args0};
+ Depth ->
+ [A,B,C,D] = Args0,
+ Args = [A,Depth,B,Depth,C,Depth,D,Depth],
+ {" Supervisor: ~P~n"
+ " Context: ~P~n"
+ " Reason: ~80.18P~n"
+ " Offender: ~80.18P~n~n",
+ Args}
+ end.
-write_report_action(io, Fd, Format, Args) ->
- io:format(Fd, Format, Args);
-write_report_action(io_lib, _Fd, Format, Args) ->
- io_lib:format(Format, Args).
+write_report_action(IO, Fd, Head, Format, Args) ->
+ S = [Head|io_lib:format(Format, Args)],
+ case IO of
+ io -> io:put_chars(Fd, S);
+ io_lib -> S
+ end.
format_key_val([{Tag,Data}|Rep]) ->
io_lib:format(" ~16w: ~p~n",[Tag,Data]) ++ format_key_val(Rep);
format_key_val(_) ->
[].
+get_depth() ->
+ case application:get_env(kernel, error_logger_format_depth) of
+ {ok, Depth} when is_integer(Depth) ->
+ max(10, Depth);
+ undefined ->
+ unlimited
+ end.
sup_get(Tag, Report) ->
case lists:keysearch(Tag, 1, Report) of
diff --git a/lib/sasl/test/Makefile b/lib/sasl/test/Makefile
index 86fc57abfc..86976def6a 100644
--- a/lib/sasl/test/Makefile
+++ b/lib/sasl/test/Makefile
@@ -29,11 +29,13 @@ MODULES= \
alarm_handler_SUITE \
installer \
release_handler_SUITE \
+ sasl_report_SUITE \
+ sasl_report_suite_supervisor \
systools_SUITE \
systools_rc_SUITE \
overload_SUITE \
rb_SUITE \
- rh_test_lib
+ rh_test_lib \
ERL_FILES= $(MODULES:%=%.erl)
diff --git a/lib/sasl/test/sasl_SUITE.erl b/lib/sasl/test/sasl_SUITE.erl
index 1d76cdee6e..cd8316b451 100644
--- a/lib/sasl/test/sasl_SUITE.erl
+++ b/lib/sasl/test/sasl_SUITE.erl
@@ -28,10 +28,11 @@
-export([app_test/1,
appup_test/1,
log_mf_h_env/1,
- log_file/1]).
+ log_file/1,
+ utc_log/1]).
all() ->
- [log_mf_h_env, log_file, app_test, appup_test].
+ [log_mf_h_env, log_file, app_test, appup_test, utc_log].
groups() ->
[].
@@ -182,20 +183,104 @@ log_mf_h_env(Config) ->
log_file(Config) ->
PrivDir = ?config(priv_dir,Config),
LogDir = filename:join(PrivDir,sasl_SUITE_log_dir),
- ok = filelib:ensure_dir(LogDir),
File = filename:join(LogDir, "file.log"),
+ ok = filelib:ensure_dir(File),
application:stop(sasl),
clear_env(sasl),
- ok = application:set_env(sasl,sasl_error_logger,{file, File}, [{persistent, true}]),
+ _ = test_log_file(File, {file,File}),
+ _ = test_log_file(File, {file,File,[write]}),
+
+ ok = file:write_file(File, <<"=PROGRESS preserve me\n">>),
+ <<"=PROGRESS preserve me\n",_/binary>> =
+ test_log_file(File, {file,File,[append]}),
+
+ ok = application:set_env(sasl,sasl_error_logger, tty,
+ [{persistent, false}]),
+ ok = application:start(sasl).
+
+test_log_file(File, Arg) ->
+ ok = application:set_env(sasl, sasl_error_logger, Arg,
+ [{persistent, true}]),
+ ok = application:start(sasl),
+ application:stop(sasl),
+ {ok,Bin} = file:read_file(File),
+ ok = file:delete(File),
+ Lines0 = binary:split(Bin, <<"\n">>, [trim_all,global]),
+ Lines = [L || L <- Lines0,
+ binary:match(L, <<"=PROGRESS">>) =:= {0,9}],
+ io:format("~p:\n~p\n", [Arg,Lines]),
+
+ %% There must be at least four PROGRESS lines.
+ if
+ length(Lines) >= 4 -> ok;
+ true -> ?t:fail()
+ end,
+ Bin.
+
+%% Make a basic test of utc_log.
+utc_log(Config) ->
+ PrivDir = ?config(priv_dir, Config),
+ LogDir = filename:join(PrivDir, sasl_SUITE_log_dir),
+ Log = filename:join(LogDir, "utc.log"),
+ ok = filelib:ensure_dir(Log),
+
+ application:stop(sasl),
+ clear_env(sasl),
+
+ %% Test that the UTC marker gets added to PROGRESS lines
+ %% when the utc_log configuration variable is set to true.
+ ok = application:set_env(sasl, sasl_error_logger, {file,Log},
+ [{persistent,true}]),
+ ok = application:set_env(sasl, utc_log, true, [{persistent,true}]),
ok = application:start(sasl),
application:stop(sasl),
- ok = application:set_env(sasl,sasl_error_logger,{file, File, [append]}, [{persistent, true}]),
+
+ verify_utc_log(Log, true),
+
+ %% Test that no UTC markers gets added to PROGRESS lines
+ %% when the utc_log configuration variable is set to false.
+ ok = application:set_env(sasl, utc_log, false, [{persistent,true}]),
+ ok = application:start(sasl),
+ application:stop(sasl),
+
+ verify_utc_log(Log, false),
+
+ %% Test that no UTC markers gets added to PROGRESS lines
+ %% when the utc_log configuration variable is unset.
+ ok = application:unset_env(sasl, utc_log, [{persistent,true}]),
ok = application:start(sasl),
application:stop(sasl),
- ok = application:set_env(sasl,sasl_error_logger, tty, [{persistent, false}]),
+
+ verify_utc_log(Log, false),
+
+ %% Change back to the standard TTY error logger.
+ ok = application:set_env(sasl,sasl_error_logger, tty,
+ [{persistent, false}]),
ok = application:start(sasl).
+verify_utc_log(Log, UTC) ->
+ {ok,Bin} = file:read_file(Log),
+ ok = file:delete(Log),
+
+ Lines0 = binary:split(Bin, <<"\n">>, [trim_all,global]),
+ Lines = [L || L <- Lines0,
+ binary:match(L, <<"=PROGRESS">>) =:= {0,9}],
+ Setting = application:get_env(sasl, utc_log),
+ io:format("utc_log ~p:\n~p\n", [Setting,Lines]),
+ Filtered = [L || L <- Lines,
+ binary:match(L, <<" UTC ===">>) =:= nomatch],
+ %% Filtered now contains all lines WITHOUT any UTC markers.
+ case UTC of
+ false ->
+ %% No UTC marker on the PROGRESS line.
+ Filtered = Lines;
+ true ->
+ %% Each PROGRESS line must have an UTC marker.
+ [] = Filtered
+ end,
+ ok.
+
%%-----------------------------------------------------------------
%% Internal
diff --git a/lib/sasl/test/sasl_report_SUITE.erl b/lib/sasl/test/sasl_report_SUITE.erl
new file mode 100644
index 0000000000..940234f152
--- /dev/null
+++ b/lib/sasl/test/sasl_report_SUITE.erl
@@ -0,0 +1,141 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2015. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(sasl_report_SUITE).
+-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
+ init_per_group/2,end_per_group/2]).
+-export([gen_server_crash/1]).
+
+-export([crash_me/0,start_link/0,init/1,handle_cast/2,terminate/2]).
+
+-include_lib("test_server/include/test_server.hrl").
+
+suite() -> [{ct_hooks,[ts_install_cth]}].
+
+all() ->
+ [gen_server_crash].
+
+groups() ->
+ [].
+
+init_per_suite(Config) ->
+ Config.
+
+end_per_suite(_Config) ->
+ ok.
+
+init_per_group(_GroupName, Config) ->
+ Config.
+
+end_per_group(_GroupName, Config) ->
+ Config.
+
+gen_server_crash(Config) ->
+ try
+ do_gen_server_crash(Config)
+ after
+ error_logger:tty(true),
+ ok = application:unset_env(sasl, sasl_error_logger),
+ ok = application:unset_env(kernel, error_logger_format_depth),
+ error_logger:add_report_handler(cth_log_redirect)
+ end,
+ ok.
+
+do_gen_server_crash(Config) ->
+ PrivDir = ?config(priv_dir, Config),
+ LogDir = filename:join(PrivDir, ?MODULE),
+ KernelLog = filename:join(LogDir, "kernel.log"),
+ SaslLog = filename:join(LogDir, "sasl.log"),
+ ok = filelib:ensure_dir(SaslLog),
+
+ error_logger:delete_report_handler(cth_log_redirect),
+ error_logger:tty(false),
+ application:stop(sasl),
+ ok = application:set_env(sasl, sasl_error_logger, {file,SaslLog},
+ [{persistent,true}]),
+ application:set_env(kernel, error_logger_format_depth, 30),
+ error_logger:logfile({open,KernelLog}),
+ application:start(sasl),
+ io:format("~p\n", [gen_event:which_handlers(error_logger)]),
+
+ crash_me(),
+
+ error_logger:logfile(close),
+
+ check_file(KernelLog, 70000, 150000),
+ check_file(SaslLog, 50000, 100000),
+
+ ok.
+
+check_file(File, Min, Max) ->
+ {ok,Bin} = file:read_file(File),
+ Base = filename:basename(File),
+ io:format("*** Contents of ~s ***\n", [Base]),
+ io:put_chars([Bin,"\n"]),
+ Sz = byte_size(Bin),
+ io:format("Size: ~p (allowed range is ~p..~p)\n",
+ [Sz,Min,Max]),
+ if
+ Sz < Min ->
+ %% Truncated? Other problem?
+ ?t:fail({too_short,Base});
+ Sz > Max ->
+ %% Truncation doesn't work?
+ ?t:fail({too_big,Base});
+ true ->
+ ok
+ end.
+
+%%%
+%%% gen_server that crashes.
+%%%
+
+crash_me() ->
+ {ok,SuperPid} = supervisor:start_link(sasl_report_suite_supervisor, []),
+ [{Id,Pid,_,_}] = supervisor:which_children(SuperPid),
+ HugeData = gb_sets:from_list(lists:seq(1, 100000)),
+ gen_server:cast(Pid, HugeData),
+ Ref = monitor(process, Pid),
+ receive
+ {'DOWN',Ref,process,Pid,_} ->
+ supervisor:terminate_child(SuperPid, Id),
+ unlink(SuperPid),
+ exit(SuperPid, kill),
+ ok
+ end.
+
+start_link() ->
+ gen_server:start_link(?MODULE, [], []).
+
+init(_) ->
+ St = <<0:100000/unit:8>>,
+ {ok,St}.
+
+handle_cast(Big, St) ->
+ Seq = lists:seq(1, 10000),
+ self() ! Seq,
+ self() ! Seq,
+ self() ! Seq,
+ self() ! Seq,
+ self() ! Seq,
+ x = Big,
+ {noreply,St}.
+
+terminate(_, _) ->
+ ok.
diff --git a/lib/sasl/test/sasl_report_suite_supervisor.erl b/lib/sasl/test/sasl_report_suite_supervisor.erl
new file mode 100644
index 0000000000..bc92a40af2
--- /dev/null
+++ b/lib/sasl/test/sasl_report_suite_supervisor.erl
@@ -0,0 +1,77 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2015. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
+-module(sasl_report_suite_supervisor).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+-define(SERVER, ?MODULE).
+
+%%%===================================================================
+%%% API functions
+%%%===================================================================
+
+%%--------------------------------------------------------------------
+%% @doc
+%% Starts the supervisor
+%%
+%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
+%% @end
+%%--------------------------------------------------------------------
+start_link() ->
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
+
+%%%===================================================================
+%%% Supervisor callbacks
+%%%===================================================================
+
+%%--------------------------------------------------------------------
+%% @private
+%% @doc
+%% Whenever a supervisor is started using supervisor:start_link/[2,3],
+%% this function is called by the new process to find out about
+%% restart strategy, maximum restart intensity, and child
+%% specifications.
+%%
+%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
+%% ignore |
+%% {error, Reason}
+%% @end
+%%--------------------------------------------------------------------
+init([]) ->
+
+ SupFlags = #{strategy => one_for_one,
+ intensity => 1,
+ period => 5},
+
+ AChild = #{id => 'sasl_report_suit_supervisor',
+ start => {sasl_report_SUITE, start_link, []},
+ restart => permanent,
+ shutdown => 5000,
+ type => worker,
+ modules => [sasl_report_SUITE]},
+
+ {ok, {SupFlags, [AChild]}}.