diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-23 10:02:08 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-23 10:02:08 +0000 |
| commit | 58d44c6ba2de32a31a09bbcaf61365a69b69374c (patch) | |
| tree | 40f50d70e9ac2bb48d680e4b2fc4a4480eaf4f99 /editors/code/src | |
| parent | dea1d957e5fec51e8210b3fc4d2db7099d0ff000 (diff) | |
| parent | 49844ab717d8d1790dbdf7f44d160936ece0e80f (diff) | |
| download | rust-58d44c6ba2de32a31a09bbcaf61365a69b69374c.tar.gz rust-58d44c6ba2de32a31a09bbcaf61365a69b69374c.zip | |
Merge #3261
3261: Extract client-side logging r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/config.ts | 5 | ||||
| -rw-r--r-- | editors/code/src/inlay_hints.ts | 3 | ||||
| -rw-r--r-- | editors/code/src/installation/download_artifact.ts | 2 | ||||
| -rw-r--r-- | editors/code/src/installation/download_file.ts | 7 | ||||
| -rw-r--r-- | editors/code/src/installation/fetch_artifact_release_info.ts | 3 | ||||
| -rw-r--r-- | editors/code/src/installation/server.ts | 19 | ||||
| -rw-r--r-- | editors/code/src/main.ts | 3 | ||||
| -rw-r--r-- | editors/code/src/util.ts | 18 |
8 files changed, 42 insertions, 18 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 347c989c455..47e8cd45d06 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -1,6 +1,7 @@ import * as os from "os"; import * as vscode from 'vscode'; import { BinarySource } from "./installation/interfaces"; +import { log } from "./util"; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; @@ -46,7 +47,9 @@ export class Config { private refreshConfig() { this.cfg = vscode.workspace.getConfiguration(Config.rootSection); - console.log("Using configuration:", this.cfg); + const enableLogging = this.cfg.get("trace.extension") as boolean; + log.setEnabled(enableLogging); + log.debug("Using configuration:", this.cfg); } private async onConfigChange(event: vscode.ConfigurationChangeEvent) { diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 641ec15c683..7e6c310a9af 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -2,6 +2,7 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import { Ctx, sendRequestWithRetry } from './ctx'; +import { log } from './util'; export function activateInlayHints(ctx: Ctx) { const hintsUpdater = new HintsUpdater(ctx); @@ -71,7 +72,7 @@ class HintsUpdater { } async setEnabled(enabled: boolean): Promise<void> { - console.log({ enabled, prev: this.enabled }); + log.debug({ enabled, prev: this.enabled }); if (this.enabled === enabled) return; this.enabled = enabled; diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts index 9996c556fc4..356723abaf5 100644 --- a/editors/code/src/installation/download_artifact.ts +++ b/editors/code/src/installation/download_artifact.ts @@ -29,7 +29,6 @@ export async function downloadArtifact( const installationPath = path.join(installationDir, artifactFileName); - console.time(`Downloading ${artifactFileName}`); await vscode.window.withProgress( { location: vscode.ProgressLocation.Notification, @@ -54,5 +53,4 @@ export async function downloadArtifact( ); } ); - console.timeEnd(`Downloading ${artifactFileName}`); } diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index d154f4816c7..319cb995c4f 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts @@ -3,6 +3,7 @@ import * as fs from "fs"; import * as stream from "stream"; import * as util from "util"; import { strict as assert } from "assert"; +import { log } from "../util"; const pipeline = util.promisify(stream.pipeline); @@ -21,8 +22,8 @@ export async function downloadFile( const res = await fetch(url); if (!res.ok) { - console.log("Error", res.status, "while downloading file from", url); - console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); + log.error("Error", res.status, "while downloading file from", url); + log.error({ body: await res.text(), headers: res.headers }); throw new Error(`Got response ${res.status} when trying to download a file.`); } @@ -30,7 +31,7 @@ export async function downloadFile( const totalBytes = Number(res.headers.get('content-length')); assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); - console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); + log.debug("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); let readBytes = 0; res.body.on("data", (chunk: Buffer) => { diff --git a/editors/code/src/installation/fetch_artifact_release_info.ts b/editors/code/src/installation/fetch_artifact_release_info.ts index 1e764718c96..1b6fc8d48c0 100644 --- a/editors/code/src/installation/fetch_artifact_release_info.ts +++ b/editors/code/src/installation/fetch_artifact_release_info.ts @@ -1,5 +1,6 @@ import fetch from "node-fetch"; import { GithubRepo, ArtifactReleaseInfo } from "./interfaces"; +import { log } from "../util"; const GITHUB_API_ENDPOINT_URL = "https://api.github.com"; @@ -24,7 +25,7 @@ export async function fetchArtifactReleaseInfo( // We skip runtime type checks for simplicity (here we cast from `any` to `GithubRelease`) - console.log("Issuing request for released artifacts metadata to", requestUrl); + log.debug("Issuing request for released artifacts metadata to", requestUrl); // FIXME: handle non-ok response const response: GithubRelease = await fetch(requestUrl, { diff --git a/editors/code/src/installation/server.ts b/editors/code/src/installation/server.ts index 75085292195..685abfdc6da 100644 --- a/editors/code/src/installation/server.ts +++ b/editors/code/src/installation/server.ts @@ -7,6 +7,7 @@ import { spawnSync } from "child_process"; import { BinarySource } from "./interfaces"; import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; import { downloadArtifact } from "./download_artifact"; +import { log } from "../util"; export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { if (!source) { @@ -40,7 +41,7 @@ export async function ensureServerBinary(source: null | BinarySource): Promise<n const installedVersion: null | string = getServerVersion(source.storage); const requiredVersion: string = source.version; - console.log("Installed version:", installedVersion, "required:", requiredVersion); + log.debug("Installed version:", installedVersion, "required:", requiredVersion); if (isBinaryAvailable(prebuiltBinaryPath) && installedVersion === requiredVersion) { return prebuiltBinaryPath; @@ -72,16 +73,16 @@ async function downloadServer(source: BinarySource.GithubRelease): Promise<boole `GitHub repository: ${err.message}` ); - console.error(err); + log.error(err); dns.resolve('example.com').then( - addrs => console.log("DNS resolution for example.com was successful", addrs), + addrs => log.debug("DNS resolution for example.com was successful", addrs), err => { - console.error( + log.error( "DNS resolution for example.com failed, " + "there might be an issue with Internet availability" ); - console.error(err); + log.error(err); } ); return false; @@ -105,19 +106,19 @@ function isBinaryAvailable(binaryPath: string): boolean { // ACHTUNG! `res` type declaration is inherently wrong, see // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42221 - console.log("Checked binary availablity via --version", res); - console.log(binaryPath, "--version output:", res.output?.map(String)); + log.debug("Checked binary availablity via --version", res); + log.debug(binaryPath, "--version output:", res.output?.map(String)); return res.status === 0; } function getServerVersion(storage: vscode.Memento): null | string { const version = storage.get<null | string>("server-version", null); - console.log("Get server-version:", version); + log.debug("Get server-version:", version); return version; } async function setServerVersion(storage: vscode.Memento, version: string): Promise<void> { - console.log("Set server-version:", version); + log.debug("Set server-version:", version); await storage.update("server-version", version.toString()); } diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index de19a44e517..7b3bb6302c0 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -7,6 +7,7 @@ import { Ctx } from './ctx'; import { activateHighlighting } from './highlighting'; import { ensureServerBinary } from './installation/server'; import { Config } from './config'; +import { log } from './util'; let ctx: Ctx | undefined; @@ -38,7 +39,7 @@ export async function activate(context: vscode.ExtensionContext) { try { sub.dispose(); } catch (e) { - console.error(e); + log.error(e); } } await activate(context); diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts new file mode 100644 index 00000000000..7a6657753ba --- /dev/null +++ b/editors/code/src/util.ts @@ -0,0 +1,18 @@ +let enabled: boolean = false; + +export const log = { + debug(message?: any, ...optionalParams: any[]): void { + if (!enabled) return; + // eslint-disable-next-line no-console + console.log(message, ...optionalParams); + }, + error(message?: any, ...optionalParams: any[]): void { + if (!enabled) return; + debugger; + // eslint-disable-next-line no-console + console.error(message, ...optionalParams); + }, + setEnabled(yes: boolean): void { + enabled = yes; + } +}; |
