Skip to content

Conversation

yamadashy
Copy link
Owner

Fixes duplicate logging issue in production environment where logs appeared twice in monitoring systems.

Summary

  • Root Cause: Both Cloud Logging transport and Console transport were active simultaneously in production, causing duplicate log entries
  • Solution: Separate transport configuration by environment:
    • Production: Use only Cloud Logging transport
    • Development: Use only Console transport
  • Impact: Eliminates log duplication in production monitoring while preserving local development debugging

Changes

  • Modified website/server/src/utils/logger.ts to conditionally configure winston transports based on NODE_ENV
  • Production environments now use Cloud Logging exclusively
  • Development environments continue using console logging for debugging

Checklist

  • Run npm run test
  • Run npm run lint

@Copilot Copilot AI review requested due to automatic review settings August 24, 2025 15:31
Copy link
Contributor

coderabbitai bot commented Aug 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Refactors logger initialization to select transports based on environment: production uses Cloud Logging via LoggingWinston; development uses a Console transport with timestamp and JSON formatting. The logger level logic and public API remain unchanged.

Changes

Cohort / File(s) Summary
Logger configuration
website/server/src/utils/logger.ts
Initializes transports as empty, adds LoggingWinston in production, Console transport with timestamp+JSON in development; retains existing logger level logic and other helpers; no exported API changes.

Sequence Diagram(s)

sequenceDiagram
  actor App
  participant Logger
  participant Console as Console Transport
  participant Cloud as Cloud Logging (LoggingWinston)

  Note over Logger: Initialization

  App->>Logger: create logger
  alt NODE_ENV=production
    Logger->>Cloud: attach transport
  else development/other
    Logger->>Console: attach transport
  end

  Note over Logger: Usage

  App->>Logger: log(message, meta)
  alt production
    Logger->>Cloud: write entry
  else development
    Logger->>Console: write line (timestamp + JSON)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/website-log

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @yamadashy, 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 addresses an issue where logs were duplicated in production environments. The fix involves refining the logging configuration to ensure that only the appropriate logging transport is active based on the deployment environment, thereby streamlining log collection and preventing redundant entries.

Highlights

  • Logging Duplication Fix: Resolves the problem of duplicate log entries appearing in production monitoring systems by ensuring only one logging transport is active.
  • Environment-Specific Logging: Implements conditional logic within the createLogger function to activate different logging transports based on the NODE_ENV environment variable.
  • Production Logging: Configures production environments to exclusively use Cloud Logging, preventing redundant console output.
  • Development Logging: Ensures development environments continue to use console logging for local debugging purposes, without interfering with production logs.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

claude bot commented Aug 24, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a duplicate logging issue in production where logs were appearing twice in monitoring systems. The root cause was having both Cloud Logging and Console transports active simultaneously in production.

  • Refactored logger configuration to use environment-specific transports
  • Production environments now use only Cloud Logging transport to eliminate duplicates
  • Development environments continue using console logging for local debugging

Comment on lines 5 to 9
// Configure transports based on environment
function createLogger() {
const transports: winston.transport[] = [
new winston.transports.Console({
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
}),
];
const transports: winston.transport[] = [];

// Add Cloud Logging transport only in production
if (process.env.NODE_ENV === 'production') {
Copy link
Preview

Copilot AI Aug 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using a more robust environment check or constants to avoid magic strings. For example, define a constant like const IS_PRODUCTION = process.env.NODE_ENV === 'production' or use an environment configuration utility.

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Aug 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.41%. Comparing base (8cf2b3e) to head (4e20fc5).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #805   +/-   ##
=======================================
  Coverage   87.41%   87.41%           
=======================================
  Files         113      113           
  Lines        6493     6493           
  Branches     1331     1331           
=======================================
  Hits         5676     5676           
  Misses        817      817           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

cloudflare-workers-and-pages bot commented Aug 24, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4e20fc5
Status: ✅  Deploy successful!
Preview URL: https://b4122c69.repomix.pages.dev
Branch Preview URL: https://feat-website-log.repomix.pages.dev

View logs

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly resolves the duplicate logging issue in production by conditionally configuring Winston transports based on NODE_ENV. The logic is sound and effectively separates production from development logging. I have provided one suggestion to refactor the implementation for improved conciseness and maintainability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
website/server/src/utils/logger.ts (2)

7-7: Nit: Consider typing transports as TransportStream[] for clearer intent.

Some setups’ TS typings are happier with the explicit TransportStream type, and it reads cleaner when mixing community transports like LoggingWinston.

Apply within the selected line range:

-  const transports: winston.transport[] = [];
+  const transports: TransportStream[] = [];

Add the supporting import at the top of the file:

import type TransportStream from 'winston-transport';

13-20: Optional: Silence logs during tests to keep CI output clean.

If your test runner sets NODE_ENV=test, adding a test-specific branch helps avoid noisy logs and speeds up log-heavy suites.

-  } else {
-    // In development, use console logging
-    transports.push(
-      new winston.transports.Console({
-        format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
-      }),
-    );
-  }
+  } else if (process.env.NODE_ENV === 'test') {
+    // In tests, silence logging
+    transports.push(
+      new winston.transports.Console({
+        silent: true,
+      }),
+    );
+  } else {
+    // In development, use console logging
+    transports.push(
+      new winston.transports.Console({
+        format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
+      }),
+    );
+  }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4d166b5 and 2ae3034.

📒 Files selected for processing (1)
  • website/server/src/utils/logger.ts (1 hunks)
🔇 Additional comments (2)
website/server/src/utils/logger.ts (2)

10-20: Production-only Cloud Logging and dev-only Console fixes the double logs — LGTM.

This environment-based transport split directly addresses the duplication in production while preserving local console output. No functional concerns here.


10-20: All logging is centralized in utils/logger.ts—no stray instances found
A repository-wide search confirms only website/server/src/utils/logger.ts contains winston.createLogger, LoggingWinston, new winston.transports.Console, or direct winston.<level> calls. No other logger initializations or transports exist elsewhere, so duplicates are avoided.

- Separate transport configuration for production and development
- Production: Use only Cloud Logging transport to prevent duplicates
- Development: Use only Console transport for local debugging
- Fixes issue where Cloud Logging and Console transports caused duplicate log entries
- Extract isProduction constant to avoid magic strings
- Use ternary operator for more concise transport initialization
- Reuse isProduction constant for log level configuration
- Improve code readability and maintainability

Addresses feedback from @Copilot and @gemini-code-assist[bot]
@yamadashy yamadashy merged commit 083e3ed into main Aug 25, 2025
57 checks passed
@yamadashy yamadashy deleted the feat/website-log branch August 25, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant