Uh oh!
There was an error while loading. Please reload this page.
🧹 Centralize backend logging using a wrapper utility - #8
Conversation
Introduced a centralized logger utility in `backend/src/utils/logger.ts` and updated all instances of `console.log` and `console.error` in the backend to use this utility. This improves maintainability and allows for easier future upgrades to a full logging library. Changes: - Created `backend/src/utils/logger.ts` - Updated `backend/src/routes/auth.ts` - Updated `backend/src/routes/notes.ts` - Updated `backend/src/server.ts` - Added `backend/pnpm-lock.yaml` (automatically generated during verification) Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR centralizes backend logging by introducing a small logger utility and updating backend entrypoints/routes to use it instead of direct console.* calls.
Changes:
- Added
backend/src/utils/logger.tsas a wrapper aroundconsolemethods. - Replaced direct
console.log/errorusage inserver.ts,routes/auth.ts, androutes/notes.tswith the new logger. - Added
backend/pnpm-lock.yaml(new lockfile).
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/src/utils/logger.ts | Introduces centralized logger wrapper functions. |
| backend/src/server.ts | Switches startup log to logger.info. |
| backend/src/routes/notes.ts | Replaces route error logging with logger.error and renames caught error to err. |
| backend/src/routes/auth.ts | Replaces route error logging with logger.error and renames caught error to err. |
| backend/pnpm-lock.yaml | Adds a pnpm lockfile for backend dependencies. |
Files not reviewed (1)
- backend/pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export const info = (...args: any[]) => { | ||
| console.log(...args); | ||
| }; | ||
| export const error = (...args: any[]) => { | ||
| console.error(...args); | ||
| }; | ||
| export const warn = (...args: any[]) => { | ||
| console.warn(...args); | ||
| }; | ||
| export const debug = (...args: any[]) => { |
There was a problem hiding this comment.
logger uses any[] for arguments, which defeats strict typing and makes it easy to accidentally log values with unsafe assumptions. Prefer typing the rest parameters as unknown[] or (even better) Parameters<typeof console.log> / Parameters<typeof console.error> so call sites stay type-safe while still matching console behavior.
| exportconstinfo=(...args: any[])=>{ | |
| console.log(...args); | |
| }; | |
| exportconsterror=(...args: any[])=>{ | |
| console.error(...args); | |
| }; | |
| exportconstwarn=(...args: any[])=>{ | |
| console.warn(...args); | |
| }; | |
| exportconstdebug=(...args: any[])=>{ | |
| exportconstinfo=(...args: Parameters<typeofconsole.log>)=>{ | |
| console.log(...args); | |
| }; | |
| exportconsterror=(...args: Parameters<typeofconsole.error>)=>{ | |
| console.error(...args); | |
| }; | |
| exportconstwarn=(...args: Parameters<typeofconsole.warn>)=>{ | |
| console.warn(...args); | |
| }; | |
| exportconstdebug=(...args: Parameters<typeofconsole.debug>)=>{ |
There was a problem hiding this comment.
Changed all logger function rest parameters from any[] to unknown[]. TypeScript compiles clean.
There was a problem hiding this comment.
I've updated backend/src/utils/logger.ts to use unknown[] for better type safety as requested. Thank you!
| lockfileVersion: '9.0' | ||
| settings: | ||
| autoInstallPeers: true | ||
| excludeLinksFromLockfile: false |
There was a problem hiding this comment.
This adds a pnpm-lock.yaml while the backend already has package-lock.json. Having multiple lockfiles for the same package.json can cause inconsistent dependency resolution across environments/CI. Either remove pnpm-lock.yaml (if the project standard is npm) or migrate fully to pnpm and delete package-lock.json + update tooling/docs accordingly.
There was a problem hiding this comment.
Removed pnpm-lock.yaml. This repo uses npm with package-lock.json.
There was a problem hiding this comment.
Apologies for the oversight. I've removed backend/pnpm-lock.yaml and ensured that package-lock.json is used instead, following the repository standards.
- Updated `backend/src/utils/logger.ts` to use `unknown[]` instead of `any[]` for better type safety. - Removed `backend/pnpm-lock.yaml` as the repository standard is `npm` with `package-lock.json`. - Updated `backend/package-lock.json` via `npm install`. Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
This PR improves the code health of the backend by standardizing logging. Instead of using
console.logandconsole.errordirectly throughout the codebase, we now use a centralized logger utility.🎯 What:
consolemethods inbackend/src/utils/logger.ts.consolecalls inauth.ts,notes.ts, andserver.tswith calls to the new logger utility.errorvariable in catch blocks toerrwhere modifications were made to improve clarity and consistency.💡 Why:
✅ Verification:
loggerutility works correctly using a standalone script executed withbun.consolecalls (except within the logger itself) have been replaced usinggrep.pnpm installand attemptedpnpm run buildto ensure no syntax errors were introduced.✨ Result:
PR created automatically by Jules for task 4467161664679516936 started by @davidraehles