forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
54 lines (47 loc) · 1.58 KB
/
Copy pathutil.ts
File metadata and controls
54 lines (47 loc) · 1.58 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
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Uri } from 'vscode';
export type Arguments = unknown[];
function valueToLogString(value: unknown, kind: string): string {
if (value === undefined) {
return 'undefined';
}
if (value === null) {
return 'null';
}
try {
if (value && (value as Uri).fsPath) {
return `<Uri:${(value as Uri).fsPath}>`;
}
return JSON.stringify(value);
} catch {
return `<${kind} cannot be serialized for logging>`;
}
}
// Convert the given array of values (func call arguments) into a string
// suitable to be used in a log message.
export function argsToLogString(args: Arguments): string {
if (!args) {
return '';
}
try {
const argStrings = args.map((item, index) => {
const valueString = valueToLogString(item, 'argument');
return `Arg ${index + 1}: ${valueString}`;
});
return argStrings.join(', ');
} catch {
return '';
}
}
// Convert the given return value into a string
// suitable to be used in a log message.
export function returnValueToLogString(returnValue: unknown): string {
const valueString = valueToLogString(returnValue, 'Return value');
return `Return Value: ${valueString}`;
}
export function getTimeForLogging(): string {
const date = new Date();
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}.${date.getMilliseconds()}`;
}