Is it possible to configure tmux so that whatever sessions are created, executed, closed tmux would automatically create appropriate directory with unique session name, log all the output of those sessions into the files, rotate them and delete the old ones...

This would be one global solution to logging if all your services are being run in tmux and output to stdout/err.


It is possible, and the command for saving the contents of the current pane is

capture-pane -S - -E - ; save-buffer ~/path/to/logfile ; delete-buffer

There are many variables available, so that you can do things like

capture-pane -S - -E -
save-buffer ~/path/to/#{session_name}/#{window_name}/#{pane_id}

You can run shell commands with run-shell. You can set up hooks for various events (e.g. session-created, pane-exited (triggered when a command in a pane exits, session-closed) with set-hook.

Have a look at the manual (man tmux) for more details. Though, I don't know if this is the best solution for logging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.