Skip to content

Commit

Permalink
Enable configuration for View Logs command
Browse files Browse the repository at this point in the history
Adds two configuration options, Follow and Tail, that match -f and --tail
command line arguments of "docker logs" command.

Closes microsoft#1505.
  • Loading branch information
luka-zitnik committed Jan 11, 2020
1 parent 1ef900a commit 36d3b12
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion src/commands/containers/viewContainerLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -12,7 +13,18 @@ export async function viewContainerLogs(context: IActionContext, node?: Containe
node = await ext.containersTree.showTreeItemPicker<ContainerTreeItem>(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();
}

0 comments on commit 36d3b12

Please sign in to comment.