Skip to content

chore(server): structured logging Phase 2 — cloro-scraper (final slice, closes #303) - #351

Merged
gkhngyk merged 1 commit into
mainfrom
feature/logging-phase2-cloro-scraper
Jul 6, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/logging-phase2-cloro-scraper

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

The final slice of #303 (structured logging Phase 2). Migrates the last remaining console.* calls — the 10 in lib/cloro-scraper.js — to the module-level pino logger. This file was intentionally held back from the earlier slices to avoid churn/conflicts with the query fan-out work (#341), which is now merged.

After this, every non-script console.* in server/src routes through the structured logger.

Changes (server/src/lib/cloro-scraper.js)

Runs outside the request lifecycle, so it uses the module logger (not req.log), with structured fields instead of interpolated strings:

  • per-task chatter (task submitted, completed, polling) → logger.debug({ taskId, scraperId, pollCount, … })
  • operational start (submitting scraper task) → logger.info({ taskType, scraperId, region })
  • submit/poll failures + timeout → logger.error({ scraperId/taskId, status/reason, … })
  • Customer prompt text is no longer written to the submit log — taskType / scraperId / region identify the task instead.

Level mapping per the issue. Behaviour unchanged; lines are now leveled + JSON.

Related issue

Closes #303. Phase 2 of #245 is complete across: #330 (lib/config), #334 (routes), #335 (workers), #336 (lib job manager/runner), #337 (server.js + middleware), and this final slice.

Type of change

  • chore — Maintenance

How to test

  1. From server/: npm run lint, npm run format:check, npm run test (99 tests) all pass.
  2. grep -rn "console\." server/src --include="*.js" | grep -v /scripts/ | grep -v .test.js returns nothing.
  3. Submitting/polling a Cloro task now emits structured JSON log lines (debug for per-task chatter, error for failures/timeouts) with no customer prompt text in the log body.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • npm run lint passes (from server/)
  • npm run format:check passes (from server/)
  • Changes are focused — one concern per PR

Migrate the last console.* calls (lib/cloro-scraper.js) to the module-level
pino logger. This file was deliberately held back from the earlier slices
to avoid churn with the query fan-out work (#341, now merged).

- submit/poll per-task chatter (task submitted, completed, polling) →
  logger.debug({ taskId, scraperId, ... }); operational start → logger.info
  ({ taskType, scraperId, region }); failures/timeouts → logger.error
  ({ ..., status/reason }). Customer prompt text is no longer written to the
  submit log — taskType/scraperId/region identify the task instead.

Closes #303: every non-script console.* in server/src now routes through the
structured logger. Phase 2 of #245 is complete (parts: #330, #334, #335,
#336, #337, and this).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Completes structured logging Phase 2 for the server by migrating the remaining console.* calls in server/src/lib/cloro-scraper.js to the module-level pino logger, using leveled, structured JSON logs and avoiding logging customer prompt text in the submit “start” line.

Changes:

  • Replaced console.log/error with logger.info/debug/error in Cloro task submit + poll paths.
  • Converted interpolated log strings into structured fields (taskId, scraperId, taskType, pollCount, etc.).
  • Removed prompt text from the submit “submitting task” log line (keeps identifying fields only).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 283 to 285
if (res.status === 404) {
console.error(`[cloro] Poll #${pollCount} task=${taskId}: 404 not found`);
logger.error({ taskId, pollCount }, 'cloro poll: task not found (404)');
throw new Error(`Cloro task ${taskId} not found`);
Comment on lines 287 to 289
const errorBody = await res.text().catch(() => '');
console.error(`[cloro] Poll #${pollCount} task=${taskId}: HTTP ${res.status}`);
logger.error({ taskId, pollCount, status: res.status }, 'cloro poll: http error');
throw new Error(`Cloro poll error ${res.status}: ${errorBody.slice(0, 300)}`);
@gkhngyk
gkhngyk merged commit 23555e0 into main Jul 6, 2026
6 checks passed
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.

feat(server): structured logging Phase 2 — migrate remaining console.* calls to the logger

2 participants