Allow config overrides for logging and silence warn toasts#68
Allow config overrides for logging and silence warn toasts#68riatzukiza merged 5 commits intodevfrom
Conversation
Summary by CodeRabbitRelease Notes
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughAdds a nested logging section to plugin config and merges it with defaults, converts static logging flags into mutable state with runtime overrides, replaces exported LOGGING_ENABLED with isLoggingEnabled(), and updates tests and call sites to use the new API and behavior. Changes
Sequence Diagram(s)sequenceDiagram
participant Init as Plugin Init
participant Config as Config Loader
participant Logger as Logger
participant State as Logging State
Init->>Config: loadPluginConfig()
Note right of Config: Read user config file\nShallow-copy DEFAULT_CONFIG\nMerge DEFAULT_CONFIG.logging with userConfig.logging
Config-->>Init: PluginConfig { logging: { ... } }
Init->>Logger: configureLogger({ pluginConfig })
Logger->>Logger: applyLoggingOverrides(pluginConfig.logging)
Logger->>State: update mutable flags (debug, enableRequestLogging,\nshowWarningToasts, rotation, queue)
Logger->>Logger: refreshLoggingState()
Logger-->>Init: configured
Init->>Logger: handleRequest()/emitWarning()
alt isLoggingEnabled()
Logger->>Logger: log to file/queue
end
alt warnToastEnabled
Logger->>Init: show toast
else
Logger->>Logger: forward to app log or console
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)test/logger.test.ts (1)
🔇 Additional comments (3)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
index.tsis excluded by none and included by nonespec/environment-variables.mdis excluded by none and included by none
📒 Files selected for processing (5)
lib/config.ts(2 hunks)lib/logger.ts(6 hunks)lib/types.ts(1 hunks)test/logger.test.ts(4 hunks)test/plugin-config.test.ts(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
lib/config.ts (2)
lib/types.ts (1)
PluginConfig(6-40)lib/logger.ts (1)
logWarn(154-156)
test/logger.test.ts (1)
lib/logger.ts (4)
configureLogger(103-125)logRequest(127-144)flushRollingLogsForTest(162-167)logWarn(154-156)
lib/logger.ts (2)
lib/utils/file-system-utils.ts (1)
getOpenCodePath(22-24)lib/types.ts (2)
PluginConfig(6-40)LoggingConfig(42-55)
test/plugin-config.test.ts (1)
lib/config.ts (1)
loadPluginConfig(30-70)
🔇 Additional comments (18)
lib/logger.ts (8)
4-4: LGTM: Type imports align with new configuration surface.The imports for
LoggingConfigandPluginConfigsupport the new pluginConfig-based override mechanism.
12-19: Good consolidation of environment-based defaults.Centralizing environment variable parsing into
envLoggingDefaultsimproves maintainability and makes the configuration source clearer.
61-71: LGTM: Helper functions implement correct validation and state refresh logic.
refreshLoggingState()properly recomputes derived flags from base configurationensurePositiveNumber()provides robust validation with appropriate fallback handling
73-86: LGTM: Override logic correctly handles partial configuration.The nullish coalescing operator (
??) ensures that undefined config values preserve existing settings, while explicitfalsevalues are applied as intended. Numeric validation throughensurePositiveNumberprevents invalid configuration.
32-36: LGTM: LoggerOptions extension maintains backward compatibility.Adding optional
pluginConfigparameter allows configuration-driven overrides without breaking existing usage.
103-110: LGTM: configureLogger correctly applies plugin-based overrides.The call to
applyLoggingOverrides(options.pluginConfig?.logging)safely handles undefined values and applies configuration before any logging occurs.
169-208: LGTM: Warning toast behavior correctly implements opt-in configuration.The updated logic ensures warning toasts are only displayed when explicitly enabled via configuration (
WARN_TOASTS_ENABLED), while error toasts remain always enabled. This prevents noisy warnings while preserving critical error notifications.The three-way routing (app log, toast, console) for warning-level messages is correct:
- When toasts disabled: warnings → app log + console
- When toasts enabled: warnings → toast only (no app log, no console)
88-88: LGTM: Initial state refresh ensures derived flags are computed.Calling
refreshLoggingState()at module initialization correctly establishesDEBUG_ENABLEDandCONSOLE_LOGGING_ENABLEDfrom the environment-based defaults.lib/types.ts (1)
36-55: LGTM: Type definitions correctly model optional configuration overrides.The
LoggingConfiginterface with all optional fields properly supports partial overrides, and the JSDoc comments clearly document the purpose of each field.lib/config.ts (3)
17-19: LGTM: Default logging configuration establishes sensible baseline.Setting
showWarningToasts: falseby default prevents noisy notifications while allowing explicit opt-in via configuration.
41-61: LGTM: Nested merge logic correctly preserves defaults and applies overrides.The configuration loading properly:
- Shallow-copies
DEFAULT_CONFIGto prevent mutation (line 45)- Extracts user logging settings with safe fallback (line 50)
- Creates a new logging object merging defaults with user values (lines 56-59), ensuring user settings take precedence
This approach correctly handles partial overrides (e.g., only
debug: truewhile preservingshowWarningToasts: falsedefault).
62-69: LGTM: Error handling preserves defaults safely.Shallow-copying
DEFAULT_CONFIGon errors prevents DEFAULT_CONFIG mutation and ensures the cached config remains independent.test/plugin-config.test.ts (2)
47-63: LGTM: Test correctly validates default configuration shape.The test properly verifies that missing configuration files result in the default configuration including
logging: { showWarningToasts: false }.
95-108: LGTM: Nested merge test validates partial override behavior.This test correctly verifies that user-provided logging fields merge with defaults, ensuring partial configuration works as expected. Good coverage of the nested merge logic.
test/logger.test.ts (4)
110-122: LGTM: Test correctly validates configuration override priority.This test properly verifies that
pluginConfig.logging.enableRequestLogging: falseoverrides the environment variable, ensuring no disk writes occur when explicitly disabled via configuration.
146-165: LGTM: Test validates default warning toast behavior is disabled.The test correctly verifies that warning toasts are not displayed by default (even with TUI support), and that warnings are instead routed to app.log and console. This aligns with the PR objective to reduce noise.
167-192: LGTM: Test validates opt-in warning toast configuration.This test properly confirms that warning toasts are displayed only when explicitly enabled via
pluginConfig.logging.showWarningToasts: true, and that duplicate logging (to app.log and console) is suppressed when toasts are enabled.
194-219: LGTM: Long message wrapping test updated for opt-in behavior.The test correctly includes
showWarningToasts: truein the configuration to enable toast display before testing message wrapping functionality.
|
/oc In lib/logger.ts around line 21, exported mutable variable LOGGING_ENABLED is |
|
Excellent! All tests are passing. Let me create a summary of the changes made: SummaryI have successfully implemented the requested changes to fix the unsafe exported mutable variable Changes Made:
Benefits:
Verification:
The change maintains backward compatibility for functionality while improving the safety and encapsulation of the logging system. |
Co-authored-by: riatzukiza <riatzukiza@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
test/README.md (1)
78-85: Logger tests description now matches API; consider mentioning new config behaviorSwitching the bullet to
isLoggingEnabled()correctly reflects the new logger surface. As a follow‑up, you might also call out that logger tests now cover config‑driven logging overrides and warning‑toast behavior so this section stays in sync with future changes.test/logger.test.ts (2)
38-45: ResetCODEX_SHOW_WARNING_TOASTSinbeforeEachto avoid flaky toast testsThe new warning‑toast tests assume
CODEX_SHOW_WARNING_TOASTSis unset/false, butbeforeEachonly deletes the older logging env vars. If a developer or CI environment setsCODEX_SHOW_WARNING_TOASTS=1, tests around “no toast by default” will fail spuriously.Consider adding this to the setup:
beforeEach(() => { vi.resetModules(); Object.assign(process.env, originalEnv); delete process.env.ENABLE_PLUGIN_REQUEST_LOGGING; delete process.env.DEBUG_CODEX_PLUGIN; delete process.env.CODEX_LOG_MAX_BYTES; delete process.env.CODEX_LOG_MAX_FILES; delete process.env.CODEX_LOG_QUEUE_MAX; + delete process.env.CODEX_SHOW_WARNING_TOASTS;Also applies to: 146-192
146-165: Warning‑toast tests accurately codify the new behavior; confirm you’re okay with replacing app/console logsThe toast‑focused tests correctly exercise the intended behavior:
- By default,
logWarnroutes throughapp.logand console, with no toast even when TUI is present.- When
pluginConfig.logging.showWarningToastsis true, warnings go to toasts only (noapp.logand no console) and long messages are wrapped.This is a deliberate trade‑off: enabling warning toasts means you no longer see those warnings in
app.logor on the console unless request/debug logging is also on. If you ever want both toast and structured/app logging for warnings, you may want to relax theshouldForwardToAppLog/shouldLogToConsoleconditions instead of treating toasts as a replacement.Also applies to: 167-192, 205-205
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.jsonand included by none
📒 Files selected for processing (5)
lib/logger.ts(6 hunks)lib/request/response-handler.ts(2 hunks)test/README.md(1 hunks)test/cache-warming.test.ts(1 hunks)test/logger.test.ts(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
lib/request/response-handler.ts (1)
lib/logger.ts (1)
isLoggingEnabled(22-24)
test/logger.test.ts (1)
lib/logger.ts (5)
isLoggingEnabled(22-24)configureLogger(106-128)logRequest(130-147)flushRollingLogsForTest(165-170)logWarn(157-159)
lib/logger.ts (2)
lib/utils/file-system-utils.ts (1)
getOpenCodePath(22-24)lib/types.ts (2)
PluginConfig(6-40)LoggingConfig(42-55)
🔇 Additional comments (2)
lib/request/response-handler.ts (1)
2-2: Use ofisLoggingEnabled()here looks correct and side‑effect freeThe import and guard now rely on the accessor instead of a mutable export, preserving the previous behavior while aligning with the safer logger API.
Also applies to: 53-55
test/cache-warming.test.ts (1)
19-24: Logger mock update matches new API surfaceExposing
isLoggingEnabled: () => falsekeeps the mock compatible with the logger module without affecting existing cache‑warming assertions.
|
/oc In test/logger.test.ts around lines 68 to 72, add an extra assertion to validate |
|
ProviderInitError |
|
/oc In test/logger.test.ts around lines 68 to 72, add an extra assertion to validate |
|
Excellent! The changes have been successfully implemented. Here's a summary of what was added: SummaryI've added the requested assertions to validate that Changes Made:
Verification:
These changes strengthen the test coverage by explicitly verifying that the |
Co-authored-by: riatzukiza <riatzukiza@users.noreply.github.com>


Summary