Save that thought…
At work, our build process can produce thousands of lines of code, and sometimes the important bits can slide off of the terminal’s scrollback buffer.
So I created an alias that logs all output of the shell. It’s nothing fancy… it’s just a call to
script with an argument to put the time and date in the filename. But it goes a step further, actually exec-ing the script command, so you do not have to exit twice when you’re done (once to exit the script, and once to exit the original shell).
alias log='exec script "/home/alan/logs/terminal-$(date +%Y%m%d-%H%M%S)-$$.log"'
Still, this requires you to think about logging before you start your work.
Since I normally launch my shell windows from a Gnome application launcher icon, I decided to modify that launcher so that EVERYTHING is logged.
On Gnome, right-click on the panel at the top and select “+ Add to panel…”. Then select “application launcher” and pick out the gnome-terminal from the menus. You’ll have a little terminal icon on the top Gnome panel.
Right-click on that terminal icon and select “properties”. It should say “gnome-terminal”. Change it to the following:
sh -c "exec gnome-terminal -x script $HOME/logs/terminal-$(date +%%Y%%m%%d-%%H%%M%%S)-$$.log"
The double-percents are so the launcher will not interpret them.
Now, when you click on that application launcher icon, a new terminal window will open, and all output to that terminal will be logged.