fix: replaced console logs with logger in adapters and agents#619
fix: replaced console logs with logger in adapters and agents#619otsybizov wants to merge 1 commit intomainnet-stagingfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces console.* logging with the shared Logger across multiple agents and adapters to standardize/structure logs and reduce raw console output.
Changes:
- Replaced
console.log/info/warn/errorcalls withLoggercalls across agents/adapters. - Added module-level
Loggerinstances in several entrypoints/config modules (including Lambda handlers). - Converted ad-hoc debug console prints in ChainService providers/dispatch paths into structured debug logs.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/agents/watchtower/src/watcher.ts | Use Logger for startup/context error reporting (adds fallback logger). |
| packages/agents/watchtower/src/config.ts | Replace console logging during config parsing/fetch with Logger. |
| packages/agents/relayer/src/make.ts | Use Logger for relayer startup/context errors (adds fallback logger). |
| packages/agents/relayer/src/config.ts | Replace console logging during config load/fetch with Logger. |
| packages/agents/relayer/src/bindings/server/index.ts | Replace server startup console.error with structured Logger.error. |
| packages/agents/relayer/src/bindings/relays/index.ts | Replace temporary console debug prints in poll loop with logger.debug. |
| packages/agents/monitor/src/monitor.ts | Replace banner/startup console logging with context.logger. |
| packages/agents/monitor/src/index.ts | Replace Lambda console logs with structured Logger invocation log. |
| packages/agents/monitor/src/config.ts | Replace config-load console output with Logger calls. |
| packages/agents/monitor/src/checklist/gas.ts | Replace relayer fetch error console.error with logger.error. |
| packages/agents/lighthouse/src/index.ts | Replace Lambda console logs with structured Logger invocation log. |
| packages/agents/lighthouse/src/context.ts | Replace banner/startup console logging with logger.info/error. |
| packages/agents/lighthouse/src/config.ts | Replace config-load console output with Logger calls. |
| packages/agents/cartographer/poller/src/pollers/index.ts | Replace poller banner console logging with context.logger. |
| packages/agents/cartographer/poller/src/index.ts | Replace Lambda console logs with structured Logger invocation log. |
| packages/agents/cartographer/core/src/config.ts | Replace config-load console output with Logger calls. |
| packages/adapters/subgraph/src/graph/reader.ts | Replace subgraph query console.error with structured logger.error. |
| packages/adapters/subgraph/src/envio/reader.ts | Replace Envio query console.error with structured logger.error (adds module logger). |
| packages/adapters/chainservice/src/shared/rpc/tron/provider.ts | Replace extensive Tron debug console logs with structured logger.debug/error. |
| packages/adapters/chainservice/src/shared/rpc/eth/provider.ts | Replace provider debug console logs with structured debug logger. |
| packages/adapters/chainservice/src/dispatch.ts | Replace dispatch console debug prints with this.logger.debug. |
| packages/adapters/chainservice/src/aggregator.ts | Replace aggregator console debug prints with this.logger.debug. |
| packages/adapters/cache/src/lib/caches/cache.ts | Replace Redis connection console.error with structured logger.error. |
Comments suppressed due to low confidence (1)
packages/adapters/subgraph/src/envio/reader.ts:41
- This file now has an
importstatement after executable code (const logger = ...). In TypeScript/ESM, imports must come before other statements, so this will fail to compile. Move theloggerinitialization below all imports (or merge the laterimport { ... } from '../lib'up with the other imports).
const logger = new Logger({
level: 'info',
name: 'envio-reader',
formatters: {
level: (label) => ({ level: label.toUpperCase() }),
},
});
import {
getEnvioIntentByIdQuery,
getEnvioIntentsQuery,
QueryResponse,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } catch (e) { | ||
| console.error('Failed to fetch everclear config:', e); | ||
| logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e }); | ||
| } |
There was a problem hiding this comment.
This call won’t include the thrown error because Logger.error overwrites ctx.error with its explicit 4th argument (currently undefined). Pass jsonifyError(e as Error) as the 4th parameter instead of { error: e } in the context.
| } catch (error) { | ||
| console.error('TRON DEBUG: Smart contract transaction failed:', error); | ||
| logger.error('Smart contract transaction failed', undefined, undefined, undefined, { error }); | ||
| if (error instanceof Error) { |
There was a problem hiding this comment.
Logger.error(..., undefined, { error }) drops the error because Logger.error overwrites ctx.error with its explicit 4th argument (here undefined). Pass jsonifyError(error as Error) (or convert to ErrorJson) as the 4th parameter so the failure reason is logged.
| everclearConfig = await getEverclearConfig(everclearConfigUrl); | ||
| } catch (e) { | ||
| console.error('Failed to fetch everclear config:', e); | ||
| logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e }); |
There was a problem hiding this comment.
This logger.error call won’t include the caught error because the 4th error parameter is undefined and Logger.error overwrites ctx.error. Pass jsonifyError(e as Error) as the 4th argument (or otherwise convert e to ErrorJson) instead of putting the error in the context.
| logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e }); | |
| logger.error('Failed to fetch everclear config', undefined, undefined, jsonifyError(e as Error)); |
| (context.logger ?? logger).error('Error starting relayer :(', undefined, undefined, undefined, { error: err }); | ||
| process.exit(1); |
There was a problem hiding this comment.
Logger.error overwrites ctx.error with its explicit 4th parameter. Because the 4th parameter is undefined here, the error won’t be logged. Pass jsonifyError(err as Error) as the 4th argument and reserve the final context argument for extra fields.
| const ethProviderLogger = new Logger({ | ||
| level: 'debug', | ||
| name: 'eth-provider', | ||
| formatters: { | ||
| level: (label) => ({ level: label.toUpperCase() }), | ||
| }, | ||
| }); | ||
|
|
||
| import { parseError, RpcError, ServerError, StallTimeout } from '../../errors'; | ||
| import { ISigner, ReadTransaction, WriteTransaction, ITransactionReceipt, ITransactionResponse, IBlock } from '../../types'; |
There was a problem hiding this comment.
There’s an import statement after executable code (const ethProviderLogger = ...). TypeScript/ESM requires all imports to be at the top level before other statements, so this will not compile. Move the ethProviderLogger initialization below the last import (or convert the later imports into the initial import block).
| (context.logger ?? logger).error( | ||
| 'Error setup context Watcher! D: Who could have done this?', | ||
| requestContext, | ||
| methodContext, | ||
| undefined, | ||
| { error }, | ||
| ); |
There was a problem hiding this comment.
Same issue here: { error } is provided in the context, but Logger.error(..., undefined, { error }) results in error being overwritten to undefined inside Logger.error. Use jsonifyError(error as Error) as the 4th argument (and add the jsonifyError import if needed).
| (context.logger ?? logger).error( | ||
| 'Error setup context Relayer! D: Who could have done this?', | ||
| requestContext, | ||
| methodContext, | ||
| undefined, | ||
| { error }, | ||
| ); |
There was a problem hiding this comment.
Same pattern here: the caught error is placed into the context object, but Logger.error sets error from its 4th argument (currently undefined), so it’s lost. Use jsonifyError(error as Error) as the 4th parameter (and import it if needed).
| } catch (e) { | ||
| console.error('Failed to fetch everclear config:', e); | ||
| logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e }); | ||
| } |
There was a problem hiding this comment.
This error log won’t include the caught exception because Logger.error overwrites ctx.error with its explicit 4th argument (here undefined). Pass a proper ErrorJson (e.g., jsonifyError(e as Error)) as the 4th parameter instead of { error: e } in the context.
| } catch (e: unknown) { | ||
| console.error('Error reading config file!', e); | ||
| logger.error('Error reading config file!', undefined, undefined, undefined, { error: e }); | ||
| process.exit(1); |
There was a problem hiding this comment.
Logger.error will overwrite ctx.error with its 4th argument. Because the 4th argument is undefined here, the exception won’t be logged. Pass jsonifyError(e as Error) as the 4th param (and use the final arg for extra fields).
| everclearConfig = await getEverclearConfig(everclearConfigUrl); | ||
| } catch (e) { | ||
| console.error('Failed to fetch everclear config:', e); | ||
| logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e }); |
There was a problem hiding this comment.
This logger.error call won’t log the caught error because the 4th error parameter is undefined, and Logger.error overwrites ctx.error. Pass jsonifyError(e as Error) (or another ErrorJson) as the 4th argument instead of { error: e } in the context.
| logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e }); | |
| logger.error('Failed to fetch everclear config', undefined, undefined, jsonifyError(e as Error)); |
🤖 Linear
Closes CONG-XXX