Skip to content

Commit

Permalink
Add verbosity flag (#6429)
Browse files Browse the repository at this point in the history
* Add verbosity flag

* Fixme fix

* Changed name, added SILENT

---------

Co-authored-by: joehan <[email protected]>
  • Loading branch information
christhompsongoogle and joehan authored Oct 10, 2023
1 parent b36700f commit 6c83905
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/commands/emulators-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const command = new Command("emulators:exec <script>")
.option(commandUtils.FLAG_INSPECT_FUNCTIONS, commandUtils.DESC_INSPECT_FUNCTIONS)
.option(commandUtils.FLAG_IMPORT, commandUtils.DESC_IMPORT)
.option(commandUtils.FLAG_EXPORT_ON_EXIT, commandUtils.DESC_EXPORT_ON_EXIT)
.option(commandUtils.FLAG_VERBOSITY, commandUtils.DESC_VERBOSITY)
.option(commandUtils.FLAG_UI, commandUtils.DESC_UI)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.action((script: string, options: any) => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/emulators-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const command = new Command("emulators:start")
.option(commandUtils.FLAG_INSPECT_FUNCTIONS, commandUtils.DESC_INSPECT_FUNCTIONS)
.option(commandUtils.FLAG_IMPORT, commandUtils.DESC_IMPORT)
.option(commandUtils.FLAG_EXPORT_ON_EXIT, commandUtils.DESC_EXPORT_ON_EXIT)
.option(commandUtils.FLAG_VERBOSITY, commandUtils.DESC_VERBOSITY)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.action((options: any) => {
const killSignalPromise = commandUtils.shutdownWhenKilled(options);
Expand Down
4 changes: 4 additions & 0 deletions src/emulator/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const EXPORT_ON_EXIT_USAGE_ERROR =

export const EXPORT_ON_EXIT_CWD_DANGER = `"${FLAG_EXPORT_ON_EXIT_NAME}" must not point to the current directory or parents. Please choose a new/dedicated directory for exports.`;

export const FLAG_VERBOSITY_NAME = "--log-verbosity";
export const FLAG_VERBOSITY = `${FLAG_VERBOSITY_NAME} <verbosity>`;
export const DESC_VERBOSITY = "One of: DEBUG, INFO, QUIET, SILENT. "; // TODO complete the rest

export const FLAG_UI = "--ui";
export const DESC_UI = "run the Emulator UI";

Expand Down
7 changes: 6 additions & 1 deletion src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ExportMetadata, HubExport } from "./hubExport";
import { EmulatorUI } from "./ui";
import { LoggingEmulator } from "./loggingEmulator";
import * as dbRulesConfig from "../database/rulesConfig";
import { EmulatorLogger } from "./emulatorLogger";
import { EmulatorLogger, Verbosity } from "./emulatorLogger";
import { EmulatorHubClient } from "./hubClient";
import { confirm } from "../prompt";
import {
Expand Down Expand Up @@ -247,6 +247,7 @@ function findExportMetadata(importPath: string): ExportMetadata | undefined {

interface EmulatorOptions extends Options {
extDevEnv?: Record<string, string>;
logVerbosity?: "DEBUG" | "INFO" | "QUIET" | "SILENT";
}

/**
Expand Down Expand Up @@ -286,6 +287,10 @@ export async function startAll(
throw new FirebaseError(JAVA_DEPRECATION_WARNING);
}
}
if (options.logVerbosity) {
EmulatorLogger.setVerbosity(Verbosity[options.logVerbosity]);
}

const hubLogger = EmulatorLogger.forEmulator(Emulators.HUB);
hubLogger.logLabeled("BULLET", "emulators", `Starting emulators: ${targets.join(", ")}`);

Expand Down
7 changes: 6 additions & 1 deletion src/emulator/emulatorLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@ export enum Verbosity {
DEBUG = 0,
INFO = 1,
QUIET = 2,
SILENT = 3,
}
export type ExtensionLogInfo = {
ref?: string;
instanceId?: string;
};

export class EmulatorLogger {
static verbosity: Verbosity = Verbosity.DEBUG;
private static verbosity: Verbosity = Verbosity.DEBUG;
static warnOnceCache = new Set<string>();

constructor(public readonly name: string, private data: LogData = {}) {}

static setVerbosity(verbosity: Verbosity) {
EmulatorLogger.verbosity = verbosity;
}

static forEmulator(emulator: Emulators) {
return new EmulatorLogger(emulator, {
metadata: {
Expand Down
2 changes: 1 addition & 1 deletion src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class FunctionsEmulator implements EmulatorInstance {

constructor(private args: FunctionsEmulatorArgs) {
// TODO: Would prefer not to have static state but here we are!
EmulatorLogger.verbosity = this.args.quiet ? Verbosity.QUIET : Verbosity.DEBUG;
EmulatorLogger.setVerbosity(this.args.quiet ? Verbosity.QUIET : Verbosity.DEBUG);
// When debugging is enabled, the "timeout" feature needs to be disabled so that
// functions don't timeout while a breakpoint is active.
if (this.args.debugPort) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function logLabeledWarning(
}

/**
* Log an rror statement with a red bullet at the start of the line.
* Log an error statement with a red bullet at the start of the line.
*/
export function logLabeledError(
label: string,
Expand Down

0 comments on commit 6c83905

Please sign in to comment.