UNPKG

@xtr-dev/payload-mailing

Version:

Template-based email system with scheduling and job processing for PayloadCMS

40 lines (39 loc) 1.63 kB
let pluginLogger = null; /** * Get or create the plugin logger instance * Uses PAYLOAD_MAILING_LOG_LEVEL environment variable to configure log level * Defaults to 'info' if not set */ export function getPluginLogger(payload) { if (!pluginLogger && payload.logger) { const logLevel = process.env.PAYLOAD_MAILING_LOG_LEVEL || 'info'; pluginLogger = payload.logger.child({ level: logLevel, plugin: '@xtr-dev/payload-mailing' }); // Log the configured log level on first initialization pluginLogger.info(`Logger initialized with level: ${logLevel}`); } // Fallback to console if logger not available (shouldn't happen in normal operation) if (!pluginLogger) { return { debug: (...args) => console.log('[MAILING DEBUG]', ...args), info: (...args) => console.log('[MAILING INFO]', ...args), warn: (...args) => console.warn('[MAILING WARN]', ...args), error: (...args) => console.error('[MAILING ERROR]', ...args), }; } return pluginLogger; } /** * Create a context-specific logger for a particular operation */ export function createContextLogger(payload, context) { const logger = getPluginLogger(payload); return { debug: (message, ...args) => logger.debug(`[${context}] ${message}`, ...args), info: (message, ...args) => logger.info(`[${context}] ${message}`, ...args), warn: (message, ...args) => logger.warn(`[${context}] ${message}`, ...args), error: (message, ...args) => logger.error(`[${context}] ${message}`, ...args), }; }