fix: replaced console logs with logger in adapters and agents#620
fix: replaced console logs with logger in adapters and agents#620otsybizov wants to merge 1 commit intomainnet-stagingfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces console.log/info/warn/error calls across multiple agents/adapters with the shared @chimera-monorepo/utils Logger to standardize structured logging and improve log parsing/redaction consistency.
Changes:
- Introduce local
Loggerinstances in several modules (agents, lambdas, adapters) and route previous console output throughlogger.*. - Convert ad-hoc debug
console.logstatements in chain providers/dispatch paths intologger.debugcalls. - Standardize error logging to prefer
jsonifyError(...)in many catch blocks.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/agents/watchtower/src/watcher.ts | Replace startup/setup console.error with logger calls; add fallback module logger. |
| packages/agents/watchtower/src/config.ts | Replace config parsing/IO console logs with a local logger. |
| packages/agents/relayer/src/make.ts | Replace startup/setup console errors with structured logger errors; add fallback module logger. |
| packages/agents/relayer/src/config.ts | Replace config parsing/IO console logs with a local logger. |
| packages/agents/relayer/src/bindings/server/index.ts | Replace server listen error console logging with logger error. |
| packages/agents/relayer/src/bindings/relays/index.ts | Replace temporary debug console logs with logger.debug. |
| packages/agents/monitor/src/monitor.ts | Replace banner console log and startup console error with logger calls. |
| packages/agents/monitor/src/index.ts | Replace lambda handler console logs with logger info. |
| packages/agents/monitor/src/config.ts | Replace config/SSM console logs with a local logger. |
| packages/agents/monitor/src/checklist/gas.ts | Replace relayer fetch console error with logger error. |
| packages/agents/lighthouse/src/index.ts | Replace lambda handler console logs with logger info. |
| packages/agents/lighthouse/src/context.ts | Replace banner console log and startup console error with logger calls. |
| packages/agents/lighthouse/src/config.ts | Replace config/SSM console logs with a local logger. |
| packages/agents/cartographer/poller/src/pollers/index.ts | Replace banner console log with logger info. |
| packages/agents/cartographer/poller/src/index.ts | Replace lambda handler console logs with logger info. |
| packages/agents/cartographer/core/src/config.ts | Replace config/SSM console logs with a local logger. |
| packages/adapters/subgraph/src/graph/reader.ts | Replace console.error on query failures with structured logger errors. |
| packages/adapters/subgraph/src/envio/reader.ts | Replace console.error on query failures with structured logger errors. |
| packages/adapters/chainservice/src/shared/rpc/tron/provider.ts | Replace extensive console debug output with logger.debug/logger.error. |
| packages/adapters/chainservice/src/shared/rpc/eth/provider.ts | Replace debug console.log path with Logger.debug via a module logger. |
| packages/adapters/chainservice/src/dispatch.ts | Replace dispatch-path console.log debug statements with this.logger.debug. |
| packages/adapters/chainservice/src/aggregator.ts | Replace aggregator-path console.log debug statement with this.logger.debug. |
| packages/adapters/cache/src/lib/caches/cache.ts | Replace Redis error console logging with logger error; add module logger. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| this.data.on('error', (err) => { | ||
| console.error('Redis connection error:', err); | ||
| logger.error('Redis connection error', undefined, undefined, undefined, { error: err }); | ||
| }); |
There was a problem hiding this comment.
In Logger.error, the 4th parameter is the structured error payload and it overwrites any error field in the ctx. Since you pass undefined as the 4th arg here, the { error: err } in ctx is effectively dropped and the Redis error details won’t be logged. Pass jsonifyError(err as Error) as the 4th arg (or put the raw error under a different ctx key).
| bindInterval(); | ||
| } catch (err: unknown) { | ||
| console.error('Error starting watcher :(', err); | ||
| (context.logger ?? logger).error('Error starting watcher :(', undefined, undefined, undefined, { error: err }); |
There was a problem hiding this comment.
Logger.error takes the structured error as the 4th argument (ErrorJson). Passing undefined there while also putting { error: err } in the ctx means the logger will overwrite ctx.error with undefined, so the actual error details won't be logged. Pass jsonifyError(err as Error) as the 4th arg (and if you still want the raw value, put it under a different ctx key).
| (context.logger ?? logger).error('Error starting watcher :(', undefined, undefined, undefined, { error: err }); | |
| (context.logger ?? logger).error( | |
| 'Error starting watcher :(', | |
| undefined, | |
| undefined, | |
| jsonifyError(err as Error), | |
| { rawError: err }, | |
| ); |
| } 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’s 4th parameter is the structured error payload. Here it’s passed as undefined and { error: e } is put into ctx, but Logger.error merges ctx and then overwrites error with the 4th arg—so the exception won’t be included in logs. Pass jsonifyError(e as Error) as the 4th arg (and use a different ctx field name if you want to attach the raw error too).
| } 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.
Same Logger.error argument issue: { error: e } is being passed in ctx while the dedicated error parameter is undefined, which results in error being overwritten to undefined and losing the exception details. Use jsonifyError(e as Error) as the 4th argument (and move any additional data to a different ctx key).
| (err, address) => { | ||
| if (err) { | ||
| console.error(err); | ||
| logger.error('Server failed to start', undefined, undefined, undefined, { error: err }); |
There was a problem hiding this comment.
Logger.error overwrites ctx.error with its 4th argument. Because the 4th arg is undefined here, the { error: err } you pass in ctx is dropped and the startup error won’t be logged. Pass jsonifyError(err as Error) as the 4th arg (and attach the raw error under a different ctx key if needed).
| logger.error('Server failed to start', undefined, undefined, undefined, { error: err }); | |
| logger.error('Server failed to start', undefined, undefined, jsonifyError(err as Error), { rawError: err }); |
| } catch (error) { | ||
| console.error(`Error fetching address from ${relayerUrl}:`, error); | ||
| logger.error(`Error fetching address from ${relayerUrl}`, undefined, undefined, undefined, { error }); | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
Logger.error’s 4th argument is reserved for the structured error. Passing undefined there causes Logger.error to overwrite ctx.error with undefined, so this log line will drop the caught exception. Pass jsonifyError(error as Error) as the 4th arg (and keep the URL/domain/etc in ctx).
🤖 Linear
Closes CONG-XXX