From 36d3b1259697a33f82bf6b22f1fdf3a2a6c09568 Mon Sep 17 00:00:00 2001 From: Luka Zitnik Date: Sat, 11 Jan 2020 18:39:46 +0100 Subject: [PATCH] Enable configuration for View Logs command Adds two configuration options, Follow and Tail, that match -f and --tail command line arguments of "docker logs" command. Closes #1505. --- package.json | 14 ++++++++++++++ src/commands/containers/viewContainerLogs.ts | 14 +++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) 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(); }