How do I log all input and output in a terminal session?

Solution 1:

When you are ready to start recording a log file, type:

script screen.log

Now, until you stop the script, all input and output in the Terminal will be stored in screen.log. When you are done, just type:

exit

Your screen.log file will stored in the local directory. If you want to redirect it, use an absolute pathname such as ~/screen.log. This will do exactly what you are looking for.

Source: Ubuntu Guide - How To Log Terminal Commands

Solution 2:

You may want to try out Asciinema. In addition to just making a recording you get the ability to share it and embed the player on your blog, article or in a conference talk.