add logger

This commit is contained in:
clauspeterhuebner 2026-02-05 00:57:34 +01:00
parent 5d69d3720c
commit 299a77b034
2 changed files with 21 additions and 2 deletions

View File

@ -51,6 +51,9 @@ export class CommandExecutor {
methodLogger.debug(`executeEncryptedCommand() commandArgs=${JSON.stringify(commandArgs)}`)
}
const command = CommandFactory.getInstance().createCommand(commandArgs.commandName, commandArgs.params);
if (methodLogger.isDebugEnabled()) {
methodLogger.debug(`executeEncryptedCommand() command=${JSON.stringify(command)}`)
}
// Execute the command
const result = await this.executeCommand(command);

View File

@ -1,5 +1,10 @@
import { Command } from './Command';
import { BaseCommand } from './BaseCommand';
import { getLogger } from 'log4js';
import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const';
const createLogger = (method: string) =>
getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.command.CommandFactory.${method}`)
export class CommandFactory {
private static instance: CommandFactory;
@ -16,13 +21,24 @@ export class CommandFactory {
registerCommand(name: string, commandClass: new (params: any) => Command): void {
this.commands.set(name, commandClass);
const methodLogger = createLogger(`registerCommand`)
if (methodLogger.isDebugEnabled()) {
methodLogger.debug(`registerCommand() name=${name}`)
}
}
createCommand<T>(name: string, params: any = {}): Command<T> {
const methodLogger = createLogger(`createCommand`)
const CommandClass = this.commands.get(name);
if (!CommandClass) {
throw new Error(`Command ${name} not found`);
const errmsg = `Command ${name} not found`;
methodLogger.error(errmsg);
throw new Error(errmsg);
}
return new CommandClass(params) as Command<T>;
const command = new CommandClass(params) as Command<T>;
if (methodLogger.isDebugEnabled()) {
methodLogger.debug(`createCommand() command=${JSON.stringify(command)}`)
}
return command;
}
}