diff --git a/package.json b/package.json index e14adcc66b..ba3af0c530 100644 --- a/package.json +++ b/package.json @@ -1513,6 +1513,20 @@ "default": "powershell", "description": "Attach command to use for Windows containers" }, + "docker.viewLogsCommand.follow": { + "type": "boolean", + "default": true, + "description": "Follow log output" + }, + "docker.viewLogsCommand.tail": { + "type": [ + "integer", + "null" + ], + "minimum": 0, + "default": null, + "description": "Number of lines to show from the end of the logs" + }, "docker.dockerComposeBuild": { "type": "boolean", "default": true, diff --git a/src/commands/containers/viewContainerLogs.ts b/src/commands/containers/viewContainerLogs.ts index b8f07c65e7..e0dbda9f0d 100644 --- a/src/commands/containers/viewContainerLogs.ts +++ b/src/commands/containers/viewContainerLogs.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See LICENSE.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as vscode from 'vscode'; import { IActionContext } from 'vscode-azureextensionui'; import { ext } from '../../extensionVariables'; import { ContainerTreeItem } from '../../tree/containers/ContainerTreeItem'; @@ -12,7 +13,18 @@ export async function viewContainerLogs(context: IActionContext, node?: Containe node = await ext.containersTree.showTreeItemPicker(ContainerTreeItem.allContextRegExp, context); } + const commandOptions: string[] = []; + const configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker'); + const follow: boolean = configOptions.get('viewLogsCommand.follow'); + const tail: number | null = configOptions.get('viewLogsCommand.tail'); + if (follow) { + commandOptions.push('-f'); + } + if (tail !== null) { + commandOptions.push(`--tail=${tail}`); + } + const terminal = ext.terminalProvider.createTerminal(node.fullTag); - terminal.sendText(`docker logs -f ${node.containerId}`); + terminal.sendText(`docker logs ${commandOptions.join(' ')} ${node.containerId}`); terminal.show(); }