you can try to use protocol/1, then start your query prefixed by leash(-all),trace
edit a solution (?) to change file on backtracking: I would save in a module (maybe named trace_protocol :-) and then would use with ?- [trace_protocol].
and subsequently ?- trace,trace_protocol(append(X,Y,[1,2,3])).
:- meta_predicate trace_protocol(0).
trace_protocol :-
Name = trace_protocol_index,
catch(nb_getval(Name, N), _Exc, nb_setval(Name, 0)),
% writeln(ex:Exc),
nb_current(Name, N),
% writeln(nb_current(Name, N)),
M is N+1, nb_setval(Name, M),
% writeln(nb_setval(Name, M)),
format(atom(PN), '~s_~d.tty', [Name, N]),
% writeln(trace_protocol:PN),
protocol(PN).
trace_protocol(Q) :- trace_protocol, forall(Q, trace_protocol).
It took a lot to code, since seems there is a bug in nb_current/2. Should not, but it throws an exception - actually the exception is thrown from library(clpfd), even if that is not directly included in my test module.
The sequentially numbered *.tty files are best shown in terminal, for instance
$ cat *.tty
since there are TTY formatting escape sequences. Maybe such sequences could be turned down with ?- set_prolog_flag(color_term, false).