You could use GNU screen, along with its logging functionality. Note also that the
logfile flush secs command allows you to control how often the output is flushed to disk. From the Screen User's Manual:
— Command: logfile flush secs
Defines the name the log files will get. The default is ‘screenlog.%n’. The second form changes the number of seconds screen will wait before flushing the logfile buffer to the file-system. The default value is 10 seconds.