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

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


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.


I have a better way to use syslog for logging every shell command this can be vary upon linux distribution but method will remain same

You need to follow some steps:

Step # 1 (Create Syslog service)

# vim /etc/rsyslog.d/bash.conf

local6.*    /var/log/commands.log

Step # 2 (Open bashrc and enter below command)

# vim /root/.bashrc

# Enable CLI Logging by Mansur 08-12-2016 
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'

Ste # 3 (Restart Syslog Service)

# /etc/init.d/rsyslog

Here is a log sample:

Dec  7 22:13:00 validationdb2 mahasan: root@export [13291]: tail -f /var/log/mysql/mysql.log [0]
Dec  7 22:13:09 validationdb2 mahasan: root@export [13291]: ls -lh [0]
Dec  7 22:13:27 validationdb2 mahasan: root@export [13291]: touch test command  [0]