diff --git a/apps/stats-web/mvm.lock b/apps/stats-web/mvm.lock index 0d99ab6a5..737b93165 100644 --- a/apps/stats-web/mvm.lock +++ b/apps/stats-web/mvm.lock @@ -1,5 +1,6 @@ { "dependencies": { + "@akashnetwork/logging": "2.0.2", "@akashnetwork/network-store": "1.0.1", "@akashnetwork/ui": "1.0.0" }, diff --git a/apps/stats-web/package.json b/apps/stats-web/package.json index c9a54267f..bd490d716 100644 --- a/apps/stats-web/package.json +++ b/apps/stats-web/package.json @@ -11,6 +11,7 @@ "start": "next start" }, "dependencies": { + "@akashnetwork/logging": "*", "@akashnetwork/network-store": "*", "@akashnetwork/ui": "*", "@cosmjs/encoding": "^0.32.4", diff --git a/apps/stats-web/src/config/browser-env.config.ts b/apps/stats-web/src/config/browser-env.config.ts index 903fec82c..9ffa681e8 100644 --- a/apps/stats-web/src/config/browser-env.config.ts +++ b/apps/stats-web/src/config/browser-env.config.ts @@ -6,5 +6,6 @@ export const browserEnvConfig = validateStaticEnvVars({ NEXT_PUBLIC_NODE_ENV: process.env.NEXT_PUBLIC_NODE_ENV, NEXT_PUBLIC_BASE_API_TESTNET_URL: process.env.NEXT_PUBLIC_BASE_API_TESTNET_URL, NEXT_PUBLIC_BASE_API_SANDBOX_URL: process.env.NEXT_PUBLIC_BASE_API_SANDBOX_URL, - NEXT_PUBLIC_BASE_API_MAINNET_URL: process.env.NEXT_PUBLIC_BASE_API_MAINNET_URL + NEXT_PUBLIC_BASE_API_MAINNET_URL: process.env.NEXT_PUBLIC_BASE_API_MAINNET_URL, + NEXT_PUBLIC_LOG_LEVEL: process.env.NEXT_PUBLIC_LOG_LEVEL }); diff --git a/apps/stats-web/src/config/env-config.schema.ts b/apps/stats-web/src/config/env-config.schema.ts index 1cb77e54f..8773a82bf 100644 --- a/apps/stats-web/src/config/env-config.schema.ts +++ b/apps/stats-web/src/config/env-config.schema.ts @@ -9,7 +9,8 @@ export const browserEnvSchema = z.object({ NEXT_PUBLIC_NODE_ENV: z.enum(["development", "production", "test"]).optional().default("development"), NEXT_PUBLIC_BASE_API_TESTNET_URL: z.string().url(), NEXT_PUBLIC_BASE_API_SANDBOX_URL: z.string().url(), - NEXT_PUBLIC_BASE_API_MAINNET_URL: z.string().url() + NEXT_PUBLIC_BASE_API_MAINNET_URL: z.string().url(), + NEXT_PUBLIC_LOG_LEVEL: z.enum(["fatal", "error", "warn", "info", "debug", "trace"]).optional().default("info") }); export const serverEnvSchema = browserEnvSchema.extend({ diff --git a/apps/stats-web/src/config/logger.config.ts b/apps/stats-web/src/config/logger.config.ts new file mode 100644 index 000000000..a84e5bb01 --- /dev/null +++ b/apps/stats-web/src/config/logger.config.ts @@ -0,0 +1,7 @@ +"use client"; + +import { LoggerService } from "@akashnetwork/logging"; + +import { browserEnvConfig } from "@/config/browser-env.config"; + +LoggerService.configure({ LOG_LEVEL: browserEnvConfig.NEXT_PUBLIC_LOG_LEVEL }); diff --git a/apps/stats-web/src/hooks/useLogger.ts b/apps/stats-web/src/hooks/useLogger.ts new file mode 100644 index 000000000..1e9bd0807 --- /dev/null +++ b/apps/stats-web/src/hooks/useLogger.ts @@ -0,0 +1,8 @@ +import "../config/logger.config"; + +import { useMemo } from "react"; +import { LoggerService } from "@akashnetwork/logging"; + +export const useLogger = (context: string) => { + return useMemo(() => LoggerService.forContext(context), [context]); +}; diff --git a/package-lock.json b/package-lock.json index 10d89d658..889cdbcc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ }, "apps/api": { "name": "@akashnetwork/console-api", - "version": "2.35.1", + "version": "2.35.2-beta.0", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akash-api": "^1.3.0", @@ -229,7 +229,7 @@ }, "apps/deploy-web": { "name": "@akashnetwork/console-web", - "version": "2.25.0", + "version": "2.25.1-beta.0", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akash-api": "^1.3.0", @@ -669,6 +669,7 @@ "apps/stats-web": { "version": "0.20.0", "dependencies": { + "@akashnetwork/logging": "*", "@akashnetwork/network-store": "*", "@akashnetwork/ui": "*", "@cosmjs/encoding": "^0.32.4", diff --git a/packages/logging/src/servicies/logger/logger.service.ts b/packages/logging/src/servicies/logger/logger.service.ts index 6a654d622..1d59f3b4f 100644 --- a/packages/logging/src/servicies/logger/logger.service.ts +++ b/packages/logging/src/servicies/logger/logger.service.ts @@ -55,16 +55,14 @@ export class LoggerService implements Logger { } private getPrettyIfPresent(): PinoPretty.PrettyStream | undefined { - if (typeof window !== "undefined" || LoggerService.config.STD_OUT_LOG_FORMAT !== "pretty") { - return; - } - - try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - return require("pino-pretty")({ colorize: true, sync: true }); - } catch (e) { - this.debug({ context: LoggerService.name, message: "Failed to load pino-pretty", error: e }); - /* empty */ + if (typeof window === "undefined" && LoggerService.config.STD_OUT_LOG_FORMAT === "pretty") { + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + return require("pino-pretty")({ colorize: true, sync: true }); + } catch (e) { + this.debug({ context: LoggerService.name, message: "Failed to load pino-pretty", error: e }); + /* empty */ + } } }