Skip to content

Commit

Permalink
refactor: Loggerutil.ts (#2984)
Browse files Browse the repository at this point in the history
  • Loading branch information
magiziz authored Oct 2, 2024
1 parent bc148e3 commit b5444bd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
38 changes: 38 additions & 0 deletions .changeset/lucky-bats-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
'@reown/appkit-utils': patch
'@apps/demo': patch
'@apps/gallery': patch
'@apps/laboratory': patch
'@examples/html-ethers': patch
'@examples/html-ethers5': patch
'@examples/html-wagmi': patch
'@examples/next-ethers': patch
'@examples/next-wagmi': patch
'@examples/react-ethers': patch
'@examples/react-ethers5': patch
'@examples/react-solana': patch
'@examples/react-wagmi': patch
'@examples/vue-ethers5': patch
'@examples/vue-solana': patch
'@examples/vue-wagmi': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-cdn': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-ethers': patch
'@reown/appkit-ethers5': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-solana': patch
'@reown/appkit-ui': patch
'@reown/appkit-wagmi': patch
'@reown/appkit-wallet': patch
---

Changed logger imports to not cause the webpack bundler to throw a CommonJS module error.
14 changes: 10 additions & 4 deletions packages/appkit-utils/src/LoggerUtil.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { pino } from '@walletconnect/logger'
import { generatePlatformLogger, getDefaultLoggerOptions } from '@walletconnect/logger'

export const LoggerUtil = {
createLogger(onError: (error: Error, ...args: unknown[]) => void, level = 'error') {
const pinoLogger = pino({ level })
const loggerOptions = getDefaultLoggerOptions({
level
})

pinoLogger.error = (...args: unknown[]) => {
const { logger } = generatePlatformLogger({
opts: loggerOptions
})

logger.error = (...args: unknown[]) => {
for (const arg of args) {
if (arg instanceof Error) {
onError(arg, ...args)
Expand All @@ -15,6 +21,6 @@ export const LoggerUtil = {
onError(new Error(), ...args)
}

return pinoLogger
return logger
}
}

0 comments on commit b5444bd

Please sign in to comment.