[erlang-questions] How to capture all output to console during Common Test?

556 views
Skip to first unread message

Max Lapshin

unread,
Jun 9, 2017, 12:06:53 PM6/9/17
to Erlang-Questions Questions
Hi.

I'm running ct_run  and want somehow to capture all output made to console (io:format,  ct:print).  Is it possible?

Fred Hebert

unread,
Jun 9, 2017, 9:09:45 PM6/9/17
to Max Lapshin, Erlang-Questions Questions
I ended up doing this for rebar3 through the cth_readable library. The
only practical way I found to hijack all traffic was to use a parse
transform to replace the function and tunnel it through my own.

Here's the parse transform I used for ct:pal/2-3 :
https://github.com/ferd/cth_readable/blob/master/src/cth_readable_transform.erl

https://github.com/ferd/cth_readable/blob/master/src/cth_readable_failonly.erl
shows how I got to capture and redirect most of lager and error_logger's
traffic as well, but it's fairly messy.

Regards,
Fred.
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Vladimir Gordeev

unread,
Jun 10, 2017, 3:15:55 AM6/10/17
to erlang-q...@erlang.org
Well, it's possible to start your own Erlang IO server, start it in ct hook during init, and then make it as a group leader for root ct process.

http://erlang.org/doc/apps/stdlib/io_protocol.html

So just start your own process that handles io_reply, io_request, and then

erlang:group_leader(MyCustomIOServerPid, CtRootPid),

Marco Molteni

unread,
Jun 11, 2017, 2:32:59 AM6/11/17
to Max Lapshin, Erlang-Questions Questions
On 9 Jun 2017, at 18:06, Max Lapshin <max.l...@gmail.com> wrote:

> I'm running ct_run and want somehow to capture all output made to console (io:format, ct:print). Is it possible?

I wrote mock_io [1] to capture/inject I/O for EUnit. If it doesn't work out of the box with CT, it should be easy to adapt, I'll be happy to accept patches :-)

marco

[1] https://github.com/marco-m/mock_io

PAILLEAU Eric

unread,
Jun 11, 2017, 5:53:17 AM6/11/17
to erlang-q...@erlang.org

>
Hi max,

you may have a look to io_server/0 and io_server/1 in
https://github.com/erlang/otp/blob/master/lib/observer/src/observer_procinfo.erl

was done to catch 'rb' output in observer.

cheers

Max Lapshin

unread,
Jun 13, 2017, 3:56:34 PM6/13/17
to Vladimir Gordeev, Erlang-Questions Questions
On Sat, Jun 10, 2017 at 10:14 AM, Vladimir Gordeev <gordeev.v...@gmail.com> wrote:
Well, it's possible to start your own Erlang IO server, start it in ct hook during init, and then make it as a group leader for root ct process.

http://erlang.org/doc/apps/stdlib/io_protocol.html

So just start your own process that handles io_reply, io_request, and then

erlang:group_leader(MyCustomIOServerPid, CtRootPid),


Have you tried to do it?

Vladimir Gordeev

unread,
Jun 14, 2017, 7:27:46 AM6/14/17
to Max Lapshin, erlang-q...@erlang.org
Have you tried to do it?

Yeah, I captured by such manner all IO from custom erlang shell that I started by shell:start/2.
I didn't tried to do it with Common Test though.

Here is module of my own IO server process, just for example: https://gist.github.com/vladimir-vg/ab5a2096759e24e8f6d51386f043430e
Reply all
Reply to author
Forward
0 new messages