fix(config): resolve circular import in unified config
- Replace direct logger import with dynamic import pattern - Add withLogger utility to handle async logger initialization - Prevent module loading issues during configuration bootstrap - Maintain logging functionality while avoiding circular dependencies
This commit is contained in:
@@ -1,4 +1,20 @@
|
|||||||
import { logger } from '../services/logging';
|
type LoggerInstance = (typeof import('../services/logging'))['logger'];
|
||||||
|
|
||||||
|
let loggerPromise: Promise<LoggerInstance | null> | null = null;
|
||||||
|
|
||||||
|
function withLogger(callback: (logger: LoggerInstance) => void): void {
|
||||||
|
if (!loggerPromise) {
|
||||||
|
loggerPromise = import('../services/logging')
|
||||||
|
.then(module => module.logger)
|
||||||
|
.catch(() => null);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loggerPromise.then(logger => {
|
||||||
|
if (logger) {
|
||||||
|
callback(logger);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unified Application Configuration System
|
* Unified Application Configuration System
|
||||||
@@ -756,10 +772,14 @@ function validateConfig(config: UnifiedConfig): void {
|
|||||||
|
|
||||||
// Log warnings and throw errors
|
// Log warnings and throw errors
|
||||||
if (warnings.length > 0) {
|
if (warnings.length > 0) {
|
||||||
logger.warn('Configuration warnings', 'CONFIG', warnings);
|
withLogger(logger =>
|
||||||
|
logger.warn('Configuration warnings', 'CONFIG', warnings)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
logger.error('Configuration errors', 'CONFIG', errors);
|
withLogger(logger =>
|
||||||
|
logger.error('Configuration errors', 'CONFIG', errors)
|
||||||
|
);
|
||||||
throw new Error(`Configuration validation failed: ${errors.join(', ')}`);
|
throw new Error(`Configuration validation failed: ${errors.join(', ')}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -957,7 +977,11 @@ export function exportAsEnvVars(
|
|||||||
* Debug helper to log current configuration
|
* Debug helper to log current configuration
|
||||||
*/
|
*/
|
||||||
export function logConfig(): void {
|
export function logConfig(): void {
|
||||||
if (unifiedConfig.features.debugMode) {
|
if (!unifiedConfig.features.debugMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
withLogger(logger =>
|
||||||
logger.info('Unified Configuration (Single Source of Truth)', 'CONFIG', {
|
logger.info('Unified Configuration (Single Source of Truth)', 'CONFIG', {
|
||||||
environment: unifiedConfig.app.environment,
|
environment: unifiedConfig.app.environment,
|
||||||
app: unifiedConfig.app.name,
|
app: unifiedConfig.app.name,
|
||||||
@@ -974,8 +998,8 @@ export function logConfig(): void {
|
|||||||
},
|
},
|
||||||
features: unifiedConfig.features,
|
features: unifiedConfig.features,
|
||||||
configSource: '.env file overrides applied',
|
configSource: '.env file overrides applied',
|
||||||
});
|
})
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto-log in development
|
// Auto-log in development
|
||||||
|
|||||||
Reference in New Issue
Block a user