Store Bash Script outputs to a file

I have a lot of echo and command execution inside my bash file and I wanted to store those outputs to a file. Initially I am using ./myscript.sh | tee -a log.txt to log but I am exploring the possibly to achieve this inside the bash file. Some articles suggests doing this echo "Successfully executed" >> /path-to-logfile but I have a lot of lines and this would be cumbersome. How could I achieve this with fewer commands/lines?

And at the start of the script, it also checks if the log folder exists

This is the correct method. Inside script it will be complicated. Remember always keep it simple.

I see. Because I want the script to create its own log directory first with filename format based on the variables available inside. Found a page where he used { //all script } | tee -a file


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki