Files
payload-automation/src/plugin/logger.ts
Bas van den Aakster 592536f61a Rename 'collection' field to 'collectionSlug' to avoid PayloadCMS reserved field conflicts
- Updated Workflow collection trigger field from 'collection' to 'collectionSlug'
- Updated all document operation steps (create, read, update, delete) to use 'collectionSlug'
- Updated corresponding handlers to destructure 'collectionSlug' instead of 'collection'
- Removed debug console.log statements from logger configLogger methods
- Fixed collection hook debug logs to use 'slug' instead of reserved 'collection' field

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-31 17:14:35 +02:00

60 lines
1.9 KiB
TypeScript

import type { Payload } from 'payload'
// Global logger instance - use Payload's logger type
let pluginLogger: null | Payload['logger'] = null
/**
* Simple config-time logger for use during plugin configuration
* Uses console with plugin prefix since Payload logger isn't available yet
*/
const configLogger = {
debug: <T>(message: string, ...args: T[]) => {
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}
console.log(`[payload-automation] ${message}`, ...args)
},
error: <T>(message: string, ...args: T[]) => {
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}
console.error(`[payload-automation] ${message}`, ...args)
},
info: <T>(message: string, ...args: T[]) => {
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}
console.log(`[payload-automation] ${message}`, ...args)
},
warn: <T>(message: string, ...args: T[]) => {
if (!process.env.PAYLOAD_AUTOMATION_CONFIG_LOGGING) {return}
console.warn(`[payload-automation] ${message}`, ...args)
}
}
/**
* Get a logger for config-time use (before Payload initialization)
*/
export function getConfigLogger() {
return configLogger
}
/**
* Initialize the plugin logger using Payload's Pino instance
* This creates a child logger with plugin identification
*/
export function initializeLogger(payload: Payload): Payload['logger'] {
// Create a child logger with plugin identification
pluginLogger = payload.logger.child({
level: process.env.PAYLOAD_AUTOMATION_LOGGING || 'silent',
plugin: '@xtr-dev/payload-automation'
})
return pluginLogger
}
/**
* Get the plugin logger instance
* Throws error if not initialized
*/
export function getLogger(): Payload['logger'] {
if (!pluginLogger) {
throw new Error('@xtr-dev/payload-automation: Logger not initialized. Make sure the plugin is properly configured.')
}
return pluginLogger
}