Skip to content

Commit

Permalink
Add more configuration options for MobileReleaseLogger (#754)
Browse files Browse the repository at this point in the history
## 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: #754
  • Loading branch information
jlauzy authored Jun 8, 2023
1 parent 7042c11 commit 76aaaaf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-cars-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/wonder-stuff-ci": minor
---

Add more configurations to the GCP logger
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("#getGCPLogTransport", () => {
logName: "release-raccoon",
level: "info",
redirectToStdout: true,
labels: {},
labels: {test: "test"},
});

// Assert
Expand Down
24 changes: 18 additions & 6 deletions packages/wonder-stuff-ci/src/get-mobile-release-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,50 @@ import {
import * as winston from "winston";

import {getGCPLogTransport} from "./get-gcp-log-transport";
import {GCPLogLevels} from "./types";

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);
Expand Down
2 changes: 2 additions & 0 deletions packages/wonder-stuff-ci/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ export type GCPTransportOptions = {
*/
labels: {[key: string]: string};
};

export type GCPLogLevels = "debug" | "info" | "warn" | "error";

0 comments on commit 76aaaaf

Please sign in to comment.