You might want to use something like this:
-module(test).
-compile(export_all).
foo(_LongBinary, _OtherParam) ->
ok.
test() ->
dbg:tracer(process, {
fun({trace, Pid, call, {M,F,A}}, _) ->
NewA = lists:map(fun(<<Reduced:5/binary, _/binary>>) ->
Reduced;
(Else) ->
Else
end, A),
erlang:display({Pid, "->", M, F, NewA});
({trace, Pid, return_from, {M,F,A}, R}, _) ->
erlang:display({Pid, "<-", M, F, A, R})
end, unused}),
dbg:p(all,c),
dbg:tpl(test, foo, x).
Mainly, I'm using an alternative version of dbg:tracer
, which takes two arguments. The first is the type and could be process or port (see doc for more details). The second parameter is a message handler function (actually a tuple containing the handler function and the initial handler data), which will be called for each trace message.
There, you can implement your logic to truncate binaries longer than a certain amount or whatever else you need to do.
So, you will get something like:
1> test:test().
{ok,[{matched,nonode@nohost,1},{saved,x}]}
2> test:foo(<<"aa">>,b).
ok
3> {<0.45.0>,"->",test,foo,[<<2 bytes>>,b]}
{<0.45.0>,"<-",test,foo,2,ok}
4> test:foo(<<"aaaaaaa">>,b).
ok
5> {<0.45.0>,"->",test,foo,[<<5 bytes>>,b]}
{<0.45.0>,"<-",test,foo,2,ok}
6> test:foo(<<"aaaaaaasdaaaaaaaaa">>,b).
ok
7> {<0.45.0>,"->",test,foo,[<<5 bytes>>,b]}
{<0.45.0>,"<-",test,foo,2,ok}
You might want to truncate return values as well. You could also look at the dbg module to emulate their pretty printing (unfortunately, formatting functions are not exported there).