From 14350c47e6d454f0409c55c35e43323c43d5965b Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Mon, 4 Nov 2024 16:31:49 +0100 Subject: [PATCH] feat: replace console with alokai logger in the middleware module (#7299) --- .../modules/middlewareModule.spec.ts | 2 +- .../middlewareModule/utils/defaultLogger.ts | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/sdk/src/__tests__/integration/modules/middlewareModule.spec.ts b/packages/sdk/src/__tests__/integration/modules/middlewareModule.spec.ts index a48d5a4544..f5fd893a2f 100644 --- a/packages/sdk/src/__tests__/integration/modules/middlewareModule.spec.ts +++ b/packages/sdk/src/__tests__/integration/modules/middlewareModule.spec.ts @@ -818,7 +818,7 @@ describe("middlewareModule", () => { it("should use the built in logger when ALOKAI_SDK_DEBUG is true", async () => { process.env.ALOKAI_SDK_DEBUG = "true"; - const logSpy = jest.spyOn(console, "log"); + const logSpy = jest.spyOn(console, "debug"); const sdk = initSDK({ commerce: buildModule(middlewareModule, { diff --git a/packages/sdk/src/modules/middlewareModule/utils/defaultLogger.ts b/packages/sdk/src/modules/middlewareModule/utils/defaultLogger.ts index 1059e15141..b5be459900 100644 --- a/packages/sdk/src/modules/middlewareModule/utils/defaultLogger.ts +++ b/packages/sdk/src/modules/middlewareModule/utils/defaultLogger.ts @@ -1,21 +1,25 @@ +import { LoggerFactory, LoggerType } from "@vue-storefront/logger"; import { Logger } from "../types"; +const internalLogger = LoggerFactory.create(LoggerType.ConsolaGcp, { + level: "debug", +}); + /** * Default logger for the `middlewareModule`. */ export const defaultLogger: Logger = { onRequest: ({ config, url, params }) => { const { pathname } = new URL(url); - // eslint-disable-next-line no-console - console.log( - `${config.method} ${pathname}`, - `(${typeof window === "undefined" ? "server" : "client"} side)`, - JSON.stringify(params) - ); + internalLogger.debug(`${config.method} ${pathname}`, { + context: `(${typeof window === "undefined" ? "server" : "client"} side)`, + params: JSON.stringify(params), + }); }, onResponse: ({ config, url, responseTime }) => { const { pathname } = new URL(url); - // eslint-disable-next-line no-console - console.log(`${config.method} ${pathname} in ${responseTime.toFixed()}ms`); + internalLogger.debug( + `${config.method} ${pathname} in ${responseTime.toFixed()}ms` + ); }, };