Debug mode

When I run a lengthy script in debug mode i need to capture all the steps which are executed.

e.g
ksh -x script.ksh
+ test -f /proc/mounts
+ /bin/ls -l /proc/21326/exe
+ is=ksh
+ test ksh = ksh
+ test -s /etc/ksh.kshrc
+ . /etc/ksh.kshrc
+ trap 1 2 3
+ who am i
+ awk {print $1}
+ sed s/.*!//

....
....
....

I tried using ksh -x script.ksh > steps but not able to capture all steps.

ksh -x script.ksh > steps 2>&1

That's because tracing output is written to stderr, not stdout. Try

ksh -x script.sh 2> trace.log