Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common_test: header option for cth_conn_log hook module #8924

Open
wants to merge 1 commit into
base: maint
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/common_test/src/ct_conn_log_h.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
-export([init/1,
handle_event/2, handle_call/2, handle_info/2,
terminate/2]).

-record(state, {logs=[], default_gl}).
-record(state, {logs=[], default_gl, header=false}).

-define(WIDTH,80).

-define(now, os:timestamp()).

%%%-----------------------------------------------------------------
%%% Callbacks
init({GL,ConnLogs}) ->
open_files(GL,ConnLogs,#state{default_gl=GL}).
init({GL,ConnLogs,Opts}) ->
open_files(GL,ConnLogs,
#state{default_gl = GL,
header = proplists:get_value(header, Opts, false)}).

open_files(GL,[{ConnMod,{LogType,LogFiles}}|T],State=#state{logs=Logs}) ->
case do_open_files(LogFiles,[]) of
Expand Down Expand Up @@ -103,6 +104,9 @@ terminate(_,#state{logs=Logs}) ->

%%%-----------------------------------------------------------------
%%% Writing reports
write_report(Time,#conn_log{header=false,module=ConnMod}=Info,Data,GL,
#state{header=true}=State) ->
write_report_with_header(Info, GL, State, ConnMod, Data, Time);
write_report(_Time,#conn_log{header=false,module=ConnMod}=Info,Data,GL,State) ->
case get_log(Info,GL,State) of
{silent,_,_} ->
Expand All @@ -113,8 +117,10 @@ write_report(_Time,#conn_log{header=false,module=ConnMod}=Info,Data,GL,State) ->
end,
io:format(Fd,Str,[format_data(ConnMod,LogType,Data)])
end;

write_report(Time,#conn_log{module=ConnMod}=Info,Data,GL,State) ->
write_report_with_header(Info, GL, State, ConnMod, Data, Time).

write_report_with_header(Info, GL, State, ConnMod, Data, Time) ->
case get_log(Info,GL,State) of
{silent,_,_} ->
ok;
Expand Down
9 changes: 5 additions & 4 deletions lib/common_test/src/cth_conn_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ get_log_opts(Mod,Opts) ->
end,
LogType = proplists:get_value(log_type,Opts,DefaultLogType),
Hosts = proplists:get_value(hosts,Opts,[]),
{LogType,Hosts}.
{LogType,Hosts,[{header, proplists:get_value(header,Opts,false)}]}.

pre_init_per_testcase(_Suite,TestCase,Config,CthState) ->
{_, _, CtTelnetOpts} = proplists:get_value(ct_telnet, CthState, {null, null, []}),
Logs =
lists:map(
fun({ConnMod,{LogType,Hosts}}) ->
fun({ConnMod,{LogType,Hosts, _Opts}}) ->
ct_util:set_testdata({{?MODULE,ConnMod},LogType}),
case LogType of
LogType when LogType==raw; LogType==pretty ->
Expand Down Expand Up @@ -128,11 +129,11 @@ pre_init_per_testcase(_Suite,TestCase,Config,CthState) ->
end
end,
CthState),

GL = group_leader(),
Update =
fun(Init) when Init == undefined; Init == [] ->
error_logger:add_report_handler(ct_conn_log_h,{GL,Logs}),
error_logger:add_report_handler(ct_conn_log_h,
{GL,Logs,CtTelnetOpts}),
[TestCase];
(PrevUsers) ->
error_logger:info_report(update,{GL,Logs}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
%%--------------------------------------------------------------------

suite() ->
[
{require,telnet_server_conn1,{unix,[telnet]}},
[{require,telnet_server_conn1,{unix,[telnet]}},
{require,ct_conn_log},
{ct_hooks, [{cth_conn_log,[]}]}
{ct_hooks, [{cth_conn_log,[{ct_telnet, [{header, true}]}]}]}
].

all() ->
Expand Down
Loading