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