Skip to content

Commit ed8a866

Browse files
author
timt
committed
Added support for multiplexed logs
1 parent 628c02b commit ed8a866

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Docker.DotNet/Endpoints/ISwarmOperations.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public interface ISwarmOperations
158158
/// <summary>
159159
/// Get service logs.
160160
///
161-
/// Get {stdout} and {stderr} logs from a container.
161+
/// Get {stdout} and {stderr} logs from all service tasks.
162162
/// Note: This endpoint works only for services with the {json-file} or {journald} logging driver.
163163
/// </summary>
164164
/// <remarks>
@@ -175,6 +175,17 @@ public interface ISwarmOperations
175175
/// <param name="id">ID or name of the service.</param>
176176
Task<Stream> GetServiceLogsAsync(string id, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken));
177177

178+
/// <summary>
179+
/// Gets the <code>stdout</code> and <code>stderr</code> logs from all service tasks.
180+
/// This endpoint works only for services with the <code>json-file</code> or <code>journald</code> logging driver.
181+
/// </summary>
182+
/// <param name="id">ID or name of the service.</param>
183+
/// <param name="tty">If the service was created with a TTY or not. If <see langword="false" />, the returned stream is multiplexed.</param>
184+
/// <param name="parameters">The parameters used to retrieve the logs.</param>
185+
/// <param name="cancellationToken">A token used to cancel this operation.</param>
186+
/// <returns>A stream with the retrieved logs. If the service wasn't created with a TTY, this stream is multiplexed.</returns>
187+
Task<MultiplexedStream> GetServiceLogsAsync(string id, bool tty, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken));
188+
178189
#endregion Services
179190

180191
#region Nodes

src/Docker.DotNet/Endpoints/SwarmOperations.cs

+19
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@ async Task<ServiceUpdateResponse> ISwarmOperations.UpdateServiceAsync(string id,
173173
return this._client.MakeRequestForStreamAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}/logs", queryParameters, cancellationToken);
174174
}
175175

176+
public async Task<MultiplexedStream> GetContainerLogsAsync(string id, bool tty, ServiceLogsParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
177+
{
178+
if (string.IsNullOrEmpty(id))
179+
{
180+
throw new ArgumentNullException(nameof(id));
181+
}
182+
183+
if (parameters == null)
184+
{
185+
throw new ArgumentNullException(nameof(parameters));
186+
}
187+
188+
IQueryString queryParameters = new QueryString<ServiceLogsParameters>(parameters);
189+
190+
Stream result = await this._client.MakeRequestForStreamAsync(new[] { SwarmResponseHandler }, HttpMethod.Get, $"services/{id}/logs", queryParameters, cancellationToken).ConfigureAwait(false);
191+
192+
return new MultiplexedStream(result, !tty);
193+
}
194+
176195
async Task ISwarmOperations.UpdateSwarmAsync(SwarmUpdateParameters parameters, CancellationToken cancellationToken)
177196
{
178197
var query = new QueryString<SwarmUpdateParameters>(parameters ?? throw new ArgumentNullException(nameof(parameters)));

0 commit comments

Comments
 (0)