RFC: allow users to pass a custom logger to init#2745
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an injectable Logger across client packages: core logging accepts a baseLogger, Config/InstantConfig types gain an optional logger field, Reactor and admin database wire the injected logger, framework packages re-export the Logger type, and the package version is bumped. ChangesCustom Logger Injection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View Vercel preview at instant-www-js-custom-logger-jsv.vercel.app. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
client/packages/admin/src/index.ts (1)
1107-1116: ⚡ Quick winConsider importing createLogger from core to reduce duplication.
The admin package defines its own
createLoggerhelper, but the core package already exports a similar function (seeclient/packages/core/src/utils/log.ts). The core version includes agetStatsparameter for appending diagnostic info to logs, which the admin version omits.If the admin package doesn't need stats, you could:
- Import the core
createLoggerand pass a no-opgetStats: () => ({}), or- Propose making
getStatsoptional in the core version with a default no-opThis would eliminate duplication and ensure consistent logger behavior across packages.
♻️ Example: Import from core
+import createLogger from '`@instantdb/core/src/utils/log`'; + class InstantAdminDatabase<...> { ... constructor(_config: Config) { ... - this.#log = createLogger(!!this.config.verbose, this.config.logger); + this.#log = createLogger( + !!this.config.verbose, + () => ({}), // no-op getStats + this.config.logger, + ); } } - -function createLogger( - isEnabled: boolean, - baseLogger: Logger = console, -): Logger { - return { - info: isEnabled ? (...args: any[]) => baseLogger.info(...args) : () => {}, - debug: isEnabled ? (...args: any[]) => baseLogger.debug(...args) : () => {}, - error: isEnabled ? (...args: any[]) => baseLogger.error(...args) : () => {}, - }; -}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@client/packages/admin/src/index.ts` around lines 1107 - 1116, The admin package redefines createLogger, duplicating logic from core's createLogger (see client/packages/core/src/utils/log.ts) which accepts an additional getStats parameter; fix by removing the local createLogger and importing the core createLogger into client/packages/admin/src/index.ts, calling it with the same isEnabled and baseLogger arguments and supplying a no-op getStats (() => ({})) if admin doesn't need stats — alternatively, change the core createLogger signature to make getStats optional with a default no-op so admin can import and call it unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@client/packages/admin/src/index.ts`:
- Around line 1107-1116: The admin package redefines createLogger, duplicating
logic from core's createLogger (see client/packages/core/src/utils/log.ts) which
accepts an additional getStats parameter; fix by removing the local createLogger
and importing the core createLogger into client/packages/admin/src/index.ts,
calling it with the same isEnabled and baseLogger arguments and supplying a
no-op getStats (() => ({})) if admin doesn't need stats — alternatively, change
the core createLogger signature to make getStats optional with a default no-op
so admin can import and call it unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0ce2225d-e475-4fa7-ab8d-70c53f6fc755
📒 Files selected for processing (9)
client/packages/admin/src/index.tsclient/packages/core/src/Reactor.jsclient/packages/core/src/index.tsclient/packages/core/src/utils/log.tsclient/packages/react-native/src/index.tsclient/packages/react/src/index.tsclient/packages/solidjs/src/index.tsclient/packages/svelte/src/lib/index.tsclient/packages/vue/src/index.ts
This is an attempt to address #2742 without making the logs harder to read in the devtools console.
Users can pass a custom logger where they format things however they like. If you wanted to JSON stringify, you might do:
Or if you just wanted to json.stringify objects, you could do: