forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
45 lines (38 loc) · 1.86 KB
/
logger.ts
File metadata and controls
45 lines (38 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable, named } from 'inversify';
import { isCI, isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../constants';
import { traceInfo } from '../logger';
import { IOutputChannel, IPathUtils } from '../types';
import { Logging } from '../utils/localize';
import { IProcessLogger, SpawnOptions } from './types';
@injectable()
export class ProcessLogger implements IProcessLogger {
constructor(
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly outputChannel: IOutputChannel,
@inject(IPathUtils) private readonly pathUtils: IPathUtils
) {}
public logProcess(file: string, args: string[], options?: SpawnOptions) {
if (!isTestExecution() && isCI && process.env.UITEST_DISABLE_PROCESS_LOGGING) {
// Added to disable logging of process execution commands during UI Tests.
// Used only during UI Tests (hence this setting need not be exposed as a valid setting).
return;
}
const argsList = args.reduce((accumulator, current, index) => {
let formattedArg = this.pathUtils.getDisplayName(current).toCommandArgument();
if (current[0] === "'" || current[0] === '"') {
formattedArg = `${current[0]}${this.pathUtils.getDisplayName(current.substr(1))}`;
}
return index === 0 ? formattedArg : `${accumulator} ${formattedArg}`;
}, '');
const info = [`> ${this.pathUtils.getDisplayName(file)} ${argsList}`];
if (options && options.cwd) {
info.push(`${Logging.currentWorkingDirectory()} ${this.pathUtils.getDisplayName(options.cwd)}`);
}
info.forEach(line => {
traceInfo(line);
this.outputChannel.appendLine(line);
});
}
}