diff --git a/docker/client.py b/docker/client.py index 4ff91d84..edfd3110 100644 --- a/docker/client.py +++ b/docker/client.py @@ -679,14 +679,17 @@ class Client(requests.Session): return self._result(response, json=True) def logs(self, container, stdout=True, stderr=True, stream=False, - timestamps=False): + timestamps=False, tail='all'): if isinstance(container, dict): container = container.get('Id') if utils.compare_version('1.11', self._version) >= 0: + if tail != 'all' and (not isinstance(tail, int) or tail <= 0): + tail = 'all' params = {'stderr': stderr and 1 or 0, 'stdout': stdout and 1 or 0, 'timestamps': timestamps and 1 or 0, - 'follow': stream and 1 or 0} + 'follow': stream and 1 or 0, + 'tail': tail} url = self._url("/containers/{0}/logs".format(container)) res = self._get(url, params=params, stream=stream) if stream: diff --git a/tests/test.py b/tests/test.py index 984e350e..fe283257 100644 --- a/tests/test.py +++ b/tests/test.py @@ -963,7 +963,8 @@ class DockerClientTest(Cleanup, unittest.TestCase): fake_request.assert_called_with( url_prefix + 'containers/3cc2351ab11b/logs', - params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1}, + params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1, + 'tail': 'all'}, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS, stream=False ) @@ -981,7 +982,8 @@ class DockerClientTest(Cleanup, unittest.TestCase): fake_request.assert_called_with( url_prefix + 'containers/3cc2351ab11b/logs', - params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1}, + params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1, + 'tail': 'all'}, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS, stream=False ) @@ -999,7 +1001,8 @@ class DockerClientTest(Cleanup, unittest.TestCase): fake_request.assert_called_with( url_prefix + 'containers/3cc2351ab11b/logs', - params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1}, + params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1, + 'tail': 'all'}, timeout=docker.client.DEFAULT_TIMEOUT_SECONDS, stream=True )