Add the code below to .sh file.
# Optional:
# exec 1<&- # Close STDOUT file descriptor
# exec 2<&- # Close STDERR FD
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
LOG_FILE=$parent_path'/error.log' #log file name
exec 1>> $LOG_FILE # Open STDOUT as $LOG_FILE file for read and write.
exec 2>&1 # Redirect STDERR to STDOUT
echo | date "+%Y-%m-%d %H:%M:%S"
# example:
echo "Time Stamp should be above this line"
cat nofile.example