n8n-nodes-proxmox
Version:
n8n community node for Proxmox Virtual Environment (VE) API integration with VM, container, storage, and cluster management capabilities
79 lines (64 loc) • 2.37 kB
text/typescript
/**
* Simple logging utility for ProxMox node operations
*/
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
interface LogContext {
operation?: string;
resource?: string;
node?: string;
vmid?: number;
[key: string]: any;
}
class ProxMoxLogger {
private isDebugEnabled(): boolean {
return process.env.NODE_ENV === 'development' || process.env.N8N_DEBUG === 'true';
}
private formatMessage(
level: LogLevel,
category: string,
message: string,
context?: LogContext,
): string {
const timestamp = new Date().toISOString();
const contextStr = context ? ` ${JSON.stringify(context)}` : '';
return `[${timestamp}] PROXMOX:${level.toUpperCase()} [${category}] ${message}${contextStr}`;
}
debug(category: string, message: string, context?: LogContext): void {
if (this.isDebugEnabled()) {
console.debug(this.formatMessage('debug', category, message, context));
}
}
info(category: string, message: string, context?: LogContext): void {
console.info(this.formatMessage('info', category, message, context));
}
warn(category: string, message: string, context?: LogContext): void {
console.warn(this.formatMessage('warn', category, message, context));
}
error(category: string, message: string, context?: LogContext): void {
console.error(this.formatMessage('error', category, message, context));
}
// Convenience methods for common ProxMox operations
apiRequest(method: string, endpoint: string, context?: LogContext): void {
this.debug('api', `${method} ${endpoint}`, context);
}
apiResponse(method: string, endpoint: string, status: number, context?: LogContext): void {
this.debug('api', `${method} ${endpoint} -> ${status}`, context);
}
apiError(method: string, endpoint: string, error: string, context?: LogContext): void {
this.error('api', `${method} ${endpoint} failed: ${error}`, context);
}
operation(
operation: string,
resource: string,
status: 'start' | 'success' | 'error',
context?: LogContext,
): void {
const level = status === 'error' ? 'error' : 'info';
this[level]('operation', `${operation} ${resource} ${status}`, context);
}
auth(action: string, status: 'success' | 'error', context?: LogContext): void {
const level = status === 'error' ? 'error' : 'info';
this[level]('auth', `${action} ${status}`, context);
}
}
export const logger = new ProxMoxLogger();