From 1633f4fccbbc1bcbc6216fe13b8e888c8940bde4 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Fri, 12 Mar 2021 14:47:50 -0800 Subject: [PATCH] Upgrade logger to TypeScript (#3138) Rewrote our logger code in TypeScript. Because we now need access to types in exported in the logger file, we export logger as a named export instead of assigning exports to logger (an anti-pattern anyway). This change touches nearly every file because of the named import change. To reduce risk these changes have been made robotically: ```bash git grep -e "require(.*logger" --name-only | xargs sed -i '' -e 's/var logger = require("\(.*logger\)")/const { logger } = require("\1")/g' git grep -e "require(.*logger" --name-only | xargs sed -i '' -e 's/const logger = require("\(.*logger\)")/const { logger } = require("\1")/g' git grep -e "import logger = require(.*logger" --name-only | xargs sed -i '' -e 's/logger = require("\(.*logger\)")/{ logger } from "\1"/g' git grep -e "import \* as logger" --name-only | xargs sed -i '' -e 's/import \* as logger/import { logger }/g' ``` Other changes like `import { warn } from 'logger'` were touched up manually Additionally, there were configurations in our logger that had been removed from the winston spec several versions ago (Particularly in our emulator code). TypeScirpt caught these errors and I upgraded to the new version of these APIs. --- CONTRIBUTING.md | 2 +- .../emulator-tests/functionsEmulator.spec.ts | 20 ++-- src/accountImporter.js | 2 +- src/api.js | 2 +- src/apiv2.ts | 2 +- src/appdistribution/distribution.ts | 2 +- src/archiveDirectory.js | 2 +- src/auth.ts | 2 +- src/bin/firebase.js | 2 +- src/checkFirebaseSDKVersion.ts | 2 +- src/commands/apps-android-sha-list.ts | 2 +- src/commands/apps-create.ts | 2 +- src/commands/apps-list.ts | 2 +- src/commands/apps-sdkconfig.ts | 2 +- src/commands/auth-export.js | 2 +- src/commands/auth-import.js | 2 +- src/commands/database-get.ts | 2 +- src/commands/database-instances-create.ts | 2 +- src/commands/database-instances-list.ts | 2 +- src/commands/database-push.ts | 2 +- src/commands/database-rules-get.ts | 2 +- src/commands/database-rules-list.ts | 2 +- src/commands/database-rules-stage.ts | 2 +- src/commands/database-set.ts | 2 +- src/commands/database-update.ts | 2 +- src/commands/emulators-start.ts | 2 +- src/commands/ext-configure.ts | 2 +- src/commands/ext-dev-init.ts | 2 +- src/commands/ext-dev-list.ts | 2 +- src/commands/ext-info.ts | 2 +- src/commands/ext-install.ts | 2 +- src/commands/ext-sources-create.ts | 2 +- src/commands/ext-uninstall.ts | 2 +- src/commands/ext.ts | 2 +- src/commands/firestore-indexes-list.ts | 2 +- src/commands/functions-config-clone.js | 2 +- src/commands/functions-config-get.js | 2 +- src/commands/functions-config-legacy.js | 2 +- src/commands/functions-config-set.js | 2 +- src/commands/functions-config-unset.js | 2 +- src/commands/functions-log.ts | 2 +- src/commands/help.js | 2 +- src/commands/hosting-channel-create.ts | 2 +- src/commands/hosting-channel-delete.ts | 2 +- src/commands/hosting-channel-deploy.ts | 2 +- src/commands/hosting-channel-list.ts | 2 +- src/commands/hosting-clone.ts | 2 +- src/commands/hosting-sites-create.ts | 2 +- src/commands/hosting-sites-delete.ts | 2 +- src/commands/hosting-sites-get.ts | 2 +- src/commands/hosting-sites-list.ts | 2 +- src/commands/init.js | 2 +- src/commands/login-ci.js | 2 +- src/commands/login.ts | 2 +- src/commands/logout.js | 2 +- src/commands/open.ts | 2 +- src/commands/projects-list.ts | 2 +- src/commands/remoteconfig-get.ts | 2 +- src/commands/remoteconfig-versions-list.ts | 2 +- src/commands/serve.js | 2 +- src/commands/target-apply.js | 2 +- src/commands/target.js | 2 +- src/commands/use.js | 2 +- src/database/listRemote.ts | 2 +- src/database/metadata.ts | 2 +- src/database/removeRemote.ts | 2 +- src/database/rulesConfig.ts | 2 +- src/defaultCredentials.ts | 2 +- src/deploy/firestore/deploy.ts | 2 +- src/deploy/functions/checkIam.ts | 13 ++- src/deploy/functions/deploymentTimer.ts | 2 +- src/deploy/functions/errorHandler.ts | 2 +- src/deploy/functions/prompts.ts | 2 +- src/deploy/functions/tasks.ts | 2 +- src/deploy/functions/validate.ts | 2 +- src/deploy/hosting/deploy.js | 2 +- src/deploy/hosting/hashcache.js | 2 +- src/deploy/hosting/release.js | 2 +- src/deploy/hosting/uploader.ts | 2 +- src/deploy/index.js | 2 +- src/deploy/lifecycleHooks.js | 2 +- src/emulator/adminSdkConfig.ts | 2 +- src/emulator/commandUtils.ts | 2 +- src/emulator/controller.ts | 2 +- src/emulator/emulatorLogger.ts | 2 +- src/emulator/functionsEmulator.ts | 2 +- src/emulator/functionsEmulatorShell.ts | 2 +- src/emulator/hub.ts | 2 +- src/emulator/hubExport.ts | 2 +- src/emulator/loggingEmulator.ts | 19 ++-- src/emulator/portUtils.ts | 2 +- src/extensions/askUserForParam.ts | 2 +- src/extensions/checkProjectBilling.js | 2 +- src/extensions/displayExtensionInfo.ts | 2 +- src/extensions/extensionsApi.ts | 2 +- src/extensions/extensionsHelper.ts | 2 +- src/extensions/listExtensions.ts | 2 +- src/extensions/localHelper.ts | 2 +- src/extensions/paramHelper.ts | 2 +- src/extensions/resolveSource.ts | 2 +- src/extensions/updateHelper.ts | 2 +- src/firestore/checkDatabaseType.ts | 2 +- src/firestore/delete.ts | 2 +- src/firestore/indexes.ts | 2 +- src/functionsDeployHelper.ts | 2 +- src/functionsShellCommandAction.js | 2 +- src/gcp/cloudfunctions.ts | 2 +- src/gcp/firedata.ts | 2 +- src/gcp/iam.ts | 4 +- src/gcp/rules.ts | 2 +- src/gcp/runtimeconfig.js | 2 +- src/gcp/storage.js | 2 +- src/getDefaultHostingSite.ts | 2 +- src/hosting/cloudRunProxy.ts | 2 +- src/hosting/implicitInit.ts | 2 +- src/hosting/initMiddleware.ts | 2 +- src/hosting/proxy.ts | 2 +- src/index.js | 2 +- src/init/features/database.ts | 2 +- src/init/features/firestore/index.ts | 2 +- src/init/features/firestore/indexes.ts | 2 +- src/init/features/firestore/rules.ts | 2 +- src/init/features/functions/index.js | 2 +- .../features/functions/npm-dependencies.js | 2 +- src/init/features/hosting/github.ts | 2 +- src/init/features/hosting/index.js | 2 +- src/init/features/project.ts | 2 +- src/init/features/storage.ts | 2 +- src/init/index.ts | 2 +- src/logError.js | 2 +- src/logger.js | 29 ------ src/logger.ts | 94 +++++++++++++++++++ src/management/apps.ts | 2 +- src/management/database.ts | 2 +- src/management/projects.ts | 2 +- src/parseRuntimeAndValidateSDK.ts | 2 +- src/prepareFunctionsUpload.ts | 2 +- src/profileReport.js | 2 +- src/profiler.ts | 2 +- src/remoteconfig/get.ts | 2 +- src/remoteconfig/versionslist.ts | 2 +- src/requireAuth.ts | 2 +- src/requirePermissions.ts | 6 +- src/rulesDeploy.ts | 2 +- src/serve/index.ts | 2 +- .../checkRuntimeDependencies.spec.ts | 2 +- src/test/extensions/paramHelper.spec.ts | 2 +- src/throttler/throttler.ts | 2 +- src/track.js | 2 +- src/utils.ts | 14 +-- 150 files changed, 276 insertions(+), 207 deletions(-) delete mode 100644 src/logger.js create mode 100644 src/logger.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53419cb38af..7ce9c273247 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -270,7 +270,7 @@ The Firebase CLI has a central logger available in `src/logger`. You should never use `console.log()` when displaying output to the user. ```typescript -import * as logger from "../logger"; +import { logger } from "../logger"; logger.info("This text will be displayed to the end user."); logger.debug("This text will only show up in firebase-debug.log or running with --debug."); diff --git a/scripts/emulator-tests/functionsEmulator.spec.ts b/scripts/emulator-tests/functionsEmulator.spec.ts index 3747228bad3..4e10165a5c5 100644 --- a/scripts/emulator-tests/functionsEmulator.spec.ts +++ b/scripts/emulator-tests/functionsEmulator.spec.ts @@ -6,15 +6,21 @@ import { EmulatedTriggerType } from "../../src/emulator/functionsEmulatorShared" import { FunctionsEmulator, InvokeRuntimeOpts } from "../../src/emulator/functionsEmulator"; import { RuntimeWorker } from "../../src/emulator/functionsRuntimeWorker"; import { TIMEOUT_LONG, MODULE_ROOT } from "./fixtures"; -import * as logger from "../../src/logger"; +import { logger } from "../../src/logger"; +import * as winston from "winston"; +import * as logform from "logform"; if ((process.env.DEBUG || "").toLowerCase().indexOf("spec") >= 0) { - // tslint:disable-next-line:no-var-requires - logger.add(require("winston").transports.Console, { - level: "debug", - showLevel: false, - colorize: true, - }); + const dropLogLevels = (info: logform.TransformableInfo) => info.message; + logger.add( + new winston.transports.Console({ + level: "debug", + format: logform.format.combine( + logform.format.colorize(), + logform.format.printf(dropLogLevels) + ), + }) + ); } const functionsEmulator = new FunctionsEmulator({ diff --git a/src/accountImporter.js b/src/accountImporter.js index dc9570898ac..e32c3c011c6 100644 --- a/src/accountImporter.js +++ b/src/accountImporter.js @@ -4,7 +4,7 @@ var clc = require("cli-color"); var _ = require("lodash"); var api = require("./api"); -var logger = require("./logger"); +const { logger } = require("./logger"); var utils = require("./utils"); var { FirebaseError } = require("./error"); diff --git a/src/api.js b/src/api.js index 3cef8e3aaf8..35cee6e6d7c 100644 --- a/src/api.js +++ b/src/api.js @@ -7,7 +7,7 @@ var url = require("url"); var { Constants } = require("./emulator/constants"); var { FirebaseError } = require("./error"); -var logger = require("./logger"); +const { logger } = require("./logger"); var responseToError = require("./responseToError"); var scopes = require("./scopes"); var utils = require("./utils"); diff --git a/src/apiv2.ts b/src/apiv2.ts index 1b708158e2f..65513522fe6 100644 --- a/src/apiv2.ts +++ b/src/apiv2.ts @@ -8,7 +8,7 @@ import util from "util"; import * as auth from "./auth"; import { FirebaseError } from "./error"; -import * as logger from "./logger"; +import { logger } from "./logger"; import * as responseToError from "./responseToError"; // Using import would require resolveJsonModule, which seems to break the diff --git a/src/appdistribution/distribution.ts b/src/appdistribution/distribution.ts index 5fae86cdc64..50de89a201d 100644 --- a/src/appdistribution/distribution.ts +++ b/src/appdistribution/distribution.ts @@ -2,7 +2,7 @@ import * as fs from "fs-extra"; import { FirebaseError } from "../error"; import * as crypto from "crypto"; import { AppDistributionApp } from "./client"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as pathUtil from "path"; export enum DistributionFileType { diff --git a/src/archiveDirectory.js b/src/archiveDirectory.js index 92a01fb8141..421bf9fc56b 100644 --- a/src/archiveDirectory.js +++ b/src/archiveDirectory.js @@ -11,7 +11,7 @@ const tmp = require("tmp"); const { listFiles } = require("./listFiles"); const { FirebaseError } = require("./error"); const fsAsync = require("./fsAsync"); -const logger = require("./logger"); +const { logger } = require("./logger"); const utils = require("./utils"); /** diff --git a/src/auth.ts b/src/auth.ts index 64980decb94..bf45ee60312 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -11,7 +11,7 @@ import * as util from "util"; import * as api from "./api"; import { configstore } from "./configstore"; import { FirebaseError } from "./error"; -import * as logger from "./logger"; +import { logger } from "./logger"; import { prompt } from "./prompt"; import * as scopes from "./scopes"; diff --git a/src/bin/firebase.js b/src/bin/firebase.js index f779be0e3be..7540f3d7aa0 100755 --- a/src/bin/firebase.js +++ b/src/bin/firebase.js @@ -36,7 +36,7 @@ const client = require(".."); const errorOut = require("../errorOut").errorOut; const winston = require("winston"); const { SPLAT } = require("triple-beam"); -const logger = require("../logger"); +const { logger } = require("../logger"); const fs = require("fs"); const fsutils = require("../fsutils"); const path = require("path"); diff --git a/src/checkFirebaseSDKVersion.ts b/src/checkFirebaseSDKVersion.ts index b6ebd65d8c9..64460e9e407 100644 --- a/src/checkFirebaseSDKVersion.ts +++ b/src/checkFirebaseSDKVersion.ts @@ -5,7 +5,7 @@ import * as semver from "semver"; import * as spawn from "cross-spawn"; import * as utils from "./utils"; -import * as logger from "./logger"; +import { logger } from "./logger"; interface NpmListResult { name: string; diff --git a/src/commands/apps-android-sha-list.ts b/src/commands/apps-android-sha-list.ts index b6a819edc7b..03a73cbd62a 100644 --- a/src/commands/apps-android-sha-list.ts +++ b/src/commands/apps-android-sha-list.ts @@ -4,7 +4,7 @@ import { Command } from "../command"; import * as getProjectId from "../getProjectId"; import { listAppAndroidSha, AppAndroidShaData } from "../management/apps"; import { requireAuth } from "../requireAuth"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { promiseWithSpinner } from "../utils"; function logCertificatesList(certificates: AppAndroidShaData[]): void { diff --git a/src/commands/apps-create.ts b/src/commands/apps-create.ts index c01ac3a87a6..653ec59f028 100644 --- a/src/commands/apps-create.ts +++ b/src/commands/apps-create.ts @@ -17,7 +17,7 @@ import { } from "../management/apps"; import { prompt, promptOnce, Question } from "../prompt"; import { requireAuth } from "../requireAuth"; -import * as logger from "../logger"; +import { logger } from "../logger"; const DISPLAY_NAME_QUESTION: Question = { type: "input", diff --git a/src/commands/apps-list.ts b/src/commands/apps-list.ts index 7bd2bbf498b..69d9dcf9e39 100644 --- a/src/commands/apps-list.ts +++ b/src/commands/apps-list.ts @@ -6,7 +6,7 @@ import { Command } from "../command"; import * as getProjectId from "../getProjectId"; import { AppMetadata, AppPlatform, getAppPlatform, listFirebaseApps } from "../management/apps"; import { requireAuth } from "../requireAuth"; -import * as logger from "../logger"; +import { logger } from "../logger"; const NOT_SPECIFIED = clc.yellow("[Not specified]"); diff --git a/src/commands/apps-sdkconfig.ts b/src/commands/apps-sdkconfig.ts index 8d0ee1d8025..18bdd961f0b 100644 --- a/src/commands/apps-sdkconfig.ts +++ b/src/commands/apps-sdkconfig.ts @@ -15,7 +15,7 @@ import * as getProjectId from "../getProjectId"; import { getOrPromptProject } from "../management/projects"; import { FirebaseError } from "../error"; import { requireAuth } from "../requireAuth"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { promptOnce } from "../prompt"; async function selectAppInteractively( diff --git a/src/commands/auth-export.js b/src/commands/auth-export.js index cbcbd6a48f1..bec5f640b80 100644 --- a/src/commands/auth-export.js +++ b/src/commands/auth-export.js @@ -7,7 +7,7 @@ var os = require("os"); var { Command } = require("../command"); var accountExporter = require("../accountExporter"); var getProjectId = require("../getProjectId"); -var logger = require("../logger"); +const { logger } = require("../logger"); var { requirePermissions } = require("../requirePermissions"); var MAX_BATCH_SIZE = 1000; diff --git a/src/commands/auth-import.js b/src/commands/auth-import.js index c6c9499cd4d..bb5ef9dbede 100644 --- a/src/commands/auth-import.js +++ b/src/commands/auth-import.js @@ -9,7 +9,7 @@ var _ = require("lodash"); var { Command } = require("../command"); var accountImporter = require("../accountImporter"); var getProjectId = require("../getProjectId"); -var logger = require("../logger"); +const { logger } = require("../logger"); var { requirePermissions } = require("../requirePermissions"); var utils = require("../utils"); diff --git a/src/commands/database-get.ts b/src/commands/database-get.ts index 182c0b46a25..71e60e66397 100644 --- a/src/commands/database-get.ts +++ b/src/commands/database-get.ts @@ -9,7 +9,7 @@ import { populateInstanceDetails } from "../management/database"; import { printNoticeIfEmulated } from "../emulator/commandUtils"; import { realtimeOriginOrEmulatorOrCustomUrl } from "../database/api"; import { requirePermissions } from "../requirePermissions"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import * as responseToError from "../responseToError"; import * as utils from "../utils"; diff --git a/src/commands/database-instances-create.ts b/src/commands/database-instances-create.ts index 9dac6f353cb..bfb99922aed 100644 --- a/src/commands/database-instances-create.ts +++ b/src/commands/database-instances-create.ts @@ -1,5 +1,5 @@ import { Command } from "../command"; -import logger = require("../logger"); +import { logger } from "../logger"; import { requirePermissions } from "../requirePermissions"; import { warnEmulatorNotSupported } from "../emulator/commandUtils"; import { Emulators } from "../emulator/types"; diff --git a/src/commands/database-instances-list.ts b/src/commands/database-instances-list.ts index 43264a24c52..9354a12359b 100644 --- a/src/commands/database-instances-list.ts +++ b/src/commands/database-instances-list.ts @@ -3,7 +3,7 @@ import Table = require("cli-table"); import * as clc from "cli-color"; import * as ora from "ora"; -import logger = require("../logger"); +import { logger } from "../logger"; import { requirePermissions } from "../requirePermissions"; import { getProjectNumber } from "../getProjectNumber"; import firedata = require("../gcp/firedata"); diff --git a/src/commands/database-push.ts b/src/commands/database-push.ts index 20ee2df79ba..dc2e43dbc36 100644 --- a/src/commands/database-push.ts +++ b/src/commands/database-push.ts @@ -11,7 +11,7 @@ import { printNoticeIfEmulated } from "../emulator/commandUtils"; import { realtimeOriginOrEmulatorOrCustomUrl } from "../database/api"; import { requirePermissions } from "../requirePermissions"; import { URL } from "url"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import * as utils from "../utils"; diff --git a/src/commands/database-rules-get.ts b/src/commands/database-rules-get.ts index 21d92670cdd..a76401f7d10 100644 --- a/src/commands/database-rules-get.ts +++ b/src/commands/database-rules-get.ts @@ -1,5 +1,5 @@ import { Command } from "../command"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import { requirePermissions } from "../requirePermissions"; import * as metadata from "../database/metadata"; diff --git a/src/commands/database-rules-list.ts b/src/commands/database-rules-list.ts index 2e54c52d963..2c1fdacfd00 100644 --- a/src/commands/database-rules-list.ts +++ b/src/commands/database-rules-list.ts @@ -1,5 +1,5 @@ import { Command } from "../command"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import { requirePermissions } from "../requirePermissions"; import * as metadata from "../database/metadata"; diff --git a/src/commands/database-rules-stage.ts b/src/commands/database-rules-stage.ts index 7b66d4d7de7..c12428a964e 100644 --- a/src/commands/database-rules-stage.ts +++ b/src/commands/database-rules-stage.ts @@ -1,5 +1,5 @@ import { Command } from "../command"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import { requirePermissions } from "../requirePermissions"; import * as metadata from "../database/metadata"; diff --git a/src/commands/database-set.ts b/src/commands/database-set.ts index 3215c097755..2172bccb15b 100644 --- a/src/commands/database-set.ts +++ b/src/commands/database-set.ts @@ -12,7 +12,7 @@ import { promptOnce } from "../prompt"; import { realtimeOriginOrEmulatorOrCustomUrl } from "../database/api"; import { requirePermissions } from "../requirePermissions"; import { URL } from "url"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import * as utils from "../utils"; diff --git a/src/commands/database-update.ts b/src/commands/database-update.ts index f73cef8e194..4f79804f037 100644 --- a/src/commands/database-update.ts +++ b/src/commands/database-update.ts @@ -11,7 +11,7 @@ import { printNoticeIfEmulated } from "../emulator/commandUtils"; import { promptOnce } from "../prompt"; import { realtimeOriginOrEmulatorOrCustomUrl } from "../database/api"; import { requirePermissions } from "../requirePermissions"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; import * as utils from "../utils"; diff --git a/src/commands/emulators-start.ts b/src/commands/emulators-start.ts index 0dadda179c0..d22814493ef 100644 --- a/src/commands/emulators-start.ts +++ b/src/commands/emulators-start.ts @@ -1,7 +1,7 @@ import { Command } from "../command"; import * as controller from "../emulator/controller"; import * as commandUtils from "../emulator/commandUtils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { EmulatorRegistry } from "../emulator/registry"; import { Emulators, EMULATORS_SUPPORTED_BY_UI } from "../emulator/types"; import * as clc from "cli-color"; diff --git a/src/commands/ext-configure.ts b/src/commands/ext-configure.ts index 760b3342d8f..efb7ba28c86 100644 --- a/src/commands/ext-configure.ts +++ b/src/commands/ext-configure.ts @@ -13,7 +13,7 @@ import { logPrefix } from "../extensions/extensionsHelper"; import * as paramHelper from "../extensions/paramHelper"; import { requirePermissions } from "../requirePermissions"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; marked.setOptions({ renderer: new TerminalRenderer(), diff --git a/src/commands/ext-dev-init.ts b/src/commands/ext-dev-init.ts index da2615ede6b..6e42d050b70 100644 --- a/src/commands/ext-dev-init.ts +++ b/src/commands/ext-dev-init.ts @@ -8,7 +8,7 @@ import { Command } from "../command"; import * as Config from "../config"; import { FirebaseError } from "../error"; import { promptOnce } from "../prompt"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as npmDependencies from "../init/features/functions/npm-dependencies"; marked.setOptions({ renderer: new TerminalRenderer(), diff --git a/src/commands/ext-dev-list.ts b/src/commands/ext-dev-list.ts index 4fa0780b7cb..9697135e12f 100644 --- a/src/commands/ext-dev-list.ts +++ b/src/commands/ext-dev-list.ts @@ -8,7 +8,7 @@ import { FirebaseError } from "../error"; import * as utils from "../utils"; import * as extensionsUtils from "../extensions/utils"; import { listExtensions } from "../extensions/extensionsApi"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requireAuth } from "../requireAuth"; /** diff --git a/src/commands/ext-info.ts b/src/commands/ext-info.ts index e5d8c22b6c1..47c43aee114 100644 --- a/src/commands/ext-info.ts +++ b/src/commands/ext-info.ts @@ -7,7 +7,7 @@ import { resolveRegistryEntry, resolveSourceUrl } from "../extensions/resolveSou import * as extensionsApi from "../extensions/extensionsApi"; import { ensureExtensionsApiEnabled, logPrefix } from "../extensions/extensionsHelper"; import { isLocalExtension, getLocalExtensionSpec } from "../extensions/localHelper"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requirePermissions } from "../requirePermissions"; import * as utils from "../utils"; diff --git a/src/commands/ext-install.ts b/src/commands/ext-install.ts index 87f0cac58e8..65852dd84b0 100644 --- a/src/commands/ext-install.ts +++ b/src/commands/ext-install.ts @@ -34,7 +34,7 @@ import { import { getRandomString } from "../extensions/utils"; import { requirePermissions } from "../requirePermissions"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { promptOnce } from "../prompt"; import { previews } from "../previews"; diff --git a/src/commands/ext-sources-create.ts b/src/commands/ext-sources-create.ts index 47858ee4880..0a856ffbb91 100644 --- a/src/commands/ext-sources-create.ts +++ b/src/commands/ext-sources-create.ts @@ -1,7 +1,7 @@ import { checkMinRequiredVersion } from "../checkMinRequiredVersion"; import { Command } from "../command"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { createSourceFromLocation, ensureExtensionsApiEnabled, diff --git a/src/commands/ext-uninstall.ts b/src/commands/ext-uninstall.ts index 85143d98866..a8b4b7ae48c 100644 --- a/src/commands/ext-uninstall.ts +++ b/src/commands/ext-uninstall.ts @@ -17,7 +17,7 @@ import { import { promptOnce } from "../prompt"; import { requirePermissions } from "../requirePermissions"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; marked.setOptions({ renderer: new TerminalRenderer(), diff --git a/src/commands/ext.ts b/src/commands/ext.ts index 5dd7ca34e60..658a2eb27d0 100644 --- a/src/commands/ext.ts +++ b/src/commands/ext.ts @@ -7,7 +7,7 @@ import * as getProjectId from "../getProjectId"; import { logPrefix } from "../extensions/extensionsHelper"; import { listExtensions } from "../extensions/listExtensions"; import { requirePermissions } from "../requirePermissions"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; import { CommanderStatic } from "commander"; diff --git a/src/commands/firestore-indexes-list.ts b/src/commands/firestore-indexes-list.ts index 288d714316d..9d44c5b93c8 100644 --- a/src/commands/firestore-indexes-list.ts +++ b/src/commands/firestore-indexes-list.ts @@ -1,7 +1,7 @@ import { Command } from "../command"; import * as clc from "cli-color"; import * as fsi from "../firestore/indexes"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requirePermissions } from "../requirePermissions"; import { Emulators } from "../emulator/types"; import { warnEmulatorNotSupported } from "../emulator/commandUtils"; diff --git a/src/commands/functions-config-clone.js b/src/commands/functions-config-clone.js index 4e501224444..9c5b324a089 100644 --- a/src/commands/functions-config-clone.js +++ b/src/commands/functions-config-clone.js @@ -7,7 +7,7 @@ var functionsConfigClone = require("../functionsConfigClone"); var getProjectId = require("../getProjectId"); var { requirePermissions } = require("../requirePermissions"); var utils = require("../utils"); -var logger = require("../logger"); +const { logger } = require("../logger"); module.exports = new Command("functions:config:clone") .description("clone environment config from another project") diff --git a/src/commands/functions-config-get.js b/src/commands/functions-config-get.js index 8f11a27500c..d142024344b 100644 --- a/src/commands/functions-config-get.js +++ b/src/commands/functions-config-get.js @@ -3,7 +3,7 @@ var _ = require("lodash"); var { Command } = require("../command"); var getProjectId = require("../getProjectId"); -var logger = require("../logger"); +const { logger } = require("../logger"); var { requirePermissions } = require("../requirePermissions"); var functionsConfig = require("../functionsConfig"); diff --git a/src/commands/functions-config-legacy.js b/src/commands/functions-config-legacy.js index 860cae4c315..28a34a5a294 100644 --- a/src/commands/functions-config-legacy.js +++ b/src/commands/functions-config-legacy.js @@ -7,7 +7,7 @@ var getProjectId = require("../getProjectId"); var { requirePermissions } = require("../requirePermissions"); var runtimeconfig = require("../gcp/runtimeconfig"); var functionsConfig = require("../functionsConfig"); -var logger = require("../logger"); +const { logger } = require("../logger"); module.exports = new Command("functions:config:legacy") .description("get legacy functions config variables") diff --git a/src/commands/functions-config-set.js b/src/commands/functions-config-set.js index f6ce5d68c2c..55ee25f49e6 100644 --- a/src/commands/functions-config-set.js +++ b/src/commands/functions-config-set.js @@ -5,7 +5,7 @@ var clc = require("cli-color"); var { Command } = require("../command"); var getProjectId = require("../getProjectId"); var { requirePermissions } = require("../requirePermissions"); -var logger = require("../logger"); +const { logger } = require("../logger"); var utils = require("../utils"); var functionsConfig = require("../functionsConfig"); diff --git a/src/commands/functions-config-unset.js b/src/commands/functions-config-unset.js index 3fc37e9e941..0a74829dc44 100644 --- a/src/commands/functions-config-unset.js +++ b/src/commands/functions-config-unset.js @@ -6,7 +6,7 @@ var clc = require("cli-color"); var { Command } = require("../command"); var functionsConfig = require("../functionsConfig"); var getProjectId = require("../getProjectId"); -var logger = require("../logger"); +const { logger } = require("../logger"); var { requirePermissions } = require("../requirePermissions"); var utils = require("../utils"); var runtimeconfig = require("../gcp/runtimeconfig"); diff --git a/src/commands/functions-log.ts b/src/commands/functions-log.ts index 9d329492c33..b391af603a0 100644 --- a/src/commands/functions-log.ts +++ b/src/commands/functions-log.ts @@ -6,7 +6,7 @@ import { Command } from "../command"; import { FirebaseError } from "../error"; import * as gcp from "../gcp"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { requirePermissions } from "../requirePermissions"; module.exports = new Command("functions:log") diff --git a/src/commands/help.js b/src/commands/help.js index b7fe226803e..99d40201bcc 100644 --- a/src/commands/help.js +++ b/src/commands/help.js @@ -4,7 +4,7 @@ var { Command } = require("../command"); var clc = require("cli-color"); -var logger = require("../logger"); +const { logger } = require("../logger"); var utils = require("../utils"); module.exports = new Command("help [command]") diff --git a/src/commands/hosting-channel-create.ts b/src/commands/hosting-channel-create.ts index d495547b256..ac8be01b314 100644 --- a/src/commands/hosting-channel-create.ts +++ b/src/commands/hosting-channel-create.ts @@ -8,7 +8,7 @@ import { logLabeledSuccess, datetimeString, logLabeledWarning, consoleUrl } from import { promptOnce } from "../prompt"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as requireConfig from "../requireConfig"; import * as marked from "marked"; import { requireHostingSite } from "../requireHostingSite"; diff --git a/src/commands/hosting-channel-delete.ts b/src/commands/hosting-channel-delete.ts index bee3a27a046..c5fd319fb57 100644 --- a/src/commands/hosting-channel-delete.ts +++ b/src/commands/hosting-channel-delete.ts @@ -9,7 +9,7 @@ import { requireHostingSite } from "../requireHostingSite"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; import * as requireConfig from "../requireConfig"; -import logger from "../logger"; +import { logger } from "../logger"; export default new Command("hosting:channel:delete ") .description("delete a Firebase Hosting channel") diff --git a/src/commands/hosting-channel-deploy.ts b/src/commands/hosting-channel-deploy.ts index 99e5af9d514..cc90790478e 100644 --- a/src/commands/hosting-channel-deploy.ts +++ b/src/commands/hosting-channel-deploy.ts @@ -15,7 +15,7 @@ import { normalizedHostingConfigs } from "../hosting/normalizedHostingConfigs"; import { requirePermissions } from "../requirePermissions"; import * as deploy from "../deploy"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as requireConfig from "../requireConfig"; import { DEFAULT_DURATION, calculateChannelExpireTTL } from "../hosting/expireUtils"; import { logLabeledSuccess, datetimeString, logLabeledWarning, consoleUrl } from "../utils"; diff --git a/src/commands/hosting-channel-list.ts b/src/commands/hosting-channel-list.ts index a6616e58959..1a33205bdd8 100644 --- a/src/commands/hosting-channel-list.ts +++ b/src/commands/hosting-channel-list.ts @@ -5,7 +5,7 @@ import { Channel, listChannels } from "../hosting/api"; import { Command } from "../command"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as requireConfig from "../requireConfig"; import { datetimeString } from "../utils"; import { requireHostingSite } from "../requireHostingSite"; diff --git a/src/commands/hosting-clone.ts b/src/commands/hosting-clone.ts index 78a00ba1f7b..2bc4470453b 100644 --- a/src/commands/hosting-clone.ts +++ b/src/commands/hosting-clone.ts @@ -14,7 +14,7 @@ import { import * as utils from "../utils"; import { requireAuth } from "../requireAuth"; import * as marked from "marked"; -import * as logger from "../logger"; +import { logger } from "../logger"; export default new Command("hosting:clone ") .description("clone a version from one site to another") diff --git a/src/commands/hosting-sites-create.ts b/src/commands/hosting-sites-create.ts index df0e5d5394d..c27bb774395 100644 --- a/src/commands/hosting-sites-create.ts +++ b/src/commands/hosting-sites-create.ts @@ -7,7 +7,7 @@ import { promptOnce } from "../prompt"; import { FirebaseError } from "../error"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; const LOG_TAG = "hosting:sites"; diff --git a/src/commands/hosting-sites-delete.ts b/src/commands/hosting-sites-delete.ts index 039dbdcb72f..5ce352895ce 100644 --- a/src/commands/hosting-sites-delete.ts +++ b/src/commands/hosting-sites-delete.ts @@ -7,7 +7,7 @@ import { FirebaseError } from "../error"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; import * as requireConfig from "../requireConfig"; -import * as logger from "../logger"; +import { logger } from "../logger"; const LOG_TAG = "hosting:sites"; diff --git a/src/commands/hosting-sites-get.ts b/src/commands/hosting-sites-get.ts index 768af65ab69..7d6eb2409bf 100644 --- a/src/commands/hosting-sites-get.ts +++ b/src/commands/hosting-sites-get.ts @@ -4,7 +4,7 @@ import { Command } from "../command"; import { Site, getSite } from "../hosting/api"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { FirebaseError } from "../error"; export default new Command("hosting:sites:get ") diff --git a/src/commands/hosting-sites-list.ts b/src/commands/hosting-sites-list.ts index f3ce402e295..e3f65e25d6f 100644 --- a/src/commands/hosting-sites-list.ts +++ b/src/commands/hosting-sites-list.ts @@ -5,7 +5,7 @@ import { Command } from "../command"; import { Site, listSites } from "../hosting/api"; import { requirePermissions } from "../requirePermissions"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; const TABLE_HEAD = ["Site ID", "Default URL", "App ID (if set)"]; diff --git a/src/commands/init.js b/src/commands/init.js index 83ec5c8fcfd..772bcb1a863 100644 --- a/src/commands/init.js +++ b/src/commands/init.js @@ -9,7 +9,7 @@ var { Command } = require("../command"); var Config = require("../config"); var fsutils = require("../fsutils"); var { init } = require("../init"); -var logger = require("../logger"); +const { logger } = require("../logger"); var { prompt, promptOnce } = require("../prompt"); var { requireAuth } = require("../requireAuth"); var utils = require("../utils"); diff --git a/src/commands/login-ci.js b/src/commands/login-ci.js index fe6922ae44a..37f08f5c243 100644 --- a/src/commands/login-ci.js +++ b/src/commands/login-ci.js @@ -3,7 +3,7 @@ var { Command } = require("../command"); var clc = require("cli-color"); var utils = require("../utils"); -var logger = require("../logger"); +const { logger } = require("../logger"); var auth = require("../auth"); module.exports = new Command("login:ci") diff --git a/src/commands/login.ts b/src/commands/login.ts index c5d655b2243..2c0f13a1fdc 100644 --- a/src/commands/login.ts +++ b/src/commands/login.ts @@ -2,7 +2,7 @@ import * as _ from "lodash"; import * as clc from "cli-color"; import { Command } from "../command"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { configstore } from "../configstore"; import * as utils from "../utils"; import { FirebaseError } from "../error"; diff --git a/src/commands/logout.js b/src/commands/logout.js index 618717b4898..b81bb35d2aa 100644 --- a/src/commands/logout.js +++ b/src/commands/logout.js @@ -2,7 +2,7 @@ var { Command } = require("../command"); var { configstore } = require("../configstore"); -var logger = require("../logger"); +const { logger } = require("../logger"); var clc = require("cli-color"); var utils = require("../utils"); diff --git a/src/commands/open.ts b/src/commands/open.ts index 52197574c6a..db270f4596d 100644 --- a/src/commands/open.ts +++ b/src/commands/open.ts @@ -5,7 +5,7 @@ import * as open from "open"; import { FirebaseError } from "../error"; import * as api from "../api"; import { Command } from "../command"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { promptOnce } from "../prompt"; import { requirePermissions } from "../requirePermissions"; import { requireDatabaseInstance } from "../requireDatabaseInstance"; diff --git a/src/commands/projects-list.ts b/src/commands/projects-list.ts index 11610948a25..00dd55de670 100644 --- a/src/commands/projects-list.ts +++ b/src/commands/projects-list.ts @@ -5,7 +5,7 @@ import Table = require("cli-table"); import { Command } from "../command"; import { FirebaseProjectMetadata, listFirebaseProjects } from "../management/projects"; import { requireAuth } from "../requireAuth"; -import * as logger from "../logger"; +import { logger } from "../logger"; const NOT_SPECIFIED = clc.yellow("[Not specified]"); diff --git a/src/commands/remoteconfig-get.ts b/src/commands/remoteconfig-get.ts index 1bad4ce2d7e..baff2614054 100644 --- a/src/commands/remoteconfig-get.ts +++ b/src/commands/remoteconfig-get.ts @@ -1,7 +1,7 @@ import * as rcGet from "../remoteconfig/get"; import { Command } from "../command"; import { requireAuth } from "../requireAuth"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { RemoteConfigTemplate } from "../remoteconfig/interfaces"; import getProjectId = require("../getProjectId"); import { requirePermissions } from "../requirePermissions"; diff --git a/src/commands/remoteconfig-versions-list.ts b/src/commands/remoteconfig-versions-list.ts index bac59051dfa..d526ffc417c 100644 --- a/src/commands/remoteconfig-versions-list.ts +++ b/src/commands/remoteconfig-versions-list.ts @@ -1,4 +1,4 @@ -import * as logger from "../logger"; +import { logger } from "../logger"; import * as rcVersion from "../remoteconfig/versionslist"; import { Command } from "../command"; import getProjectId = require("../getProjectId"); diff --git a/src/commands/serve.js b/src/commands/serve.js index f0a31951112..e35be1aef7c 100644 --- a/src/commands/serve.js +++ b/src/commands/serve.js @@ -4,7 +4,7 @@ var clc = require("cli-color"); var _ = require("lodash"); var { Command } = require("../command"); -var logger = require("../logger"); +const { logger } = require("../logger"); var utils = require("../utils"); var { requirePermissions } = require("../requirePermissions"); var requireConfig = require("../requireConfig"); diff --git a/src/commands/target-apply.js b/src/commands/target-apply.js index 388d795e2e3..8171c57ce81 100644 --- a/src/commands/target-apply.js +++ b/src/commands/target-apply.js @@ -4,7 +4,7 @@ var _ = require("lodash"); var clc = require("cli-color"); var { Command } = require("../command"); -var logger = require("../logger"); +const { logger } = require("../logger"); var requireConfig = require("../requireConfig"); var utils = require("../utils"); diff --git a/src/commands/target.js b/src/commands/target.js index 38a4ceaf185..017eb2d026f 100644 --- a/src/commands/target.js +++ b/src/commands/target.js @@ -4,7 +4,7 @@ var _ = require("lodash"); var clc = require("cli-color"); var { Command } = require("../command"); -var logger = require("../logger"); +const { logger } = require("../logger"); var requireConfig = require("../requireConfig"); var utils = require("../utils"); diff --git a/src/commands/use.js b/src/commands/use.js index c3d43e012f3..08c75d83ba8 100644 --- a/src/commands/use.js +++ b/src/commands/use.js @@ -8,7 +8,7 @@ var { getFirebaseProject, listFirebaseProjects } = require("../management/projec var { prompt } = require("../prompt"); var { requireAuth } = require("../requireAuth"); var { validateProjectId } = require("../command"); -var logger = require("../logger"); +const { logger } = require("../logger"); var utils = require("../utils"); var listAliases = function (options) { diff --git a/src/database/listRemote.ts b/src/database/listRemote.ts index 9ddcfc4ece9..5075fc7e7dd 100644 --- a/src/database/listRemote.ts +++ b/src/database/listRemote.ts @@ -1,6 +1,6 @@ import { Client } from "../apiv2"; import { URL } from "url"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; export interface ListRemote { diff --git a/src/database/metadata.ts b/src/database/metadata.ts index 281d6c9ead8..24b0ed589d6 100644 --- a/src/database/metadata.ts +++ b/src/database/metadata.ts @@ -3,7 +3,7 @@ */ import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; function handleErrorResponse(response: any): Promise { diff --git a/src/database/removeRemote.ts b/src/database/removeRemote.ts index 33f07a43e04..2c655651e5c 100644 --- a/src/database/removeRemote.ts +++ b/src/database/removeRemote.ts @@ -1,6 +1,6 @@ import { Client } from "../apiv2"; import { URL } from "url"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; export interface RemoveRemote { diff --git a/src/database/rulesConfig.ts b/src/database/rulesConfig.ts index 9ccbde97099..b0edce82025 100644 --- a/src/database/rulesConfig.ts +++ b/src/database/rulesConfig.ts @@ -1,6 +1,6 @@ import { FirebaseError } from "../error"; import * as Config from "../config"; -import * as logger from "../logger"; +import { logger } from "../logger"; export interface RulesInstanceConfig { instance: string; diff --git a/src/defaultCredentials.ts b/src/defaultCredentials.ts index 641df897fe6..e0d97ccb21c 100644 --- a/src/defaultCredentials.ts +++ b/src/defaultCredentials.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as api from "./api"; import { configstore } from "./configstore"; -import * as logger from "./logger"; +import { logger } from "./logger"; // Interface for a valid JSON refresh token credential, so the // fields must be snake_case not camelCase. diff --git a/src/deploy/firestore/deploy.ts b/src/deploy/firestore/deploy.ts index e6639931341..c5d6c534d0d 100644 --- a/src/deploy/firestore/deploy.ts +++ b/src/deploy/firestore/deploy.ts @@ -3,7 +3,7 @@ import * as clc from "cli-color"; import { FirebaseError } from "../../error"; import { FirestoreIndexes } from "../../firestore/indexes"; -import logger = require("../../logger"); +import { logger } from "../../logger"; import utils = require("../../utils"); import { RulesDeploy, RulesetServiceType } from "../../rulesDeploy"; diff --git a/src/deploy/functions/checkIam.ts b/src/deploy/functions/checkIam.ts index f0e83575fbf..8b151ffa00b 100644 --- a/src/deploy/functions/checkIam.ts +++ b/src/deploy/functions/checkIam.ts @@ -1,7 +1,7 @@ import { has, last } from "lodash"; import { bold } from "cli-color"; -import { debug } from "../../logger"; +import { logger } from "../../logger"; import * as track from "../../track"; import { getReleaseNames, getFilterGroups } from "../../functionsDeployHelper"; import { CloudFunctionTrigger } from "./deploymentPlanner"; @@ -27,7 +27,7 @@ export async function checkServiceAccountIam(projectId: string): Promise { ); passed = iamResult.passed; } catch (err) { - debug("[functions] service account IAM check errored, deploy may fail:", err); + logger.debug("[functions] service account IAM check errored, deploy may fail:", err); // we want to fail this check open and not rethrow since it's informational only return; } @@ -71,7 +71,7 @@ export async function checkHttpIam(context: any, options: any, payload: any): Pr return; } - debug( + logger.debug( "[functions] found", newHttpFunctions.length, "new HTTP functions, testing setIamPolicy permission..." @@ -82,7 +82,10 @@ export async function checkHttpIam(context: any, options: any, payload: any): Pr const iamResult = await testIamPermissions(context.projectId, [PERMISSION]); passed = iamResult.passed; } catch (e) { - debug("[functions] failed http create setIamPolicy permission check. deploy may fail:", e); + logger.debug( + "[functions] failed http create setIamPolicy permission check. deploy may fail:", + e + ); // fail open since this is an informational check return; } @@ -99,5 +102,5 @@ export async function checkHttpIam(context: any, options: any, payload: any): Pr `\n\nTo address this error, please ask a project Owner to assign your account the "Cloud Functions Admin" role at the following URL:\n\nhttps://console.cloud.google.com/iam-admin/iam?project=${context.projectId}` ); } - debug("[functions] found setIamPolicy permission, proceeding with deploy"); + logger.debug("[functions] found setIamPolicy permission, proceeding with deploy"); } diff --git a/src/deploy/functions/deploymentTimer.ts b/src/deploy/functions/deploymentTimer.ts index f6c0aa5bd63..413f63c7b0e 100644 --- a/src/deploy/functions/deploymentTimer.ts +++ b/src/deploy/functions/deploymentTimer.ts @@ -1,4 +1,4 @@ -import * as logger from "../../logger"; +import { logger } from "../../logger"; import * as track from "../../track"; interface Timing { diff --git a/src/deploy/functions/errorHandler.ts b/src/deploy/functions/errorHandler.ts index 3e05970d535..52848e1f743 100644 --- a/src/deploy/functions/errorHandler.ts +++ b/src/deploy/functions/errorHandler.ts @@ -1,6 +1,6 @@ import * as clc from "cli-color"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import { getFunctionId, getFunctionLabel } from "../../functionsDeployHelper"; import { FirebaseError } from "../../error"; diff --git a/src/deploy/functions/prompts.ts b/src/deploy/functions/prompts.ts index ebb3c3f08fa..a11dd799d3d 100644 --- a/src/deploy/functions/prompts.ts +++ b/src/deploy/functions/prompts.ts @@ -6,7 +6,7 @@ import { FirebaseError } from "../../error"; import { promptOnce } from "../../prompt"; import * as gcp from "../../gcp"; import * as utils from "../../utils"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; /** * Checks if a deployment will create any functions with a failure policy. diff --git a/src/deploy/functions/tasks.ts b/src/deploy/functions/tasks.ts index 47b53a7ee40..01330adf524 100644 --- a/src/deploy/functions/tasks.ts +++ b/src/deploy/functions/tasks.ts @@ -1,6 +1,6 @@ import * as clc from "cli-color"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import * as utils from "../../utils"; import { CloudFunctionTrigger } from "./deploymentPlanner"; import { cloudfunctions, cloudscheduler } from "../../gcp"; diff --git a/src/deploy/functions/validate.ts b/src/deploy/functions/validate.ts index 21c9096b23f..2a2f880cfbe 100644 --- a/src/deploy/functions/validate.ts +++ b/src/deploy/functions/validate.ts @@ -2,7 +2,7 @@ import { FirebaseError } from "../../error"; import * as _ from "lodash"; import * as path from "path"; import * as clc from "cli-color"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import * as projectPath from "../../projectPath"; import * as fsutils from "../../fsutils"; import { RUNTIME_NOT_SET } from "../../parseRuntimeAndValidateSDK"; diff --git a/src/deploy/hosting/deploy.js b/src/deploy/hosting/deploy.js index 2adb8eda430..7b6a2cf82a3 100644 --- a/src/deploy/hosting/deploy.js +++ b/src/deploy/hosting/deploy.js @@ -3,7 +3,7 @@ const { Uploader } = require("./uploader"); const { detectProjectRoot } = require("../../detectProjectRoot"); var { listFiles } = require("../../listFiles"); -var logger = require("../../logger"); +const { logger } = require("../../logger"); var track = require("../../track"); var utils = require("../../utils"); diff --git a/src/deploy/hosting/hashcache.js b/src/deploy/hosting/hashcache.js index d5619d85c53..34d50ee607d 100644 --- a/src/deploy/hosting/hashcache.js +++ b/src/deploy/hosting/hashcache.js @@ -1,6 +1,6 @@ const fs = require("fs-extra"); const path = require("path"); -const logger = require("../../logger"); +const { logger } = require("../../logger"); function cachePath(cwd, name) { return path.resolve(cwd, ".firebase/hosting." + name + ".cache"); diff --git a/src/deploy/hosting/release.js b/src/deploy/hosting/release.js index ee734aeea18..76135e826f0 100644 --- a/src/deploy/hosting/release.js +++ b/src/deploy/hosting/release.js @@ -1,6 +1,6 @@ const api = require("../../api"); const utils = require("../../utils"); -const logger = require("../../logger"); +const { logger } = require("../../logger"); module.exports = function (context, options) { if (!context.hosting || !context.hosting.deploys) { diff --git a/src/deploy/hosting/uploader.ts b/src/deploy/hosting/uploader.ts index 504baa15b43..f18b7d5ef0e 100644 --- a/src/deploy/hosting/uploader.ts +++ b/src/deploy/hosting/uploader.ts @@ -10,7 +10,7 @@ import { Client } from "../../apiv2"; import { Queue } from "../../throttler/queue"; import { hostingApiOrigin } from "../../api"; import * as hashcache from "./hashcache"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import { FirebaseError } from "../../error"; const MIN_UPLOAD_TIMEOUT = 30000; // 30s diff --git a/src/deploy/index.js b/src/deploy/index.js index d2c851b2265..a170c438c03 100644 --- a/src/deploy/index.js +++ b/src/deploy/index.js @@ -1,6 +1,6 @@ "use strict"; -var logger = require("../logger"); +const { logger } = require("../logger"); var api = require("../api"); var clc = require("cli-color"); var _ = require("lodash"); diff --git a/src/deploy/lifecycleHooks.js b/src/deploy/lifecycleHooks.js index 9082946bf8d..13c376a916c 100644 --- a/src/deploy/lifecycleHooks.js +++ b/src/deploy/lifecycleHooks.js @@ -7,7 +7,7 @@ const clc = require("cli-color"); const childProcess = require("child_process"); const { FirebaseError } = require("../error"); const getProjectId = require("../getProjectId"); -const logger = require("../logger"); +const { logger } = require("../logger"); const path = require("path"); function runCommand(command, childOptions) { diff --git a/src/emulator/adminSdkConfig.ts b/src/emulator/adminSdkConfig.ts index aa605f45357..9c8e97a0798 100644 --- a/src/emulator/adminSdkConfig.ts +++ b/src/emulator/adminSdkConfig.ts @@ -2,7 +2,7 @@ import { firebaseApiOrigin } from "../api"; import * as apiv2 from "../apiv2"; import { configstore } from "../configstore"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; export type AdminSdkConfig = { projectId: string; diff --git a/src/emulator/commandUtils.ts b/src/emulator/commandUtils.ts index dc9f4c9041e..18f7e68fd8b 100644 --- a/src/emulator/commandUtils.ts +++ b/src/emulator/commandUtils.ts @@ -4,7 +4,7 @@ import * as childProcess from "child_process"; import * as controller from "../emulator/controller"; import * as Config from "../config"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as path from "path"; import { Constants } from "./constants"; import { requireAuth } from "../requireAuth"; diff --git a/src/emulator/controller.ts b/src/emulator/controller.ts index 9440f7d87e0..d791daed300 100644 --- a/src/emulator/controller.ts +++ b/src/emulator/controller.ts @@ -4,7 +4,7 @@ import * as fs from "fs"; import * as path from "path"; import * as Config from "../config"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as track from "../track"; import * as utils from "../utils"; import { EmulatorRegistry } from "./registry"; diff --git a/src/emulator/emulatorLogger.ts b/src/emulator/emulatorLogger.ts index 7f1fbb77fa4..3cb20c20599 100644 --- a/src/emulator/emulatorLogger.ts +++ b/src/emulator/emulatorLogger.ts @@ -1,7 +1,7 @@ import * as clc from "cli-color"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { EmulatorLog, Emulators } from "./types"; import { tryParse } from "../utils"; import { LogData } from "./loggingEmulator"; diff --git a/src/emulator/functionsEmulator.ts b/src/emulator/functionsEmulator.ts index 1c886400ef2..ffd0f317299 100644 --- a/src/emulator/functionsEmulator.ts +++ b/src/emulator/functionsEmulator.ts @@ -7,7 +7,7 @@ import * as http from "http"; import * as jwt from "jsonwebtoken"; import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as track from "../track"; import { Constants } from "./constants"; import { diff --git a/src/emulator/functionsEmulatorShell.ts b/src/emulator/functionsEmulatorShell.ts index ac2b2d5c15b..b1369d0c39e 100644 --- a/src/emulator/functionsEmulatorShell.ts +++ b/src/emulator/functionsEmulatorShell.ts @@ -6,7 +6,7 @@ import { getFunctionRegion, } from "./functionsEmulatorShared"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { FirebaseError } from "../error"; import { LegacyEvent } from "./events/types"; diff --git a/src/emulator/hub.ts b/src/emulator/hub.ts index 56cdbec5ae7..904c7373a2e 100644 --- a/src/emulator/hub.ts +++ b/src/emulator/hub.ts @@ -5,7 +5,7 @@ import * as path from "path"; import * as bodyParser from "body-parser"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { Constants } from "./constants"; import { Emulators, EmulatorInstance, EmulatorInfo } from "./types"; import { HubExport } from "./hubExport"; diff --git a/src/emulator/hubExport.ts b/src/emulator/hubExport.ts index dbbb1755fa3..7984fb728ac 100644 --- a/src/emulator/hubExport.ts +++ b/src/emulator/hubExport.ts @@ -3,7 +3,7 @@ import * as fs from "fs"; import * as http from "http"; import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { IMPORT_EXPORT_EMULATORS, Emulators, ALL_EMULATORS } from "./types"; import { EmulatorRegistry } from "./registry"; import { FirebaseError } from "../error"; diff --git a/src/emulator/loggingEmulator.ts b/src/emulator/loggingEmulator.ts index 4ffc31747fe..38d1666416e 100644 --- a/src/emulator/loggingEmulator.ts +++ b/src/emulator/loggingEmulator.ts @@ -2,8 +2,9 @@ import { EmulatorInfo, EmulatorInstance, Emulators } from "./types"; import { Constants } from "./constants"; import { SPLAT } from "triple-beam"; import * as WebSocket from "ws"; +import { LogEntry } from "winston"; import * as TransportStream from "winston-transport"; -import logger = require("../logger"); +import { logger } from "../logger"; const ansiStrip = require("cli-color/strip"); export interface LoggingEmulatorArgs { @@ -45,10 +46,11 @@ export class LoggingEmulator implements EmulatorInstance { return Promise.resolve(); } - stop(): Promise { - logger.remove(this.transport); - - return this.transport ? this.transport.stop() : Promise.resolve(); + async stop(): Promise { + if (this.transport) { + logger.remove(this.transport); + return this.transport.stop(); + } } getInfo(): EmulatorInfo { @@ -67,13 +69,6 @@ export class LoggingEmulator implements EmulatorInstance { } } -type LogEntry = { - level: string; - data: any; - timestamp: number; - message: string; -}; - class WebSocketTransport extends TransportStream { wss?: WebSocket.Server; connections = new Set(); diff --git a/src/emulator/portUtils.ts b/src/emulator/portUtils.ts index c4d0223691e..e9a6a6a6278 100644 --- a/src/emulator/portUtils.ts +++ b/src/emulator/portUtils.ts @@ -2,7 +2,7 @@ import * as pf from "portfinder"; import * as tcpport from "tcp-port-used"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; // See: // - https://stackoverflow.com/questions/4313403/why-do-browsers-block-some-ports diff --git a/src/extensions/askUserForParam.ts b/src/extensions/askUserForParam.ts index 41cabcfeb1e..57ad0ba9772 100644 --- a/src/extensions/askUserForParam.ts +++ b/src/extensions/askUserForParam.ts @@ -5,7 +5,7 @@ import * as marked from "marked"; import { Param, ParamOption, ParamType } from "./extensionsApi"; import { logPrefix, substituteParams } from "./extensionsHelper"; import { convertExtensionOptionToLabeledList, onceWithJoin } from "./utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { promptOnce } from "../prompt"; import * as utils from "../utils"; diff --git a/src/extensions/checkProjectBilling.js b/src/extensions/checkProjectBilling.js index 4662a1a1d6b..38d9030c09c 100644 --- a/src/extensions/checkProjectBilling.js +++ b/src/extensions/checkProjectBilling.js @@ -6,7 +6,7 @@ const opn = require("open"); const cloudbilling = require("../gcp/cloudbilling"); const { FirebaseError } = require("../error"); -const logger = require("../logger"); +const { logger } = require("../logger"); const extensionsHelper = require("./extensionsHelper"); const prompt = require("../prompt"); const utils = require("../utils"); diff --git a/src/extensions/displayExtensionInfo.ts b/src/extensions/displayExtensionInfo.ts index 3b58887acb1..cecf0c0b358 100644 --- a/src/extensions/displayExtensionInfo.ts +++ b/src/extensions/displayExtensionInfo.ts @@ -6,7 +6,7 @@ import TerminalRenderer = require("marked-terminal"); import * as extensionsApi from "./extensionsApi"; import * as utils from "../utils"; import { logPrefix } from "./extensionsHelper"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { FirebaseError } from "../error"; import { promptOnce } from "../prompt"; diff --git a/src/extensions/extensionsApi.ts b/src/extensions/extensionsApi.ts index f1edb2aa30e..b334434c1e6 100644 --- a/src/extensions/extensionsApi.ts +++ b/src/extensions/extensionsApi.ts @@ -4,7 +4,7 @@ import * as _ from "lodash"; import * as clc from "cli-color"; import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as operationPoller from "../operation-poller"; import { FirebaseError } from "../error"; diff --git a/src/extensions/extensionsHelper.ts b/src/extensions/extensionsHelper.ts index 1440b6b920d..cb9a0e659d1 100644 --- a/src/extensions/extensionsHelper.ts +++ b/src/extensions/extensionsHelper.ts @@ -28,7 +28,7 @@ import { } from "./extensionsApi"; import { getLocalExtensionSpec } from "./localHelper"; import { promptOnce } from "../prompt"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { envOverride } from "../utils"; /** diff --git a/src/extensions/listExtensions.ts b/src/extensions/listExtensions.ts index 7fce165165c..17fffc8f684 100644 --- a/src/extensions/listExtensions.ts +++ b/src/extensions/listExtensions.ts @@ -6,7 +6,7 @@ import { ExtensionInstance, listInstances } from "./extensionsApi"; import { logPrefix } from "./extensionsHelper"; import * as utils from "../utils"; import * as extensionsUtils from "./utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; /** * Lists the extensions installed under a project diff --git a/src/extensions/localHelper.ts b/src/extensions/localHelper.ts index 8210ccf7200..48a0f93bdef 100644 --- a/src/extensions/localHelper.ts +++ b/src/extensions/localHelper.ts @@ -5,7 +5,7 @@ import * as yaml from "js-yaml"; import { fileExistsSync } from "../fsutils"; import { FirebaseError } from "../error"; import { ExtensionSpec } from "./extensionsApi"; -import * as logger from "../logger"; +import { logger } from "../logger"; const EXTENSIONS_SPEC_FILE = "extension.yaml"; const EXTENSIONS_PREINSTALL_FILE = "PREINSTALL.md"; diff --git a/src/extensions/paramHelper.ts b/src/extensions/paramHelper.ts index dfc70b1e007..f63ab3d8bf0 100644 --- a/src/extensions/paramHelper.ts +++ b/src/extensions/paramHelper.ts @@ -5,7 +5,7 @@ import * as dotenv from "dotenv"; import * as fs from "fs-extra"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as extensionsApi from "./extensionsApi"; import { getFirebaseProjectParams, diff --git a/src/extensions/resolveSource.ts b/src/extensions/resolveSource.ts index 017a310d8a2..2d7ad345ae0 100644 --- a/src/extensions/resolveSource.ts +++ b/src/extensions/resolveSource.ts @@ -4,7 +4,7 @@ import * as marked from "marked"; import * as semver from "semver"; import * as api from "../api"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { promptOnce } from "../prompt"; const EXTENSIONS_REGISTRY_ENDPOINT = "/extensions.json"; diff --git a/src/extensions/updateHelper.ts b/src/extensions/updateHelper.ts index 22b94372443..7f9b44a317a 100644 --- a/src/extensions/updateHelper.ts +++ b/src/extensions/updateHelper.ts @@ -2,7 +2,7 @@ import * as clc from "cli-color"; import * as semver from "semver"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as resolveSource from "./resolveSource"; import * as extensionsApi from "./extensionsApi"; import { promptOnce } from "../prompt"; diff --git a/src/firestore/checkDatabaseType.ts b/src/firestore/checkDatabaseType.ts index 4eed29b916b..7fd8c666c5d 100644 --- a/src/firestore/checkDatabaseType.ts +++ b/src/firestore/checkDatabaseType.ts @@ -1,5 +1,5 @@ import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; /** * Determine the Firestore database type for a given project. One of: diff --git a/src/firestore/delete.ts b/src/firestore/delete.ts index 650296b9f7d..7915c8ff424 100644 --- a/src/firestore/delete.ts +++ b/src/firestore/delete.ts @@ -4,7 +4,7 @@ import * as ProgressBar from "progress"; import * as apiv2 from "../apiv2"; import * as firestore from "../gcp/firestore"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; import { firestoreOriginOrEmulator } from "../api"; diff --git a/src/firestore/indexes.ts b/src/firestore/indexes.ts index 7a60962dcae..9068391aa1c 100644 --- a/src/firestore/indexes.ts +++ b/src/firestore/indexes.ts @@ -1,7 +1,7 @@ import * as clc from "cli-color"; import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; import * as validator from "./validator"; diff --git a/src/functionsDeployHelper.ts b/src/functionsDeployHelper.ts index 72b2b66e11e..b0b8f73617b 100644 --- a/src/functionsDeployHelper.ts +++ b/src/functionsDeployHelper.ts @@ -2,7 +2,7 @@ import * as _ from "lodash"; import * as clc from "cli-color"; import { FirebaseError } from "./error"; -import * as logger from "./logger"; +import { logger } from "./logger"; import * as track from "./track"; import * as utils from "./utils"; import * as cloudfunctions from "./gcp/cloudfunctions"; diff --git a/src/functionsShellCommandAction.js b/src/functionsShellCommandAction.js index f9113ad251e..691788c7b35 100644 --- a/src/functionsShellCommandAction.js +++ b/src/functionsShellCommandAction.js @@ -12,7 +12,7 @@ var util = require("util"); var { FunctionsServer } = require("./serve/functions"); var LocalFunction = require("./localFunction"); var utils = require("./utils"); -var logger = require("./logger"); +const { logger } = require("./logger"); var shell = require("./emulator/functionsEmulatorShell"); var commandUtils = require("./emulator/commandUtils"); var { EMULATORS_SUPPORTED_BY_FUNCTIONS } = require("./emulator/types"); diff --git a/src/gcp/cloudfunctions.ts b/src/gcp/cloudfunctions.ts index ab84b988c6f..a09dcac5085 100644 --- a/src/gcp/cloudfunctions.ts +++ b/src/gcp/cloudfunctions.ts @@ -3,7 +3,7 @@ import * as clc from "cli-color"; import * as api from "../api"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; import { CloudFunctionTrigger } from "../deploy/functions/deploymentPlanner"; diff --git a/src/gcp/firedata.ts b/src/gcp/firedata.ts index d5dff48a58e..9ab727a1888 100644 --- a/src/gcp/firedata.ts +++ b/src/gcp/firedata.ts @@ -1,5 +1,5 @@ import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; export interface DatabaseInstance { diff --git a/src/gcp/iam.ts b/src/gcp/iam.ts index 4b3677b4e2b..7ea41492ee7 100644 --- a/src/gcp/iam.ts +++ b/src/gcp/iam.ts @@ -1,7 +1,7 @@ import * as api from "../api"; import { endpoint } from "../utils"; import { difference } from "lodash"; -import { debug } from "../logger"; +import { logger } from "../logger"; const API_VERSION = "v1"; @@ -172,7 +172,7 @@ export async function testResourceIamPermissions( permissions: string[] ): Promise { if (process.env.FIREBASE_SKIP_INFORMATIONAL_IAM) { - debug( + logger.debug( "[iam] skipping informational check of permissions", JSON.stringify(permissions), "on resource", diff --git a/src/gcp/rules.ts b/src/gcp/rules.ts index 6dc9597d5ca..0a2bf466385 100644 --- a/src/gcp/rules.ts +++ b/src/gcp/rules.ts @@ -1,7 +1,7 @@ import * as _ from "lodash"; import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; const API_VERSION = "v1"; diff --git a/src/gcp/runtimeconfig.js b/src/gcp/runtimeconfig.js index 89f51e94bec..c3c1a538d0e 100644 --- a/src/gcp/runtimeconfig.js +++ b/src/gcp/runtimeconfig.js @@ -3,7 +3,7 @@ var api = require("../api"); var utils = require("../utils"); -var logger = require("../logger"); +const { logger } = require("../logger"); var _ = require("lodash"); var API_VERSION = "v1beta1"; diff --git a/src/gcp/storage.js b/src/gcp/storage.js index cb6d4388908..1d526a83c4e 100644 --- a/src/gcp/storage.js +++ b/src/gcp/storage.js @@ -2,7 +2,7 @@ var path = require("path"); var api = require("../api"); -var logger = require("../logger"); +const { logger } = require("../logger"); var { FirebaseError } = require("../error"); function _getDefaultBucket(projectId) { diff --git a/src/getDefaultHostingSite.ts b/src/getDefaultHostingSite.ts index efb2263e4d6..aa931c0e029 100644 --- a/src/getDefaultHostingSite.ts +++ b/src/getDefaultHostingSite.ts @@ -1,4 +1,4 @@ -import * as logger from "./logger"; +import { logger } from "./logger"; import { getFirebaseProject } from "./management/projects"; /** diff --git a/src/hosting/cloudRunProxy.ts b/src/hosting/cloudRunProxy.ts index c2fe282b7f1..8a3b2e1f50c 100644 --- a/src/hosting/cloudRunProxy.ts +++ b/src/hosting/cloudRunProxy.ts @@ -3,7 +3,7 @@ import { get } from "lodash"; import { errorRequestHandler, proxyRequestHandler } from "./proxy"; import * as getProjectId from "../getProjectId"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { cloudRunApiOrigin, request as apiRequest } from "../api"; export interface CloudRunProxyOptions { diff --git a/src/hosting/implicitInit.ts b/src/hosting/implicitInit.ts index b6b612b729c..242cbac4304 100644 --- a/src/hosting/implicitInit.ts +++ b/src/hosting/implicitInit.ts @@ -4,7 +4,7 @@ import * as fs from "fs"; import { fetchWebSetup, getCachedWebSetup } from "../fetchWebSetup"; import * as utils from "../utils"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { EmulatorRegistry } from "../emulator/registry"; import { EMULATORS_SUPPORTED_BY_USE_EMULATOR, Address, Emulators } from "../emulator/types"; diff --git a/src/hosting/initMiddleware.ts b/src/hosting/initMiddleware.ts index cd49983201d..b70a3cf1bec 100644 --- a/src/hosting/initMiddleware.ts +++ b/src/hosting/initMiddleware.ts @@ -4,7 +4,7 @@ import { RequestHandler } from "express"; import { Client } from "../apiv2"; import { TemplateServerResponse } from "./implicitInit"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; const SDK_PATH_REGEXP = /^\/__\/firebase\/([^/]+)\/([^/]+)$/; diff --git a/src/hosting/proxy.ts b/src/hosting/proxy.ts index 494dc2f71e2..eeedfce5750 100644 --- a/src/hosting/proxy.ts +++ b/src/hosting/proxy.ts @@ -7,7 +7,7 @@ import { URL } from "url"; import { Client, HttpMethod } from "../apiv2"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; const REQUIRED_VARY_VALUES = ["Accept-Encoding", "Authorization", "Cookie"]; diff --git a/src/index.js b/src/index.js index 1a615f2cb93..0c8c52f0713 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ var program = require("commander"); var pkg = require("../package.json"); var clc = require("cli-color"); -var logger = require("./logger"); +const { logger } = require("./logger"); var { setupLoggers } = require("./utils"); var leven = require("leven"); diff --git a/src/init/features/database.ts b/src/init/features/database.ts index 8efc167d56d..1cf72685fb4 100644 --- a/src/init/features/database.ts +++ b/src/init/features/database.ts @@ -1,7 +1,7 @@ import * as clc from "cli-color"; import * as api from "../../api"; import { prompt, promptOnce } from "../../prompt"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import * as utils from "../../utils"; import * as fsutils from "../../fsutils"; import Config = require("../../config"); diff --git a/src/init/features/firestore/index.ts b/src/init/features/firestore/index.ts index 269e4ab4fc1..6838f0fb7e4 100644 --- a/src/init/features/firestore/index.ts +++ b/src/init/features/firestore/index.ts @@ -1,4 +1,4 @@ -import * as logger from "../../../logger"; +import { logger } from "../../../logger"; import * as apiEnabled from "../../../ensureApiEnabled"; import { ensureLocationSet } from "../../../ensureCloudResourceLocation"; import { requirePermissions } from "../../../requirePermissions"; diff --git a/src/init/features/firestore/indexes.ts b/src/init/features/firestore/indexes.ts index a28a412aed2..029a946d9cb 100644 --- a/src/init/features/firestore/indexes.ts +++ b/src/init/features/firestore/indexes.ts @@ -5,7 +5,7 @@ import { FirebaseError } from "../../../error"; import iv2 = require("../../../firestore/indexes"); import fsutils = require("../../../fsutils"); import { prompt, promptOnce } from "../../../prompt"; -import logger = require("../../../logger"); +import { logger } from "../../../logger"; const indexes = new iv2.FirestoreIndexes(); diff --git a/src/init/features/firestore/rules.ts b/src/init/features/firestore/rules.ts index af021b7c508..2824025d6e8 100644 --- a/src/init/features/firestore/rules.ts +++ b/src/init/features/firestore/rules.ts @@ -4,7 +4,7 @@ import fs = require("fs"); import gcp = require("../../../gcp"); import fsutils = require("../../../fsutils"); import { prompt, promptOnce } from "../../../prompt"; -import logger = require("../../../logger"); +import { logger } from "../../../logger"; import utils = require("../../../utils"); const DEFAULT_RULES_FILE = "firestore.rules"; diff --git a/src/init/features/functions/index.js b/src/init/features/functions/index.js index 7978bf695b9..254dc2cf6e9 100644 --- a/src/init/features/functions/index.js +++ b/src/init/features/functions/index.js @@ -4,7 +4,7 @@ var clc = require("cli-color"); var _ = require("lodash"); -var logger = require("../../../logger"); +const { logger } = require("../../../logger"); var { prompt } = require("../../../prompt"); var enableApi = require("../../../ensureApiEnabled").enable; var { requirePermissions } = require("../../../requirePermissions"); diff --git a/src/init/features/functions/npm-dependencies.js b/src/init/features/functions/npm-dependencies.js index 373c9d1b26b..e8c9588bccf 100644 --- a/src/init/features/functions/npm-dependencies.js +++ b/src/init/features/functions/npm-dependencies.js @@ -2,7 +2,7 @@ var spawn = require("cross-spawn"); -var logger = require("../../../logger"); +const { logger } = require("../../../logger"); var { prompt } = require("../../../prompt"); exports.askInstallDependencies = function (setup, config) { diff --git a/src/init/features/hosting/github.ts b/src/init/features/hosting/github.ts index 4b42798951c..e1ac3e115c3 100644 --- a/src/init/features/hosting/github.ts +++ b/src/init/features/hosting/github.ts @@ -15,7 +15,7 @@ import { deleteServiceAccount, } from "../../../gcp/iam"; import { addServiceAccountToRoles, firebaseRoles } from "../../../gcp/resourceManager"; -import * as logger from "../../../logger"; +import { logger } from "../../../logger"; import { prompt } from "../../../prompt"; import { logBullet, logLabeledBullet, logSuccess, reject } from "../../../utils"; import { githubApiOrigin, githubClientId } from "../../../api"; diff --git a/src/init/features/hosting/index.js b/src/init/features/hosting/index.js index b98516ab92b..cf6243a7469 100644 --- a/src/init/features/hosting/index.js +++ b/src/init/features/hosting/index.js @@ -6,7 +6,7 @@ const fs = require("fs"); const { Client } = require("../../../apiv2"); const { initGitHub } = require("./github"); const { prompt } = require("../../../prompt"); -const logger = require("../../../logger"); +const { logger } = require("../../../logger"); const INDEX_TEMPLATE = fs.readFileSync( __dirname + "/../../../../templates/init/hosting/index.html", diff --git a/src/init/features/project.ts b/src/init/features/project.ts index d26cbc8b2b0..7587575462c 100644 --- a/src/init/features/project.ts +++ b/src/init/features/project.ts @@ -11,7 +11,7 @@ import { PROJECTS_CREATE_QUESTIONS, promptAvailableProjectId, } from "../../management/projects"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import { prompt, promptOnce } from "../../prompt"; import * as utils from "../../utils"; diff --git a/src/init/features/storage.ts b/src/init/features/storage.ts index e9c5914f83f..096e8f9d984 100644 --- a/src/init/features/storage.ts +++ b/src/init/features/storage.ts @@ -1,7 +1,7 @@ import * as clc from "cli-color"; import * as fs from "fs"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import { promptOnce } from "../../prompt"; import { ensureLocationSet } from "../../ensureCloudResourceLocation"; diff --git a/src/init/index.ts b/src/init/index.ts index 8bffe1fedf0..08ae3a9a329 100644 --- a/src/init/index.ts +++ b/src/init/index.ts @@ -1,6 +1,6 @@ import * as _ from "lodash"; import * as clc from "cli-color"; -import logger = require("../logger"); +import { logger } from "../logger"; import * as _features from "./features"; import * as utils from "../utils"; diff --git a/src/logError.js b/src/logError.js index 2365bb4cff9..9cf538dd299 100644 --- a/src/logError.js +++ b/src/logError.js @@ -1,6 +1,6 @@ "use strict"; -var logger = require("./logger"); +const { logger } = require("./logger"); var clc = require("cli-color"); /* istanbul ignore next */ diff --git a/src/logger.js b/src/logger.js deleted file mode 100644 index 0c7f5825c60..00000000000 --- a/src/logger.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; - -const winston = require("winston"); - -function expandErrors(logger) { - const oldLogFunc = logger.log; - logger.log = function (...logArgs) { - const args = logArgs.slice(0); - if (args.length >= 2 && args[1] instanceof Error) { - args[1] = args[1].stack; - } - return oldLogFunc.apply(this, args); - }; - return logger; -} - -const logger = expandErrors(winston.createLogger()); - -// Set a default silent logger to suppress logs during tests -logger.add(new winston.transports.Console({ silent: true })); - -const debug = logger.debug; -logger.debug = function (...args) { - args[0] = "[" + new Date().toISOString() + "] " + (args[0] || ""); - debug(...args); -}; - -logger.exitOnError = false; -module.exports = logger; diff --git a/src/logger.ts b/src/logger.ts new file mode 100644 index 00000000000..96ef299e4b4 --- /dev/null +++ b/src/logger.ts @@ -0,0 +1,94 @@ +import * as winston from "winston"; +import * as Transport from "winston-transport"; + +export type LogLevel = + | "error" + | "warn" + | "help" + | "data" + | "info" + | "debug" + | "prompt" + | "http" + | "verbose" + | "input" + | "silly"; + +// Extend the Winston log methods to support error signatures +export interface LogMethod extends winston.LogMethod { + (level: LogLevel, err: Error, ...meta: any[]): Logger; +} + +export interface LeveledLogMessage extends winston.LeveledLogMethod { + // We use empty log messages to create newlines + (): Logger; + + // We transform Errors to strings dynamically + (err: Error, ...meta: any[]): Logger; +} + +export interface Logger { + log: LogMethod; + + error: LeveledLogMessage; + warn: LeveledLogMessage; + help: LeveledLogMessage; + data: LeveledLogMessage; + info: LeveledLogMessage; + debug: LeveledLogMessage; + prompt: LeveledLogMessage; + http: LeveledLogMessage; + verbose: LeveledLogMessage; + input: LeveledLogMessage; + silly: LeveledLogMessage; + + add(transport: Transport): Logger; + remove(transport: Transport): Logger; +} + +function expandErrors(logger: winston.Logger): winston.Logger { + const oldLogFunc: winston.LogMethod = logger.log.bind(logger); + const newLogFunc: winston.LogMethod = function ( + levelOrEntry: string | winston.LogEntry, + message?: string | Error, + ...meta: any[] + ): winston.Logger { + if (message && message instanceof Error) { + message = message.stack || message.message; + return oldLogFunc(levelOrEntry as string, message, ...meta); + } + // Overloads are weird in TypeScript. This method works so long as the original + // function isn't checking arguments.length. + return oldLogFunc(levelOrEntry as string, message as string, ...meta); + }; + logger.log = newLogFunc; + return logger; +} + +function annotateDebugLines(logger: winston.Logger): winston.Logger { + const debug: winston.LeveledLogMethod = logger.debug.bind(logger); + const newDebug: winston.LeveledLogMethod = function ( + message: string | any, + ...meta: any[] + ): winston.Logger { + if (typeof message === "string") { + message = `[${new Date().toISOString()}] ${message || ""}`; + } + return debug(message, ...meta); + }; + logger.debug = newDebug; + return logger; +} + +const rawLogger = winston.createLogger(); +// Set a default silent logger to suppress logs during tests +rawLogger.add(new winston.transports.Console({ silent: true })); +rawLogger.exitOnError = false; + +// The type system for TypeScript is a bit wonky. The type of winston.LeveledLogMessage +// and winston.LogMessage is an interface of function overloads. There's no easy way to +// extend that and also subclass Logger to change the return type of those methods to +// allow error parameters. +// Casting looks super dodgy, but it should be safe because we know the underlying code +// handles all parameter types we care about. +export const logger = (annotateDebugLines(expandErrors(rawLogger)) as unknown) as Logger; diff --git a/src/management/apps.ts b/src/management/apps.ts index e8646266290..5c43f98cea8 100644 --- a/src/management/apps.ts +++ b/src/management/apps.ts @@ -2,7 +2,7 @@ import * as fs from "fs"; import * as api from "../api"; import { FirebaseError } from "../error"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { pollOperation } from "../operation-poller"; const TIMEOUT_MILLIS = 30000; diff --git a/src/management/database.ts b/src/management/database.ts index 812b446498f..509be437d45 100644 --- a/src/management/database.ts +++ b/src/management/database.ts @@ -4,7 +4,7 @@ */ import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; import { FirebaseError } from "../error"; import { Constants } from "../emulator/constants"; diff --git a/src/management/projects.ts b/src/management/projects.ts index 02dae023992..20a6ec32d69 100644 --- a/src/management/projects.ts +++ b/src/management/projects.ts @@ -8,7 +8,7 @@ import { pollOperation } from "../operation-poller"; import { promptOnce } from "../prompt"; import { Question } from "inquirer"; import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import * as utils from "../utils"; const TIMEOUT_MILLIS = 30000; diff --git a/src/parseRuntimeAndValidateSDK.ts b/src/parseRuntimeAndValidateSDK.ts index 805a5dc3eb5..7be80c470d6 100644 --- a/src/parseRuntimeAndValidateSDK.ts +++ b/src/parseRuntimeAndValidateSDK.ts @@ -6,7 +6,7 @@ import * as semver from "semver"; import { getFunctionsSDKVersion } from "./checkFirebaseSDKVersion"; import { FirebaseError } from "./error"; import * as utils from "./utils"; -import * as logger from "./logger"; +import { logger } from "./logger"; import * as track from "./track"; // have to require this because no @types/cjson available diff --git a/src/prepareFunctionsUpload.ts b/src/prepareFunctionsUpload.ts index 06a01b52a95..ee5ed51dabd 100644 --- a/src/prepareFunctionsUpload.ts +++ b/src/prepareFunctionsUpload.ts @@ -9,7 +9,7 @@ import * as tmp from "tmp"; import { FirebaseError } from "./error"; import * as functionsConfig from "./functionsConfig"; import * as getProjectId from "./getProjectId"; -import * as logger from "./logger"; +import { logger } from "./logger"; import * as utils from "./utils"; import * as parseTriggers from "./parseTriggers"; import * as fsAsync from "./fsAsync"; diff --git a/src/profileReport.js b/src/profileReport.js index f6bb32af215..edfa2e78da2 100644 --- a/src/profileReport.js +++ b/src/profileReport.js @@ -8,7 +8,7 @@ var _ = require("lodash"); var readline = require("readline"); var { FirebaseError } = require("./error"); -var logger = require("./logger"); +const { logger } = require("./logger"); var DATA_LINE_REGEX = /^data: /; diff --git a/src/profiler.ts b/src/profiler.ts index 7d7e87e6c17..8bad6b1efae 100644 --- a/src/profiler.ts +++ b/src/profiler.ts @@ -6,7 +6,7 @@ import AbortController from "abort-controller"; import { Client } from "./apiv2"; import { realtimeOriginOrEmulatorOrCustomUrl } from "./database/api"; -import * as logger from "./logger"; +import { logger } from "./logger"; import * as ProfileReport from "./profileReport"; import * as responseToError from "./responseToError"; import * as utils from "./utils"; diff --git a/src/remoteconfig/get.ts b/src/remoteconfig/get.ts index 4853bda53b8..eee4334a807 100644 --- a/src/remoteconfig/get.ts +++ b/src/remoteconfig/get.ts @@ -1,5 +1,5 @@ import * as api from "../api"; -import * as logger from "../logger"; +import { logger } from "../logger"; import { FirebaseError } from "../error"; import { RemoteConfigTemplate } from "./interfaces"; diff --git a/src/remoteconfig/versionslist.ts b/src/remoteconfig/versionslist.ts index ce9deaf69ad..9f58b8baf0f 100644 --- a/src/remoteconfig/versionslist.ts +++ b/src/remoteconfig/versionslist.ts @@ -1,7 +1,7 @@ import api = require("../api"); import { FirebaseError } from "../error"; import { ListVersionsResult } from "./interfaces"; -import * as logger from "../logger"; +import { logger } from "../logger"; const TIMEOUT = 30000; diff --git a/src/requireAuth.ts b/src/requireAuth.ts index 2b407b61bb1..cf83711a1dd 100644 --- a/src/requireAuth.ts +++ b/src/requireAuth.ts @@ -5,7 +5,7 @@ import * as api from "./api"; import * as apiv2 from "./apiv2"; import { configstore } from "./configstore"; import { FirebaseError } from "./error"; -import * as logger from "./logger"; +import { logger } from "./logger"; import * as utils from "./utils"; import * as scopes from "./scopes"; diff --git a/src/requirePermissions.ts b/src/requirePermissions.ts index 8bbd3a08b7f..329a28ea041 100644 --- a/src/requirePermissions.ts +++ b/src/requirePermissions.ts @@ -1,7 +1,7 @@ import { bold } from "cli-color"; import getProjectId = require("./getProjectId"); import { requireAuth } from "./requireAuth"; -import { debug } from "./logger"; +import { logger } from "./logger"; import { FirebaseError } from "./error"; import { testIamPermissions } from "./gcp/iam"; @@ -21,7 +21,7 @@ export async function requirePermissions(options: any, permissions: string[] = [ await requireAuth(options); - debug( + logger.debug( `[iam] checking project ${projectId} for permissions ${JSON.stringify(requiredPermissions)}` ); @@ -35,7 +35,7 @@ export async function requirePermissions(options: any, permissions: string[] = [ ); } } catch (err) { - debug(`[iam] error while checking permissions, command may fail: ${err}`); + logger.debug(`[iam] error while checking permissions, command may fail: ${err}`); return; } } diff --git a/src/rulesDeploy.ts b/src/rulesDeploy.ts index 5cd30ad01eb..bbf85d664c5 100644 --- a/src/rulesDeploy.ts +++ b/src/rulesDeploy.ts @@ -3,7 +3,7 @@ import clc = require("cli-color"); import fs = require("fs"); import gcp = require("./gcp"); -import logger = require("./logger"); +import { logger } from "./logger"; import { FirebaseError } from "./error"; import utils = require("./utils"); diff --git a/src/serve/index.ts b/src/serve/index.ts index 3e7bb68fb1e..79699a80bb9 100644 --- a/src/serve/index.ts +++ b/src/serve/index.ts @@ -1,6 +1,6 @@ import { EmulatorServer } from "../emulator/emulatorServer"; import * as _ from "lodash"; -import * as logger from "../logger"; +import { logger } from "../logger"; const { FunctionsServer } = require("./functions"); diff --git a/src/test/deploy/functions/checkRuntimeDependencies.spec.ts b/src/test/deploy/functions/checkRuntimeDependencies.spec.ts index 27deda54577..6789ce348b2 100644 --- a/src/test/deploy/functions/checkRuntimeDependencies.spec.ts +++ b/src/test/deploy/functions/checkRuntimeDependencies.spec.ts @@ -2,7 +2,7 @@ import * as sinon from "sinon"; import * as nock from "nock"; import { expect } from "chai"; -import * as logger from "../../../logger"; +import { logger } from "../../../logger"; import { configstore } from "../../../configstore"; import * as api from "../../../api"; import { checkRuntimeDependencies } from "../../../deploy/functions/checkRuntimeDependencies"; diff --git a/src/test/extensions/paramHelper.spec.ts b/src/test/extensions/paramHelper.spec.ts index afb38bd4a0a..532b92b9f90 100644 --- a/src/test/extensions/paramHelper.spec.ts +++ b/src/test/extensions/paramHelper.spec.ts @@ -5,7 +5,7 @@ import * as dotenv from "dotenv"; import * as fs from "fs-extra"; import { FirebaseError } from "../../error"; -import * as logger from "../../logger"; +import { logger } from "../../logger"; import { ExtensionInstance, Param, ParamType } from "../../extensions/extensionsApi"; import * as extensionsHelper from "../../extensions/extensionsHelper"; import * as paramHelper from "../../extensions/paramHelper"; diff --git a/src/throttler/throttler.ts b/src/throttler/throttler.ts index c42e408b491..2253a0b4de2 100644 --- a/src/throttler/throttler.ts +++ b/src/throttler/throttler.ts @@ -1,4 +1,4 @@ -import * as logger from "../logger"; +import { logger } from "../logger"; import RetriesExhaustedError from "./errors/retries-exhausted-error"; import TimeoutError from "./errors/timeout-error"; import TaskError from "./errors/task-error"; diff --git a/src/track.js b/src/track.js index 0536c40c4fa..7f9bb9bd532 100644 --- a/src/track.js +++ b/src/track.js @@ -6,7 +6,7 @@ var _ = require("lodash"); var { configstore } = require("./configstore"); var pkg = require("../package.json"); var uuid = require("uuid"); -var logger = require("./logger"); +const { logger } = require("./logger"); var anonId = configstore.get("analytics-uuid"); if (!anonId) { diff --git a/src/utils.ts b/src/utils.ts index 505854c7731..9cdb941d189 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,7 +11,7 @@ const ansiStrip = require("cli-color/strip") as (input: string) => string; import { configstore } from "./configstore"; import { FirebaseError } from "./error"; -import * as logger from "./logger"; +import { logger, LogLevel } from "./logger"; import { LogDataOrUndefined } from "./emulator/loggingEmulator"; import { Socket } from "net"; @@ -126,7 +126,7 @@ export function addSubdomain(origin: string, subdomain: string): string { */ export function logSuccess( message: string, - type = "info", + type: LogLevel = "info", data: LogDataOrUndefined = undefined ): void { logger[type](clc.green.bold(`${SUCCESS_CHAR} `), message, data); @@ -138,7 +138,7 @@ export function logSuccess( export function logLabeledSuccess( label: string, message: string, - type = "info", + type: LogLevel = "info", data: LogDataOrUndefined = undefined ): void { logger[type](clc.green.bold(`${SUCCESS_CHAR} ${label}:`), message, data); @@ -149,7 +149,7 @@ export function logLabeledSuccess( */ export function logBullet( message: string, - type = "info", + type: LogLevel = "info", data: LogDataOrUndefined = undefined ): void { logger[type](clc.cyan.bold("i "), message, data); @@ -161,7 +161,7 @@ export function logBullet( export function logLabeledBullet( label: string, message: string, - type = "info", + type: LogLevel = "info", data: LogDataOrUndefined = undefined ): void { logger[type](clc.cyan.bold(`i ${label}:`), message, data); @@ -172,7 +172,7 @@ export function logLabeledBullet( */ export function logWarning( message: string, - type = "warn", + type: LogLevel = "warn", data: LogDataOrUndefined = undefined ): void { logger[type](clc.yellow.bold(`${WARNING_CHAR} `), message, data); @@ -184,7 +184,7 @@ export function logWarning( export function logLabeledWarning( label: string, message: string, - type = "warn", + type: LogLevel = "warn", data: LogDataOrUndefined = undefined ): void { logger[type](clc.yellow.bold(`${WARNING_CHAR} ${label}:`), message, data);