4
%% Copyright Ericsson AB 2011. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
19
-module(cth_log_redirect).
21
%%% @doc Common Test Framework functions handling test specifications.
23
%%% <p>This module redirects sasl and error logger info to common test log.</p>
28
-export([id/1, init/2, post_init_per_group/4, pre_end_per_group/3,
29
post_end_per_testcase/4]).
31
%% Event handler Callbacks
33
handle_event/2, handle_call/2, handle_info/2,
39
init(?MODULE, _Opts) ->
40
error_logger:add_report_handler(?MODULE),
43
post_init_per_group(Group, Config, Result, tc_log) ->
44
case lists:member(parallel,proplists:get_value(
45
tc_group_properties,Config,[])) of
47
{Result, {set_log_func(ct_log),Group}};
51
post_init_per_group(_Group, _Config, Result, State) ->
54
post_end_per_testcase(_TC, _Config, Result, State) ->
55
%% Make sure that the event queue is flushed
56
%% before ending this test case.
57
gen_event:call(error_logger, ?MODULE, flush),
60
pre_end_per_group(Group, Config, {ct_log, Group}) ->
61
{Config, set_log_func(tc_log)};
62
pre_end_per_group(_Group, Config, State) ->
66
%% Copied and modified from sasl_report_tty_h.erl
70
handle_event({_Type, GL, _Msg}, State) when node(GL) /= node() ->
72
handle_event(Event, LogFunc) ->
73
case lists:keyfind(sasl, 1, application:which_applications()) of
77
{ok, ErrLogType} = application:get_env(sasl, errlog_type),
78
SReport = sasl_report:format_report(group_leader(), ErrLogType,
80
if is_list(SReport) ->
81
ct_logs:LogFunc(sasl, SReport, []);
82
true -> %% Report is an atom if no logging is to be done
86
EReport = error_logger_tty_h:write_event(
87
tag_event(Event),io_lib),
88
if is_list(EReport) ->
89
ct_logs:LogFunc(error_logger, EReport, []);
90
true -> %% Report is an atom if no logging is to be done
96
handle_info(_,State) -> {ok, State}.
98
handle_call(flush,State) ->
100
handle_call({set_logfunc,NewLogFunc},_) ->
101
{ok, NewLogFunc, NewLogFunc};
102
handle_call(_Query, _State) -> {error, bad_query}.
104
terminate(_Reason, _Type) ->
108
{calendar:local_time(), Event}.
110
set_log_func(Func) ->
111
gen_event:call(error_logger, ?MODULE, {set_logfunc, Func}).