From 76aaaafa6e7427eebcb9c74f51f09bbd164fe6a7 Mon Sep 17 00:00:00 2001 From: Jeffrey Lau <34088613+jlauzy@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:29:49 -0700 Subject: [PATCH] Add more configuration options for MobileReleaseLogger (#754) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: - Just adding more configurations options. Issue: XXX-XXXX ## Test plan: Author: jlauzy Reviewers: jeresig, somewhatabstract Required Reviewers: Approved By: jeresig, somewhatabstract Checks: ✅ codecov/project, ✅ Test (macos-latest, 16.x), ✅ CodeQL, ✅ Lint, typecheck, and coverage check (ubuntu-latest, 16.x), ✅ Analyze (javascript), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ✅ gerald, ⏭ dependabot Pull Request URL: https://github.com/Khan/wonder-stuff/pull/754 --- .changeset/bright-cars-eat.md | 5 ++++ .../__tests__/get-gcp-log-transport.test.ts | 2 +- .../src/get-mobile-release-logger.ts | 24 ++++++++++++++----- packages/wonder-stuff-ci/src/types.ts | 2 ++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .changeset/bright-cars-eat.md diff --git a/.changeset/bright-cars-eat.md b/.changeset/bright-cars-eat.md new file mode 100644 index 00000000..6ca9a9a1 --- /dev/null +++ b/.changeset/bright-cars-eat.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/wonder-stuff-ci": minor +--- + +Add more configurations to the GCP logger diff --git a/packages/wonder-stuff-ci/src/__tests__/get-gcp-log-transport.test.ts b/packages/wonder-stuff-ci/src/__tests__/get-gcp-log-transport.test.ts index 7f7eea17..279a184b 100644 --- a/packages/wonder-stuff-ci/src/__tests__/get-gcp-log-transport.test.ts +++ b/packages/wonder-stuff-ci/src/__tests__/get-gcp-log-transport.test.ts @@ -8,7 +8,7 @@ describe("#getGCPLogTransport", () => { logName: "release-raccoon", level: "info", redirectToStdout: true, - labels: {}, + labels: {test: "test"}, }); // Assert diff --git a/packages/wonder-stuff-ci/src/get-mobile-release-logger.ts b/packages/wonder-stuff-ci/src/get-mobile-release-logger.ts index f3e222ae..547d3407 100644 --- a/packages/wonder-stuff-ci/src/get-mobile-release-logger.ts +++ b/packages/wonder-stuff-ci/src/get-mobile-release-logger.ts @@ -7,6 +7,7 @@ import { import * as winston from "winston"; import {getGCPLogTransport} from "./get-gcp-log-transport"; +import {GCPLogLevels} from "./types"; let logger: winston.Logger | null = null; @@ -14,31 +15,42 @@ let logger: winston.Logger | null = null; * Logger for auditing mobile release events. * @param {boolean} redirectToStdout If true, logs will be written to stdout. * @param {{[key: string]: string}} labels K/V metadata that will be add to the logs + * @param {GCPLogLevels} logLevel The log level to send to GCP. + * @param {string} logName The name of the log to send logs to in GCP. + * @param {string} projectId The GCP project ID to send logs to. */ export const getMobileReleaseLogger = ( { redirectToStdout, labels, + logLevel, + logName, + projectId, }: { redirectToStdout: boolean; labels: {[key: string]: string}; + logLevel: GCPLogLevels; + logName: string; + projectId: string; } = { redirectToStdout: false, labels: {}, + logLevel: "info", + logName: "release-raccoon", + projectId: "mobile-365917", }, ): winston.Logger => { if (!logger) { logger = createLogger({ mode: Runtime.Production, - level: "info", + level: logLevel, defaultMetadata: {}, transport: getGCPLogTransport({ - // Hardcoded so that the client does not need to know these values - projectId: "mobile-365917", - logName: "release-raccoon", - level: "info", + projectId: projectId, + logName: logName, + level: logLevel, redirectToStdout: redirectToStdout, - labels: {}, + labels: labels, }), }); setRootLogger(logger); diff --git a/packages/wonder-stuff-ci/src/types.ts b/packages/wonder-stuff-ci/src/types.ts index 8b019d01..123bf761 100644 --- a/packages/wonder-stuff-ci/src/types.ts +++ b/packages/wonder-stuff-ci/src/types.ts @@ -31,3 +31,5 @@ export type GCPTransportOptions = { */ labels: {[key: string]: string}; }; + +export type GCPLogLevels = "debug" | "info" | "warn" | "error";