Repository navigation
chore(server): structured logging Phase 2 — server.js + middleware - #337
Merged
Merged
Conversation
Migrate the remaining console.* calls in server.js and middleware/index.js
to the pino logger (server.js already imported it in Phase 1).
- server.js (21): request handlers (internal endpoints, /cloro/callback)
→ req.log with structured fields (taskId, scraperId, ip, …); cron /
startup lines (runDailyTracking, listen, self-hosted cron) → module
logger. The global error handler uses the module logger, not req.log,
because an error thrown before requestIdMiddleware (public traffic
routes / body parser) has no req.log.
- middleware/index.js (4): socket + domain-check paths → module logger
({ err }); no req.log since sockets carry no requestId and the HTTP
variant isn't guaranteed to run after requestIdMiddleware.
Final slice of #303 (Phase 2 of #245) except lib/cloro-scraper.js, which
is deferred to land with the query fan-out work (#332). Behaviour
unchanged; lines are now leveled + JSON.
There was a problem hiding this comment.
Pull request overview
This PR completes the structured-logging migration for the server entrypoint and core middleware by replacing remaining console.* calls with the pino logger, using request-scoped req.log inside handlers and the module logger elsewhere (including the global error handler).
Changes:
- Replace remaining
console.*calls inserver/src/server.jswithreq.log.*(request handlers) and modulelogger.*(startup/cron/global error handler). - Replace remaining
console.*calls inserver/src/middleware/index.jswith modulelogger.*for socket and domain-check paths. - Add structured fields to key log lines (e.g.,
taskId,scraperId,brandId,status,ip,reason).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server/src/server.js | Migrates remaining logging in server handlers/startup/cron/error handling to structured pino logging (req.log + module logger). |
| server/src/middleware/index.js | Replaces console logging in socket auth + domain checks with module-level structured pino logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| console.log(`[cron] Daily tracking: triggered=${triggered} total_brands=${brands.length}`); | ||
| logger.info({ triggered, total: brands.length }, 'daily tracking triggered'); |
This was referenced Jul 6, 2026
Merged
gkhngyk
added a commit
that referenced
this pull request
Jul 6, 2026
…e) (#351) 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fifth slice of #303 (structured logging Phase 2). Migrates the remaining
console.*calls inserver.jsandmiddleware/index.jsto the pinologger(server.js already imported it in Phase 1).Files migrated (~25 calls):
server.js(21):/cloro/callback) →req.log.*with structured fields (taskId,scraperId,ip,status, …)runDailyTrackingsummary,server.listen, self-hosted cron trigger/schedule) → moduleloggerlogger, notreq.log— an error thrown beforerequestIdMiddleware(public traffic routes / body parser) has noreq.log, soreq.log.errorthere would itself throwmiddleware/index.js(4): socket auth + domain-check paths → modulelogger.error({ err })/logger.warn(sockets carry norequestId, and the HTTP domain-check variant isn't guaranteed to run afterrequestIdMiddleware)Level mapping per the issue. Behaviour unchanged; lines are now leveled + JSON.
Related issue
Part of #303 (Phase 2 of #245) — the final slice, following #330, and the routes / workers / lib-jobs slices. The only file left after this is
lib/cloro-scraper.js(10 calls), intentionally deferred to land together with the query fan-out work (#332) to avoid churn/conflicts. Once #332 lands, #303 can be closed.Type of change
chore— MaintenanceHow to test
server/:npm run lint,npm run format:check,npm run test(93 tests) all pass.grep -n "console\." server/src/server.js server/src/middleware/index.jsreturns nothing.server runningline; a/cloro/callbackdelivery logs structured request-scoped lines (req.log) carryingtaskId/scraperId; an unhandled error logs via the module logger with{ err }.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdnpm run lintpasses (fromserver/)npm run format:checkpasses (fromserver/)