From: Jérôme Benoit Date: Sun, 11 Sep 2022 13:11:40 +0000 (+0200) Subject: Improve and unify log messages X-Git-Tag: v1.1.73~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ba7965c4b933e479b36fc81f934a643336efcbea;p=e-mobility-charging-stations-simulator.git Improve and unify log messages Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index a09ee7a1..03297e4a 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -60,7 +60,7 @@ export default class AutomaticTransactionGenerator { public start(): void { if (this.started === true) { - logger.warn(`${this.logPrefix()} trying to start while already started`); + logger.warn(`${this.logPrefix()} is already started`); return; } this.startConnectors(); @@ -69,7 +69,7 @@ export default class AutomaticTransactionGenerator { public stop(): void { if (this.started === false) { - logger.warn(`${this.logPrefix()} trying to stop while not started`); + logger.warn(`${this.logPrefix()} is already stopped`); return; } this.stopConnectors(); @@ -78,7 +78,7 @@ export default class AutomaticTransactionGenerator { public startConnector(connectorId: number): void { if (this.chargingStation.connectors.has(connectorId) === false) { - logger.warn(`${this.logPrefix(connectorId)} trying to start on non existing connector`); + logger.warn(`${this.logPrefix(connectorId)} starting on non existing connector`); return; } if (this.connectorsStatus.get(connectorId)?.start === false) { @@ -89,15 +89,23 @@ export default class AutomaticTransactionGenerator { }); }); } else if (this.connectorsStatus.get(connectorId)?.start === true) { - logger.warn(`${this.logPrefix(connectorId)} already started on connector`); + logger.warn(`${this.logPrefix(connectorId)} is already started on connector`); } } public stopConnector(connectorId: number): void { - this.connectorsStatus.set(connectorId, { - ...this.connectorsStatus.get(connectorId), - start: false, - }); + if (this.chargingStation.connectors.has(connectorId) === false) { + logger.warn(`${this.logPrefix(connectorId)} stopping on non existing connector`); + return; + } + if (this.connectorsStatus.get(connectorId)?.start === true) { + this.connectorsStatus.set(connectorId, { + ...this.connectorsStatus.get(connectorId), + start: false, + }); + } else if (this.connectorsStatus.get(connectorId)?.start === false) { + logger.warn(`${this.logPrefix(connectorId)} is already stopped on connector`); + } } private startConnectors(): void { @@ -286,7 +294,7 @@ export default class AutomaticTransactionGenerator { const idTag = this.chargingStation.getRandomIdTag(); const startTransactionLogMsg = `${this.logPrefix( connectorId - )} start transaction for idTag '${idTag}'`; + )} start transaction with an idTag '${idTag}'`; if (this.getRequireAuthorize()) { this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag; // Authorize idTag @@ -358,7 +366,7 @@ export default class AutomaticTransactionGenerator { } else { const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId; logger.warn( - `${this.logPrefix(connectorId)} trying to stop a not started transaction${ + `${this.logPrefix(connectorId)} stopping a not started transaction${ transactionId ? ' ' + transactionId.toString() : '' }` ); diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index d0c40162..eb437ab0 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -147,10 +147,10 @@ export class Bootstrap { this.workerImplementation = null; this.uiServer?.stop(); await this.storage?.close(); + this.started = false; } else { - console.error(chalk.red('Trying to stop the charging stations simulator while not started')); + console.error(chalk.red('Cannot stop a not started charging stations simulator')); } - this.started = false; } public async restart(): Promise { diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 9d7bdae7..32cbc671 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1471,7 +1471,7 @@ export default class ChargingStation { // Outcome Message case MessageType.CALL_RESULT_MESSAGE: [, , commandPayload] = request as Response; - if (!this.requests.has(messageId)) { + if (this.requests.has(messageId) === false) { // Error throw new OCPPError( ErrorType.INTERNAL_ERROR, @@ -1502,7 +1502,7 @@ export default class ChargingStation { // Error Message case MessageType.CALL_ERROR_MESSAGE: [, , errorType, errorMessage, errorDetails] = request as ErrorResponse; - if (!this.requests.has(messageId)) { + if (this.requests.has(messageId) === false) { // Error throw new OCPPError( ErrorType.INTERNAL_ERROR, @@ -1539,7 +1539,7 @@ export default class ChargingStation { parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); } else { throw new OCPPError(ErrorType.PROTOCOL_ERROR, 'Incoming message is not an array', null, { - payload: request, + request, }); } } catch (error) { @@ -1552,7 +1552,7 @@ export default class ChargingStation { )}' processing error:`, error ); - if (!(error instanceof OCPPError)) { + if (error instanceof OCPPError === false) { logger.warn( `${this.logPrefix()} Error thrown at incoming OCPP command '${ commandName ?? requestCommandName ?? null @@ -1560,14 +1560,15 @@ export default class ChargingStation { error ); } - // Send error - messageType === MessageType.CALL_MESSAGE && - (await this.ocppRequestService.sendError( + if (messageType === MessageType.CALL_MESSAGE) { + // Send error + await this.ocppRequestService.sendError( this, messageId, error as OCPPError, commandName ?? requestCommandName ?? null - )); + ); + } } }