@@ -166,6 +166,55 @@ def services(self, filters=None):
166
166
url = self ._url ('/services' )
167
167
return self ._result (self ._get (url , params = params ), True )
168
168
169
+ @utils .minimum_version ('1.25' )
170
+ def service_logs (self , service , details = False , follow = False , stdout = False ,
171
+ stderr = False , since = 0 , timestamps = False , tail = 'all' ,
172
+ is_tty = None ):
173
+ """
174
+ Get log stream for a service.
175
+ Note: This endpoint works only for services with the ``json-file``
176
+ or ``journald`` logging drivers.
177
+
178
+ Args:
179
+ service (str): ID or name of the container
180
+ details (bool): Show extra details provided to logs.
181
+ Default: ``False``
182
+ follow (bool): Keep connection open to read logs as they are
183
+ sent by the Engine. Default: ``False``
184
+ stdout (bool): Return logs from ``stdout``. Default: ``False``
185
+ stderr (bool): Return logs from ``stderr``. Default: ``False``
186
+ since (int): UNIX timestamp for the logs staring point.
187
+ Default: 0
188
+ timestamps (bool): Add timestamps to every log line.
189
+ tail (string or int): Number of log lines to be returned,
190
+ counting from the current end of the logs. Specify an
191
+ integer or ``'all'`` to output all log lines.
192
+ Default: ``all``
193
+ is_tty (bool): Whether the service's :py:class:`ContainerSpec`
194
+ enables the TTY option. If omitted, the method will query
195
+ the Engine for the information, causing an additional
196
+ roundtrip.
197
+
198
+ Returns (generator): Logs for the service.
199
+ """
200
+ params = {
201
+ 'details' : details ,
202
+ 'follow' : follow ,
203
+ 'stdout' : stdout ,
204
+ 'stderr' : stderr ,
205
+ 'since' : since ,
206
+ 'timestamps' : timestamps ,
207
+ 'tail' : tail
208
+ }
209
+
210
+ url = self ._url ('/services/{0}/logs' , service )
211
+ res = self ._get (url , params = params , stream = True )
212
+ if is_tty is None :
213
+ is_tty = self .inspect_service (
214
+ service
215
+ )['Spec' ]['TaskTemplate' ]['ContainerSpec' ].get ('TTY' , False )
216
+ return self ._get_result_tty (True , res , is_tty )
217
+
169
218
@utils .minimum_version ('1.24' )
170
219
def tasks (self , filters = None ):
171
220
"""
0 commit comments