mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
add logger
This commit is contained in:
parent
5d69d3720c
commit
299a77b034
@ -51,6 +51,9 @@ export class CommandExecutor {
|
|||||||
methodLogger.debug(`executeEncryptedCommand() commandArgs=${JSON.stringify(commandArgs)}`)
|
methodLogger.debug(`executeEncryptedCommand() commandArgs=${JSON.stringify(commandArgs)}`)
|
||||||
}
|
}
|
||||||
const command = CommandFactory.getInstance().createCommand(commandArgs.commandName, commandArgs.params);
|
const command = CommandFactory.getInstance().createCommand(commandArgs.commandName, commandArgs.params);
|
||||||
|
if (methodLogger.isDebugEnabled()) {
|
||||||
|
methodLogger.debug(`executeEncryptedCommand() command=${JSON.stringify(command)}`)
|
||||||
|
}
|
||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
const result = await this.executeCommand(command);
|
const result = await this.executeCommand(command);
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import { Command } from './Command';
|
import { Command } from './Command';
|
||||||
import { BaseCommand } from './BaseCommand';
|
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 {
|
export class CommandFactory {
|
||||||
private static instance: CommandFactory;
|
private static instance: CommandFactory;
|
||||||
@ -16,13 +21,24 @@ export class CommandFactory {
|
|||||||
|
|
||||||
registerCommand(name: string, commandClass: new (params: any) => Command): void {
|
registerCommand(name: string, commandClass: new (params: any) => Command): void {
|
||||||
this.commands.set(name, commandClass);
|
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> {
|
createCommand<T>(name: string, params: any = {}): Command<T> {
|
||||||
|
const methodLogger = createLogger(`createCommand`)
|
||||||
const CommandClass = this.commands.get(name);
|
const CommandClass = this.commands.get(name);
|
||||||
if (!CommandClass) {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user