forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
38 lines (32 loc) · 1.52 KB
/
logger.ts
File metadata and controls
38 lines (32 loc) · 1.52 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { inject, injectable, named } from 'inversify';
import { 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) {
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);
});
}
}