Skip to content

fix: replaced console logs with logger in adapters and agents#620

Closed
otsybizov wants to merge 1 commit intomainnet-stagingfrom
fix/replace-console-logging
Closed

fix: replaced console logs with logger in adapters and agents#620
otsybizov wants to merge 1 commit intomainnet-stagingfrom
fix/replace-console-logging

Conversation

@otsybizov
Copy link
Contributor

🤖 Linear

Closes CONG-XXX

Copilot AI review requested due to automatic review settings March 25, 2026 19:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Logger instances in several modules (agents, lambdas, adapters) and route previous console output through logger.*.
  • Convert ad-hoc debug console.log statements in chain providers/dispatch paths into logger.debug calls.
  • 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.

Comment on lines 33 to 35
this.data.on('error', (err) => {
console.error('Redis connection error:', err);
logger.error('Redis connection error', undefined, undefined, undefined, { error: err });
});
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
bindInterval();
} catch (err: unknown) {
console.error('Error starting watcher :(', err);
(context.logger ?? logger).error('Error starting watcher :(', undefined, undefined, undefined, { error: err });
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
(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 },
);

Copilot uses AI. Check for mistakes.
Comment on lines 86 to 88
} catch (e: unknown) {
console.error('Error reading config file!', e);
logger.error('Error reading config file!', undefined, undefined, undefined, { error: e });
process.exit(1);
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines 96 to 98
} catch (e) {
console.error('Failed to fetch everclear config:', e);
logger.error('Failed to fetch everclear config', undefined, undefined, undefined, { error: e });
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
(err, address) => {
if (err) {
console.error(err);
logger.error('Server failed to start', undefined, undefined, undefined, { error: err });
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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 });

Copilot uses AI. Check for mistakes.
Comment on lines 218 to 221
} catch (error) {
console.error(`Error fetching address from ${relayerUrl}:`, error);
logger.error(`Error fetching address from ${relayerUrl}`, undefined, undefined, undefined, { error });
return undefined;
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@otsybizov otsybizov closed this Mar 25, 2026
@otsybizov otsybizov deleted the fix/replace-console-logging branch March 25, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants