UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

152 lines 4.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.globalLoggerManager = exports.LoggerManager = void 0; exports.initLogger = initLogger; exports.getDomainLogger = getDomainLogger; exports.getComponentLogger = getComponentLogger; exports.setGlobalLogLevel = setGlobalLogLevel; exports.setGlobalCallerEnabled = setGlobalCallerEnabled; exports.setGlobalJsonFormat = setGlobalJsonFormat; const logger_1 = require("./logger"); const types_1 = require("./types"); /** * Global Logger Manager * Manages logger instances across different domains with unified configuration */ class LoggerManager { constructor() { // Default global configuration this.globalConfig = { level: types_1.LogLevel.DEBUG, enableCaller: true, jsonFormat: true }; this.loggers = new Map(); } /** * Get the singleton instance of LoggerManager */ static getInstance() { if (!LoggerManager.instance) { LoggerManager.instance = new LoggerManager(); } return LoggerManager.instance; } /** * Set global logger configuration * This affects all new logger instances created after this call */ setGlobalConfig(config) { this.globalConfig = { ...this.globalConfig, ...config }; // Update existing loggers with new config this.loggers.clear(); // Clear cache to force recreation with new config } /** * Get global logger configuration */ getGlobalConfig() { return { ...this.globalConfig }; } /** * Get logger for a specific domain/component * Creates and caches logger instances per domain */ getLogger(domain, additionalFields) { const cacheKey = domain + (additionalFields ? JSON.stringify(additionalFields) : ''); if (!this.loggers.has(cacheKey)) { const logger = (0, logger_1.NewWithConfig)(this.globalConfig); // Add domain field and any additional fields const fields = { domain, ...additionalFields }; const domainLogger = logger.with(fields); this.loggers.set(cacheKey, domainLogger); } return this.loggers.get(cacheKey); } /** * Get logger for a specific domain with component information */ getComponentLogger(domain, component, additionalFields) { const fields = { component, ...additionalFields }; return this.getLogger(domain, fields); } /** * Clear all cached loggers * Useful when you want to force recreation with new configuration */ clearCache() { this.loggers.clear(); } /** * Get all cached logger domains */ getCachedDomains() { return Array.from(this.loggers.keys()); } /** * Set log level for all existing and future loggers */ setLogLevel(level) { this.setGlobalConfig({ level }); } /** * Enable or disable caller information for all loggers */ setCallerEnabled(enabled) { this.setGlobalConfig({ enableCaller: enabled }); } /** * Set JSON format for all loggers */ setJsonFormat(enabled) { this.setGlobalConfig({ jsonFormat: enabled }); } } exports.LoggerManager = LoggerManager; // Global instance for easy access const globalLoggerManager = LoggerManager.getInstance(); exports.globalLoggerManager = globalLoggerManager; /** * Initialize global logger configuration * Call this once at application startup */ function initLogger(config) { globalLoggerManager.setGlobalConfig(config); } /** * Get logger for a domain * Convenience function to avoid accessing LoggerManager directly */ function getDomainLogger(domain, additionalFields) { return globalLoggerManager.getLogger(domain, additionalFields); } /** * Get logger for a specific component within a domain */ function getComponentLogger(domain, component, additionalFields) { return globalLoggerManager.getComponentLogger(domain, component, additionalFields); } /** * Set global log level */ function setGlobalLogLevel(level) { globalLoggerManager.setLogLevel(level); } /** * Enable or disable caller information globally */ function setGlobalCallerEnabled(enabled) { globalLoggerManager.setCallerEnabled(enabled); } /** * Set JSON format globally */ function setGlobalJsonFormat(enabled) { globalLoggerManager.setJsonFormat(enabled); } //# sourceMappingURL=manager.js.map