diff --git a/apps/stats-web/mvm.lock b/apps/stats-web/mvm.lock index 0d99ab6a5..c120eb026 100644 --- a/apps/stats-web/mvm.lock +++ b/apps/stats-web/mvm.lock @@ -1,7 +1,8 @@ { "dependencies": { "@akashnetwork/network-store": "1.0.1", - "@akashnetwork/ui": "1.0.0" + "@akashnetwork/ui": "1.0.0", + "@akashnetwork/logging": "2.0.2" }, "devDependencies": { "@akashnetwork/dev-config": "1.0.0" diff --git a/apps/stats-web/package.json b/apps/stats-web/package.json index c9a54267f..550ad3381 100644 --- a/apps/stats-web/package.json +++ b/apps/stats-web/package.json @@ -13,6 +13,7 @@ "dependencies": { "@akashnetwork/network-store": "*", "@akashnetwork/ui": "*", + "@akashnetwork/logging": "*", "@cosmjs/encoding": "^0.32.4", "@json2csv/plainjs": "^7.0.4", "@nivo/line": "^0.87.0", diff --git a/apps/stats-web/src/app/blocks/[height]/errors.tsx b/apps/stats-web/src/app/blocks/[height]/errors.tsx index 65ae27eb5..544fb5b83 100644 --- a/apps/stats-web/src/app/blocks/[height]/errors.tsx +++ b/apps/stats-web/src/app/blocks/[height]/errors.tsx @@ -1,11 +1,14 @@ "use client"; // Error components must be Client Components import { useEffect } from "react"; +import { LoggerService } from "@akashnetwork/logging"; + +const blockErrorLogger = LoggerService.forContext("apps/stats-web/src/app/blocks/[height]/errors.tsx"); export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { useEffect(() => { // Log the error to an error reporting service - console.error(error); + blockErrorLogger.debug(error); }, [error]); return ( diff --git a/apps/stats-web/src/app/error.tsx b/apps/stats-web/src/app/error.tsx index c6ede3758..a0c686d6b 100644 --- a/apps/stats-web/src/app/error.tsx +++ b/apps/stats-web/src/app/error.tsx @@ -1,15 +1,18 @@ "use client"; // Error components must be Client Components import { useEffect } from "react"; +import { LoggerService } from "@akashnetwork/logging"; import { Button } from "@akashnetwork/ui/components"; import PageContainer from "@/components/PageContainer"; import { Title } from "@/components/Title"; +const errorLogger = LoggerService.forContext("apps/stats-web/src/app/error.tsx"); + export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { useEffect(() => { // Log the error to an error reporting service - console.error(error); + errorLogger.debug(error); }, [error]); return ( diff --git a/apps/stats-web/src/app/transactions/[hash]/error.tsx b/apps/stats-web/src/app/transactions/[hash]/error.tsx index c6ede3758..6eb7b774d 100644 --- a/apps/stats-web/src/app/transactions/[hash]/error.tsx +++ b/apps/stats-web/src/app/transactions/[hash]/error.tsx @@ -1,15 +1,18 @@ "use client"; // Error components must be Client Components import { useEffect } from "react"; +import { LoggerService } from "@akashnetwork/logging"; import { Button } from "@akashnetwork/ui/components"; import PageContainer from "@/components/PageContainer"; import { Title } from "@/components/Title"; +const transactionLogger = LoggerService.forContext("apps/stats-web/src/app/transactions/[hash]/errors.tsx"); + export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { useEffect(() => { // Log the error to an error reporting service - console.error(error); + transactionLogger.debug(error); }, [error]); return ( diff --git a/apps/stats-web/src/app/transactions/[hash]/page.tsx b/apps/stats-web/src/app/transactions/[hash]/page.tsx index 76bc605b6..2f2ab4477 100644 --- a/apps/stats-web/src/app/transactions/[hash]/page.tsx +++ b/apps/stats-web/src/app/transactions/[hash]/page.tsx @@ -1,4 +1,5 @@ import React from "react"; +import { LoggerService } from "@akashnetwork/logging"; import type { Network } from "@akashnetwork/network-store"; import { Alert, Card, CardContent } from "@akashnetwork/ui/components"; import type { Metadata } from "next"; @@ -14,6 +15,8 @@ import { getSplitText } from "@/hooks/useShortText"; import { serverApiUrlService } from "@/services/api-url/server-api-url.service"; import { TransactionDetail } from "@/types"; +const transactionLogger = LoggerService.forContext("apps/stats-web/src/app/transactions/[hash]/page.tsx"); + const TransactionDetailPageSchema = z.object({ params: z.object({ hash: z.string() @@ -33,7 +36,7 @@ export async function generateMetadata({ params: { hash } }: TransactionDetailPa async function fetchTransactionData(hash: string, network: Network["id"]): Promise { const apiUrl = serverApiUrlService.getBaseApiUrlFor(network); - console.log("DEBUG apiUrl", apiUrl); + transactionLogger.debug(`DEBUG apiUrl: ${apiUrl}`); const response = await fetch(`${apiUrl}/v1/transactions/${hash}`); if (!response.ok && response.status !== 404) { diff --git a/apps/stats-web/src/lib/copyClipboard.ts b/apps/stats-web/src/lib/copyClipboard.ts index 9744acbdc..d914d7436 100644 --- a/apps/stats-web/src/lib/copyClipboard.ts +++ b/apps/stats-web/src/lib/copyClipboard.ts @@ -1,3 +1,7 @@ +import { LoggerService } from "@akashnetwork/logging"; + +const libLogger = LoggerService.forContext("apps/stats-web/src/lib/copyClipboard.ts"); + function fallbackCopyTextToClipboard(text: string) { const textArea = document.createElement("textarea"); textArea.value = text; @@ -14,9 +18,9 @@ function fallbackCopyTextToClipboard(text: string) { try { const successful = document.execCommand("copy"); const msg = successful ? "successful" : "unsuccessful"; - console.log("Fallback: Copying text command was " + msg); + libLogger.debug("Fallback: Copying text command was " + msg); } catch (err) { - console.error("Fallback: Oops, unable to copy", err); + libLogger.debug(`Fallback: Oops, unable to copy: ${err}`); } document.body.removeChild(textArea); @@ -28,10 +32,10 @@ export const copyTextToClipboard = (text: string) => { } navigator.clipboard.writeText(text).then( () => { - console.log("Async: Copying to clipboard was successful!"); + libLogger.debug("Async: Copying to clipboard was successful!"); }, err => { - console.error("Async: Could not copy text: ", err); + libLogger.debug(`Async: Could not copy text: ${err}`); } ); }; diff --git a/package-lock.json b/package-lock.json index 10d89d658..f52d2f80e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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..bc97e3ce0 100644 --- a/packages/logging/src/servicies/logger/logger.service.ts +++ b/packages/logging/src/servicies/logger/logger.service.ts @@ -60,8 +60,10 @@ export class LoggerService implements Logger { } try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - return require("pino-pretty")({ colorize: true, sync: true }); + if (typeof window === 'undefined') { + // 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 */