Perhaps you are looking for something like:
if [ "$LOG" == "" ]; then
date >> log & exec bash -x $0 $* 2>>log
# log should be going
This will create a log file looking like:
Sat Jul 5 04:45:23 EDT 2014
+ '[' 1 == '' ']'
+ echo testing1
+ echo testing2
You can change the detail of the log by changing the "-x" on the bash command line to "-vx".
Warning: because the bash command redirects stderr, any error messages will be redirected to the log.
The first line (following the date) will always show - it is the test to whether to create a log output or not, and is caused by the recursive use of bash.
The purpose of the "exec bash..." is to reduce the depth of active processes. Using exec is not required, the only thing saved by its use is the parent shell (that starts the subprocess) doesn't have to actually interpret/execute the "exit $?" command. The parent shell only sets up the log (with the date) and then restarts the shell with the log file getting the commands (from the "-x") and all the error messages.
One last thing you might like to have... The "LOG" environment variable must not be defined by default. Its value can be set to anything by the script. If the value is set to the log file name, then it is possible for the script to use that to put its own messages in the log (things like "echo 'this shouldn't happen' >>$LOG").
The log will have the date as the first line, then all command recording will have a "+" (or ++ if you use the "-vx" options). So any special messages will be in there twice, once with the "+" followed by the command, then a line with the special message. This could make it easy to quickly identify special messages.
One final warning - the destination of the log will need a LOT of maintenance. ESPECIALLY if a script logs like this and is put into a loop by a different script (that doesn't set the LOG variable)... You could get thousands of log files rather quickly.