Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
View docker-compose services logs in split tmux panes
# Requires pyyaml
import os
import yaml
run = os.system
new_window = lambda cmd: run('tmux new-window -n "logs" "{}"'.format(cmd))
split_vertical = lambda cmd: run('tmux split-window "{}"'.format(cmd))
split_horizontal = lambda cmd: run('tmux split-window -h "{}"'.format(cmd))
even_vertical = lambda: run('tmux select-layout even-vertical')
if __name__ == '__main__':
config_text = open('docker-compose.yaml').read()
except IOError:
config_text = open('docker-compose.yml').read()
config = yaml.load(config_text)
services = config['services'].keys()
new_window('docker-compose logs -f {}'.format(services[0]))
for service in services[1:]:
split_horizontal('docker-compose logs -f {}'.format(service))

This comment has been minimized.

Copy link

pletnes commented Apr 2, 2019

This works great for me! One minor issue - to run on python 3.7, line 20 should be:

    services = list(config['services'].keys())

This comment has been minimized.

Copy link

saintaardvark commented May 23, 2020

To get around this warning:

/ YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, 
as the default Loader is unsafe. Please read for full details.
  config = yaml.load(config_text) need to change line 18 to:

    config = yaml.load(config_text, Loader=yaml.SafeLoader)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.