From 49844ab717d8d1790dbdf7f44d160936ece0e80f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Feb 2020 15:59:46 +0100 Subject: Extract client-side logging --- editors/code/src/installation/download_artifact.ts | 2 -- editors/code/src/installation/download_file.ts | 7 ++++--- .../src/installation/fetch_artifact_release_info.ts | 3 ++- editors/code/src/installation/server.ts | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 15 deletions(-) (limited to 'editors/code/src/installation') diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts index 9996c556f..356723aba 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 d154f4816..319cb995c 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 1e764718c..1b6fc8d48 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 750852921..685abfdc6 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 { if (!source) { @@ -40,7 +41,7 @@ export async function ensureServerBinary(source: null | BinarySource): Promise 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("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 { - console.log("Set server-version:", version); + log.debug("Set server-version:", version); await storage.update("server-version", version.toString()); } -- cgit v1.2.3