From f0cf18e8c540d0dec2683afb11f6cc95177d116f Mon Sep 17 00:00:00 2001 From: Matt Wilde Date: Fri, 22 Nov 2024 19:02:52 -0500 Subject: [PATCH] logger component --- src/cli.mjs | 2 +- src/lib/command-helpers.mjs | 6 ++++-- src/lib/fauna-account-client.mjs | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cli.mjs b/src/cli.mjs index e571ac4e..7a80dc87 100644 --- a/src/cli.mjs +++ b/src/cli.mjs @@ -142,7 +142,7 @@ function buildYargs(argvInput) { "components to emit diagnostic logs for; this takes precedence over the 'verbosity' flag", type: "array", default: [], - choices: ["fetch", "error", "argv"], + choices: ["fetch", "error", "argv", "client"], }, // Whether authNZ middleware should run. Better way of doing this? authRequired: { diff --git a/src/lib/command-helpers.mjs b/src/lib/command-helpers.mjs index d1dcb59a..5b6223ad 100644 --- a/src/lib/command-helpers.mjs +++ b/src/lib/command-helpers.mjs @@ -31,10 +31,11 @@ export async function getSimpleClient(argv) { const { profile, secret } = argv; const accountKey = getAccountKey(profile).accountKey; if (secret) { - logger.debug("Using Database secret from command line flag"); + logger.debug("Using Database secret from command line flag", "client"); } else if (process.env.FAUNA_SECRET) { logger.debug( "Using Database secret from FAUNA_SECRET environment variable", + "client", ); } const secretSource = secret ? "command line flag" : "environment variable"; @@ -59,6 +60,7 @@ export async function getSimpleClient(argv) { } else { logger.debug( "No secret provided, checking for stored secret in credentials file", + "client", ); client = await clientFromStoredSecret({ argv, @@ -89,7 +91,7 @@ async function clientFromStoredSecret({ argv, accountKey }) { const newArgs = [args[0], { ...args[1], secret: existingSecret }]; return originalQuery(...newArgs).then(async (result) => { if (result.status === 401) { - logger.debug("stored secret is invalid, refreshing"); + logger.debug("stored secret is invalid, refreshing", "client"); // Refresh the secret, store it, and use it to try again const newSecret = await refreshDBKey(argv); const newArgs = [args[0], { ...args[1], secret: newSecret.secret }]; diff --git a/src/lib/fauna-account-client.mjs b/src/lib/fauna-account-client.mjs index 2e037c94..72a8a176 100644 --- a/src/lib/fauna-account-client.mjs +++ b/src/lib/fauna-account-client.mjs @@ -22,7 +22,10 @@ export class FaunaAccountClient { result = await original(args); } catch (e) { if (e instanceof InvalidCredsError) { - logger.debug("401 in account api, attempting to refresh session"); + logger.debug( + "401 in account api, attempting to refresh session", + "client", + ); try { const { accountKey: newAccountKey, refreshToken: newRefreshToken } = await refreshSession(this.profile); @@ -36,6 +39,7 @@ export class FaunaAccountClient { if (e instanceof InvalidCredsError) { logger.debug( "Failed to refresh session, expired or missing refresh token", + "client", ); promptLogin(); } else {