forked from microsoft/vscode-java-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
55 lines (45 loc) · 1.69 KB
master
/
logger.ts
File metadata and controls
- Code
- Blame
55 lines (45 loc) · 1.69 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
55
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as fs from "fs";
import * as vscode from "vscode";
import TelemetryReporter from "vscode-extension-telemetry";
export enum Type {
EXCEPTION = "exception",
USAGEDATA = "usageData",
USAGEERROR = "usageError",
ACTIVATEEXTENSION = "activateExtension", // TODO: Activation belongs to usage data, remove this category.
}
class Logger implements vscode.Disposable {
private reporter: TelemetryReporter = null;
public initialize(context: vscode.ExtensionContext): void {
if (this.reporter) {
return;
}
const extensionPackage = JSON.parse(fs.readFileSync(context.asAbsolutePath("./package.json"), "utf-8"));
if (extensionPackage) {
const packageInfo = {
name: extensionPackage.name,
version: extensionPackage.version,
aiKey: extensionPackage.aiKey,
};
if (packageInfo.aiKey) {
this.reporter = new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
}
}
}
public log(type: Type, properties?: { [key: string]: string; }, measures?: { [key: string]: number; }): void {
if (!this.reporter) {
return;
}
this.reporter.sendTelemetryEvent(type, properties, measures);
}
public logMessage(type: Type, message: string): void {
this.log(type, { message });
}
public dispose() {
if (this.reporter) {
this.reporter.dispose();
}
}
}
export const logger = new Logger();