mirror of https://github.com/docker/compose.git
parent
b4c905dc83
commit
feafea2c6d
|
@ -31,28 +31,18 @@ class LogPrinter(object):
|
||||||
|
|
||||||
def _make_log_generator(self, container, color_fn):
|
def _make_log_generator(self, container, color_fn):
|
||||||
prefix = color_fn(container.name + " | ")
|
prefix = color_fn(container.name + " | ")
|
||||||
websocket = self._attach(container)
|
for line in split_buffer(self._attach(container), '\n'):
|
||||||
return (prefix + line for line in split_buffer(read_websocket(websocket), '\n'))
|
yield prefix + line
|
||||||
|
|
||||||
def _attach(self, container):
|
def _attach(self, container):
|
||||||
params = {
|
params = {
|
||||||
'stdin': False,
|
|
||||||
'stdout': True,
|
'stdout': True,
|
||||||
'stderr': True,
|
'stderr': True,
|
||||||
'logs': False,
|
|
||||||
'stream': True,
|
'stream': True,
|
||||||
}
|
}
|
||||||
params.update(self.attach_params)
|
params.update(self.attach_params)
|
||||||
params = dict((name, 1 if value else 0) for (name, value) in list(params.items()))
|
params = dict((name, 1 if value else 0) for (name, value) in list(params.items()))
|
||||||
return container.attach_socket(params=params, ws=True)
|
return container.attach(**params)
|
||||||
|
|
||||||
def read_websocket(websocket):
|
|
||||||
while True:
|
|
||||||
data = websocket.recv()
|
|
||||||
if data:
|
|
||||||
yield data
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
def split_buffer(reader, separator):
|
def split_buffer(reader, separator):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -122,6 +122,9 @@ class Container(object):
|
||||||
links.append(bits[2])
|
links.append(bits[2])
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
def attach(self, *args, **kwargs):
|
||||||
|
return self.client.attach(self.id, *args, **kwargs)
|
||||||
|
|
||||||
def attach_socket(self, **kwargs):
|
def attach_socket(self, **kwargs):
|
||||||
return self.client.attach_socket(self.id, **kwargs)
|
return self.client.attach_socket(self.id, **kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue