Skip to content

Conversation

@adelrodriguez
Copy link
Collaborator

@adelrodriguez adelrodriguez commented Feb 1, 2026

Greptile Overview

Greptile Summary

Refactored logger initialization from global configuration to per-app singleton pattern with lazy initialization. Each app now configures only the logger categories it needs, improving performance and reducing overhead.

  • Replaced configureLogger()/configureLoggerAsync() with new buildLogger() function that configures specific categories per app
  • Introduced singleton pattern for logger instances to prevent re-initialization across module imports
  • Moved from eager global configuration to lazy initialization on first logger use
  • Added LoggerCategory.EMAIL and removed unused LoggerCategory.SECURITY
  • Fixed hardcoded category string in workflows package to use LoggerCategory.INNGEST constant
  • Apps now configure async logging only where needed (API server and app server-side)
  • Client-side apps (desktop, extension, mobile, app client) use synchronous logging for immediate console output

Confidence Score: 5/5

  • This PR is safe to merge with no concerns
  • Clean refactoring that improves architecture by making logger configuration explicit per-app. All changes follow consistent patterns, unused code removed, and hardcoded strings replaced with constants. No logic errors or breaking changes detected.
  • No files require special attention

Important Files Changed

Filename Overview
packages/observability/src/logger/index.ts Replaced global config functions with buildLogger() that configures specific categories per app, removed unused SECURITY category, added EMAIL category
apps/api/src/shared/logger.ts New file that creates singleton logger instance with async configuration for all API-needed categories
apps/app/src/shared/logger.ts Replaced getLogger() with singleton pattern, async only on server-side (checks globalThis.window)
packages/email/src/client.ts Changed from global logger import to getLogger(LoggerCategory.EMAIL) for email-specific logging
packages/workflows/src/client.ts Fixed hardcoded array ["inngest"] to use LoggerCategory.INNGEST constant

Sequence Diagram

sequenceDiagram
    participant App as Application Entry Point
    participant Logger as app/shared/logger.ts
    participant Singleton as @init/utils/singleton
    participant Builder as @init/observability/logger
    participant LogTape as @logtape/logtape

    Note over App,LogTape: Before: Eager Global Initialization
    App->>Builder: configureLogger() / configureLoggerAsync()
    Builder->>LogTape: configure() / configureSync() with all categories
    Note over LogTape: All categories configured globally

    Note over App,LogTape: After: Lazy Per-App Initialization
    App->>Logger: import { logger }
    Logger->>Singleton: singleton("logger:app", buildLogger)
    alt First access
        Singleton->>Builder: buildLogger(categories, options)
        Builder->>Builder: Filter LOGGER_CONFIGS by categories
        Builder->>LogTape: configure() / configureSync() with filtered config
        LogTape-->>Builder: configured
        Builder->>LogTape: getLogger(defaultCategory)
        LogTape-->>Builder: logger instance
        Builder-->>Singleton: logger instance
        Singleton-->>Logger: cached logger
    else Subsequent access
        Singleton-->>Logger: cached logger (from globalThis.__remember_init)
    end
    Logger-->>App: logger instance
Loading

@adelrodriguez adelrodriguez marked this pull request as ready for review February 1, 2026 17:57
@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

Important

Review skipped

Auto 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.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor_improve_logger_initialization_and_configuration

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator Author

adelrodriguez commented Feb 1, 2026

@adelrodriguez adelrodriguez force-pushed the refactor_improve_logger_initialization_and_configuration branch from 9a07a34 to dec9aab Compare February 1, 2026 19:10
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Base automatically changed from refactor_centralize_environment_variable_handling_with_tooling/env to main February 1, 2026 19:27
@adelrodriguez adelrodriguez force-pushed the refactor_improve_logger_initialization_and_configuration branch from dec9aab to dff01d7 Compare February 1, 2026 19:29
@adelrodriguez adelrodriguez merged commit 575d313 into main Feb 1, 2026
8 checks passed
@adelrodriguez adelrodriguez deleted the refactor_improve_logger_initialization_and_configuration branch February 1, 2026 19:44
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.

2 participants