Redirection
Redirecting stdout and stderr to log file
Use exec to redirect both streams to a file like in the following example:
#!/bin/bash
LOG_FILE=/tmp/redirection_test.log
exec 1> $LOG_FILE 2>&1
echo "Stdout is redirected"
echo "Stderr, too: "
ls /path/does/not/exist
If you do not want the logfile to be overriden, i.e. if you want to write entries in append mode, change the exec command line like below
exec 1>> $LOG_FILE 2>&1