GNU screen has an amazing config option that I used almost all the time:
logfile screenlogs/%S%Y%m%d-%n.log
deflog on
The problem is that tmux doesnt have the same option :( the closest thing I have seen is the "pipe-pane" option, but I couldnt find any way to automate that upon startup of tmux. I figured, well since tmux doesnt let me do it, maybe I can hack something together myself. And thats exactly what i did. I give to you...tmux output logging via the script command:
if [[ $TERM = "screen" ]] && [[ $(ps $PPID -o comm=) = "tmux" ]] ; then logname="$(date '+%d.%m.%Y_%H:%M:%S').tmux.log" mkdir $HOME/logs 2> /dev/null script -t 1 $HOME/logs/${logname} bash -login exit fi
That code works for OSX, for your basic GNU linux setup try this instead:
if [[ $TERM = "screen" ]] && [[ $(ps -p $PPID -o comm=) = "tmux" ]]; then logname="$(date '+%d.%m.%Y_%H:%M:%S').tmux.log" mkdir $HOME/logs 2> /dev/null script -f $HOME/logs/${logname} exit fi
All you have to do is put that code into your .profile or .bashrc/.bash_profile and you are good to go.
Enjoy!
There is an easier way of having the log dumped into the file. As you mentioned the `pipe-pane` is the answer.
ReplyDeletetmux new-session -d 'ping -c 100 google.com'\; pipe-pane -o 'cat >>$HOME/tmux.log'
Cheers