Repository navigation
chore(server): structured logging Phase 2 — routes slice (req.log) - #334
Merged
Merged
Conversation
Migrate the console.* calls in server/src/routes/ to the structured
logger. All lines run inside request handlers, so they use the
request-scoped req.log child (carries requestId) instead of raw
console.error, with { err } structured fields.
- audits.js — 6 handlers → req.log; 2 detached background functions
(runAuditJob / createAndRunAudit) use the module logger + auditId/brandId
- content.js, prompts.js, tracking.js, volumes.js, traffic.js,
competitors.js, topics.js — handler console.error → req.log.error({ err })
Part of #303 (Phase 2 of #245), part 2 of the incremental sweep after
#330. Level mapping unchanged (error → error); lines are now leveled +
JSON + request-correlatable.
There was a problem hiding this comment.
Pull request overview
This PR continues the server’s structured logging Phase 2 migration by replacing console.error calls in route handlers with request-scoped structured logging via req.log, improving log level semantics, JSON structure, and request correlation.
Changes:
- Migrates error logging in
server/src/routes/*handlers fromconsole.error(...)toreq.log.error({ err }, '...'). - Updates
audits.jsdetached/background execution paths to use the module-levelloggerwith useful identifiers (auditId,brandId) sincereqis not in scope. - Removes remaining
console.*usage from the touched routes slice.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| server/src/routes/audits.js | Migrates handler logs to req.log and uses module logger for background/detached audit functions. |
| server/src/routes/content.js | Converts multiple handler console.error calls to structured req.log.error({ err }) logs. |
| server/src/routes/prompts.js | Converts prompt suggestion route error logs to req.log.error({ err }). |
| server/src/routes/tracking.js | Migrates tracking endpoints’ error logs to request-scoped structured logs. |
| server/src/routes/volumes.js | Converts volume analysis/refresh/fetch error logs to req.log.error({ err }). |
| server/src/routes/topics.js | Migrates topic suggestion error logging to req.log. |
| server/src/routes/competitors.js | Migrates competitor suggestion error logging to req.log. |
| server/src/routes/traffic.js | Migrates traffic track error log to req.log (but see review comment re: middleware ordering). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return res.status(204).end(); | ||
| } catch (error) { | ||
| console.error('[traffic] Track error:', error.message); | ||
| req.log.error({ err: error }, 'traffic track error'); |
trafficRoutes is mounted before requestIdMiddleware in server.js (it needs its own open CORS for navigator.sendBeacon from any origin), so req.log is undefined on this public beacon path — req.log.error would throw on the first error. Use the module-level logger instead. Addresses the Copilot review on #334.
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
Second incremental slice of #303 (structured logging Phase 2), following #330. Migrates the
console.*calls inserver/src/routes/to the structured pino logger.Every migrated call lives inside a request handler, so it uses the request-scoped
req.logchild logger (which carries the per-requestrequestIdfrom the request-id middleware) instead of rawconsole.error— with structured{ err }fields rather than interpolatederr.messagestrings.Files migrated (~38 calls):
audits.js— 6 handlers →req.log.error({ err }, …); the 2 detached background functions (runAuditJob,createAndRunAudit, wherereqis out of scope) use the module-levellogger+{ auditId, brandId }content.js(10),tracking.js(7),prompts.js(6),volumes.js(4),traffic.js(1),topics.js(1),competitors.js(1) — handlerconsole.error→req.log.error({ err })Level mapping unchanged (
error→error); behaviour is identical — lines are now leveled + JSON-formatted + request-correlatable.Related issue
Part of #303 (Phase 2 of #245). This is part 2 (routes /
req.log). Workers, remaininglib/, andserver.js/middlewarefollow as separate PRs per the issue's "do it incrementally" guidance.Type of change
chore— MaintenanceHow to test
server/:npm run lint,npm run format:check, andnpm run test(93 tests) all pass.grep -rn "console\." server/src/routes/returns nothing.POST /api/audits) now emits a structured JSON log line aterrorlevel carryingrequestId, instead of aconsole.errorstring.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdnpm run lintpasses (fromserver/)npm run format:checkpasses (fromserver/)