Skip to content

Commit 3a51b69

Browse files
authored
dev: custom logfile path #3299
Problem: vscode always changes the logfile location, so following it with "tail -F" is not easy. Solution: Introduce setting "aws.dev.logfile" which sets a fixed logfile path.
1 parent 0df8dab commit 3a51b69

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ Toolkit for testing and development purposes. To use a setting just add it to
236236
your `settings.json`. At runtime, if the Toolkit reads any of these settings,
237237
the "AWS" statusbar item will [change its color](https://github.com/aws/aws-toolkit-vscode/blob/479b9d45b5f5ad30fc10567e649b59801053aeba/src/credentials/awsCredentialsStatusBarItem.ts#L45). Use the setting `aws.dev.forceDevMode` to trigger this effect on start-up.
238238
239+
### Logging
240+
241+
The `aws.dev.logfile` setting allows you to set the path of the logfile. This makes it easy to
242+
follow and filter the logfile using shell tools like `tail` and `grep`. For example in
243+
settings.json,
244+
245+
"aws.dev.logfile": "~/awstoolkit.log",
246+
247+
then following the log with:
248+
249+
tail -F ~/awstoolkit.log
250+
239251
### Service Endpoints
240252
241253
Endpoint overrides can be set per-service using the `aws.dev.endpoints` settings. This is a JSON object where each key is the service ID (case-insensitive) and each value is the endpoint. Refer to the SDK [API models](https://github.com/aws/aws-sdk-js/tree/master/apis) to find relevant service IDs.

src/shared/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as vscode from 'vscode'
77

88
import { isCloud9 } from './extensionUtilities'
99

10-
export const extensionSettingsPrefix = 'aws'
1110
export const regionSettingKey = 'region'
1211
export const profileSettingKey = 'profile'
1312
export const productName: string = 'aws-toolkit-vscode'

src/shared/logger/activation.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as vscode from 'vscode'
99
import * as nls from 'vscode-nls'
1010
import * as fs from 'fs-extra'
1111
import { Logger, LogLevel, getLogger } from '.'
12-
import { extensionSettingsPrefix } from '../constants'
1312
import { setLogger } from './logger'
1413
import { logOutputChannel } from './outputChannel'
1514
import { WinstonToolkitLogger } from './winstonToolkitLogger'
@@ -18,6 +17,7 @@ import { cleanLogFiles } from './util'
1817
import { Settings } from '../settings'
1918
import { Logging } from './commands'
2019
import { SystemUtilities } from '../systemUtilities'
20+
import { resolvePath } from '../utilities/pathUtils'
2121

2222
const localize = nls.loadMessageBundle()
2323

@@ -31,7 +31,11 @@ export async function activate(
3131
outputChannel: vscode.OutputChannel
3232
): Promise<void> {
3333
const chan = logOutputChannel
34-
const logUri = vscode.Uri.joinPath(extensionContext.logUri, makeLogFilename())
34+
const settings = Settings.instance.getSection('aws')
35+
const devLogfile = settings.get('dev.logfile', '')
36+
const logUri = devLogfile
37+
? vscode.Uri.file(resolvePath(devLogfile))
38+
: vscode.Uri.joinPath(extensionContext.logUri, makeLogFilename())
3539

3640
await SystemUtilities.createDirectory(extensionContext.logUri)
3741

@@ -139,8 +143,7 @@ export function makeLogger(
139143
}
140144

141145
function getLogLevel(): LogLevel {
142-
const configuration = Settings.instance.getSection(extensionSettingsPrefix)
143-
146+
const configuration = Settings.instance.getSection('aws')
144147
return configuration.get('logLevel', defaultLogLevel)
145148
}
146149

src/shared/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ export class Experiments extends Settings.define(
539539
}
540540

541541
const devSettings = {
542+
logfile: String,
542543
forceCloud9: Boolean,
543544
forceDevMode: Boolean,
544545
forceInstallTools: Boolean,

src/shared/utilities/pathUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import * as _path from 'path'
88

99
export const driveLetterRegex = /^[a-zA-Z]\:/
1010

11+
/**
12+
* Expands "~" at the start of `fname` to user home dir.
13+
* TODO: expand env vars too.
14+
*/
15+
export function resolvePath(fname: string) {
16+
const homedir = os.homedir()
17+
if (fname.startsWith('~/') || fname.startsWith('~\\')) {
18+
return _path.join(homedir, fname.substring(2))
19+
}
20+
21+
return fname
22+
}
23+
1124
function isUncPath(path: string) {
1225
return /^\s*[\/\\]{2}[^\/\\]+/.test(path)
1326
}

0 commit comments

Comments
 (0)