To avoid this kind of situations I usually use a terminal multiplexer such as screen
or tmux
.
Although they are ideal for working on remote machines (because you can disconnect and reconnect at a later time without loosing your session, say, in case someone trips on your powercord :) ), both have logging facilities of the sessions (which is what you want in your case).