🧹 replace console logging with centralized logger#42
Conversation
|
👋 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. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new centralized logging utility to standardize error and warning messages across the codebase. The primary goal is to improve maintainability, security, and readability by replacing direct Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request replaces direct console.log calls with a centralized logger. My review focuses on the implementation of the new logger utility. I've found a potential security issue where nested Error objects might not be sanitized, and I've provided a suggestion to improve the implementation to make it more robust.
| const formatArg = (arg: unknown): unknown => { | ||
| if (arg instanceof Error) { | ||
| return arg.message; | ||
| } | ||
| return arg; | ||
| }; |
There was a problem hiding this comment.
The current formatArg implementation only sanitizes top-level Error objects. If an Error object is nested within another object, it will be logged along with its stack trace, which could leak sensitive information. This doesn't fully meet the security goal of preventing accidental exposure of sensitive data.
To make the logger more robust, I suggest implementing a recursive sanitization function that traverses nested objects and arrays, sanitizes any Error instances it finds, and handles circular references.
const formatArg = (arg: unknown): unknown => {
const sanitize = (value: unknown, seen: WeakSet<object>): unknown => {
if (value instanceof Error) {
return value.message;
}
if (typeof value !== "object" || value === null) {
return value;
}
if (seen.has(value)) {
return "[Circular]";
}
seen.add(value);
if (Array.isArray(value)) {
return value.map((item) => sanitize(item, seen));
}
const sanitizedObject: { [key: string]: unknown } = {};
for (const key of Object.keys(value)) {
sanitizedObject[key] = sanitize((value as Record<string, unknown>)[key], seen);
}
return sanitizedObject;
};
return sanitize(arg, new WeakSet());
};
Review: 🔴 要修正致命的: スタックトレースの消失
// 現状: スタックトレースが消える
const formatArg = (arg: unknown): unknown => {
if (arg instanceof Error) {
return arg.message; // ← stack が失われる
}
return arg;
};最低限、以下のいずれかが必要です:
その他
スタックトレース問題を修正してから再レビューお願いします。 |
Thank you for the feedback. I have addressed the points as follows:
Please review the updated implementation. |
Re-review: ✅ 修正済み
マージ可能です。 |
- Created a centralized logger utility in `src/lib/logger.ts`. - Replaced `console.error` and `console.warn` with the new logger across the codebase. - Ensured security compliance by automatically formatting Error objects to log only their messages. - Standardized logging patterns in API routes and React hooks. Co-authored-by: kwrkb <49333683+kwrkb@users.noreply.github.com>
- Updated `src/lib/logger.ts` to include full stack traces for Error objects. - Added ISO timestamps and log level prefixes ([INFO], [WARN], [ERROR]) for better traceability. - Addressed PR feedback regarding stack trace loss and logger utility. Co-authored-by: kwrkb <49333683+kwrkb@users.noreply.github.com>
formatArg was stripping Error objects down to message-only, losing the error name (TypeError, RangeError, etc.). Now outputs "ErrorName: message" for better debuggability while still sanitizing stack traces. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Thank you for the re-review. I have removed the timestamp prefixes as suggested, since Next.js/dev server provides sufficient context. The logger now focuses on log level prefixes and stack trace preservation. |
785df24 to
6e7a8b5
Compare
💡 Codex Reviewhttps://github.com/kwrkb/gen-jigsaw/blob/785df24804e073cd0c6e9ed3012d5bfd0448bea9/src/app/api/rooms/[id]/route.ts#L12-L13 Adding a hard 401 here can strand first-time visitors on the room page: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🎯 What
Replaced raw
console.errorandconsole.warnstatements with a centralizedloggerutility insrc/lib/logger.ts.💡 Why
✅ Verification
loggerutility with a standalone script usingbunto confirm correct handling of strings, objects, andErrorobjects.bun testfor available tests. Note: fullnpm run testandtscwere limited by environment-specificnode_modulesissues, but core functionality was verified withbun.✨ Result
The codebase now uses a consistent, secure, and extensible logging pattern.
PR created automatically by Jules for task 5488992365948415776 started by @kwrkb