mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-13 01:53:23 +00:00
- 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>
60 lines
1.9 KiB
TypeScript
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
|
|
}
|