From 54ebb82c196c3b5cf81e6ed4ab8a65fd96ed2f5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 28 Apr 2023 14:10:03 +0200 Subject: [PATCH] refactor: uniformize log messages formatting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 8 ++--- src/charging-station/ChargingStationUtils.ts | 6 ++-- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 2 +- .../ocpp/1.6/OCPP16ResponseService.ts | 33 +++++++++---------- .../ocpp/1.6/OCPP16ServiceUtils.ts | 16 ++++----- src/charging-station/ocpp/OCPPServiceUtils.ts | 12 +++---- 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index d058866a..fb79ae25 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -231,16 +231,16 @@ export class AutomaticTransactionGenerator extends AsyncResource { Utils.getRandomInteger(this.configuration.maxDuration, this.configuration.minDuration) * 1000; logger.info( - `${this.logPrefix(connectorId)} transaction ${this.chargingStation + `${this.logPrefix(connectorId)} transaction started with id ${this.chargingStation .getConnectorStatus(connectorId) - ?.transactionId?.toString()} started and will stop in ${Utils.formatDurationMilliSeconds( + ?.transactionId?.toString()} and will stop in ${Utils.formatDurationMilliSeconds( waitTrxEnd )}` ); await Utils.sleep(waitTrxEnd); // Stop transaction logger.info( - `${this.logPrefix(connectorId)} stop transaction ${this.chargingStation + `${this.logPrefix(connectorId)} stop transaction with id ${this.chargingStation .getConnectorStatus(connectorId) ?.transactionId?.toString()}` ); @@ -402,7 +402,7 @@ export class AutomaticTransactionGenerator extends AsyncResource { const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId; logger.warn( `${this.logPrefix(connectorId)} stopping a not started transaction${ - !Utils.isNullOrUndefined(transactionId) ? ` ${transactionId?.toString()}` : '' + !Utils.isNullOrUndefined(transactionId) ? ` with id ${transactionId?.toString()}` : '' }` ); } diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index a14d2048..49a61101 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -171,7 +171,7 @@ export class ChargingStationUtils { ): void { if (!Utils.isNullOrUndefined(connectorStatus?.status)) { logger.warn( - `${logPrefix} Charging station information from template ${templateFile} with connector ${connectorId} status configuration defined, undefine it` + `${logPrefix} Charging station information from template ${templateFile} with connector id ${connectorId} status configuration defined, undefine it` ); delete connectorStatus.status; } @@ -210,7 +210,7 @@ export class ChargingStationUtils { for (const connectorId of connectors.keys()) { if (connectorId > 0 && connectors.get(connectorId)?.transactionStarted === true) { logger.warn( - `${logPrefix} Connector id ${connectorId} at initialization has a transaction started: ${ + `${logPrefix} Connector id ${connectorId} at initialization has a transaction started with id ${ connectors.get(connectorId)?.transactionId }` ); @@ -556,7 +556,7 @@ export class ChargingStationUtils { } /** - * Charging profiles should already be sorted by connectorId and stack level (highest stack level has priority) + * Charging profiles should already be sorted by connector id and stack level (highest stack level has priority) * * @param chargingProfiles - * @param logPrefix - diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 424ee43a..642cb18c 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -983,7 +983,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } } logger.warn( - `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction ${transactionId.toString()}` + `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction with id: ${transactionId.toString()}` ); return OCPP16Constants.OCPP_RESPONSE_REJECTED; } diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index a082653d..743455ff 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -418,7 +418,7 @@ export class OCPP16ResponseService extends OCPPResponseService { (chargingStation.getConnectorStatus(authorizeConnectorId).idTagAuthorized = true); logger.debug( `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' accepted${ - authorizeConnectorIdDefined ? ` on connector ${authorizeConnectorId}` : '' + authorizeConnectorIdDefined ? ` on connector id ${authorizeConnectorId}` : '' }` ); } else { @@ -429,7 +429,7 @@ export class OCPP16ResponseService extends OCPPResponseService { logger.debug( `${chargingStation.logPrefix()} idTag '${requestPayload.idTag}' rejected with status '${ payload.idTagInfo.status - }'${authorizeConnectorIdDefined ? ` on connector ${authorizeConnectorId}` : ''}` + }'${authorizeConnectorIdDefined ? ` on connector id ${authorizeConnectorId}` : ''}` ); } } @@ -440,7 +440,6 @@ export class OCPP16ResponseService extends OCPPResponseService { requestPayload: OCPP16StartTransactionRequest ): Promise { const connectorId = requestPayload.connectorId; - if (connectorId === 0 || !chargingStation.connectors.has(connectorId)) { logger.error( `${chargingStation.logPrefix()} Trying to start a transaction on a non existing connector id ${connectorId.toString()}` @@ -507,7 +506,7 @@ export class OCPP16ResponseService extends OCPPResponseService { } if (chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) { logger.debug( - `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector ${connectorId.toString()}: %j`, + `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId.toString()}: %j`, chargingStation.getConnectorStatus(connectorId) ); return; @@ -518,20 +517,20 @@ export class OCPP16ResponseService extends OCPPResponseService { chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Preparing ) { logger.error( - `${chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with status ${ + `${chargingStation.logPrefix()} Trying to start a transaction on connector id ${connectorId.toString()} with status ${ chargingStation.getConnectorStatus(connectorId)?.status }` ); return; } - // if (!Number.isInteger(payload.transactionId)) { - // logger.warn( - // `${chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with a non integer transaction Id ${ - // payload.transactionId - // }, converting to integer` - // ); - // payload.transactionId = Utils.convertToInt(payload.transactionId); - // } + if (!Number.isInteger(payload.transactionId)) { + logger.warn( + `${chargingStation.logPrefix()} Trying to start a transaction on connector id ${connectorId.toString()} with a non integer transaction id ${ + payload.transactionId + }, converting to integer` + ); + payload.transactionId = Utils.convertToInt(payload.transactionId); + } if (payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { chargingStation.getConnectorStatus(connectorId).transactionStarted = true; @@ -561,7 +560,7 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16ChargePointStatus.Charging ); logger.info( - `${chargingStation.logPrefix()} Transaction ${payload.transactionId.toString()} STARTED on ${ + `${chargingStation.logPrefix()} Transaction with id ${payload.transactionId.toString()} STARTED on ${ chargingStation.stationInfo.chargingStationId }#${connectorId.toString()} for idTag '${requestPayload.idTag}'` ); @@ -581,7 +580,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ); } else { logger.warn( - `${chargingStation.logPrefix()} Starting transaction id ${payload.transactionId.toString()} REJECTED with status '${ + `${chargingStation.logPrefix()} Starting transaction with id ${payload.transactionId.toString()} REJECTED with status '${ payload.idTagInfo?.status }', idTag '${requestPayload.idTag}'` ); @@ -617,7 +616,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ); if (Utils.isNullOrUndefined(transactionConnectorId)) { logger.error( - `${chargingStation.logPrefix()} Trying to stop a non existing transaction ${requestPayload.transactionId.toString()}` + `${chargingStation.logPrefix()} Trying to stop a non existing transaction with id ${requestPayload.transactionId.toString()}` ); return; } @@ -662,7 +661,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ); chargingStation.stopMeterValues(transactionConnectorId); parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation)); - const logMsg = `${chargingStation.logPrefix()} Transaction ${requestPayload.transactionId.toString()} STOPPED on ${ + const logMsg = `${chargingStation.logPrefix()} Transaction with id ${requestPayload.transactionId.toString()} STOPPED on ${ chargingStation.stationInfo.chargingStationId }#${transactionConnectorId?.toString()} with status '${ payload.idTagInfo?.status ?? 'undefined' diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 932d4515..578699a7 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -89,7 +89,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${socMinimumValue}/${ meterValue.sampledValue[sampledValuesIndex].value @@ -384,7 +384,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction ${ connector?.transactionId }, value: ${connectorMinimumPowerRounded}/${ meterValue.sampledValue[sampledValuesIndex].value @@ -428,7 +428,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: phase ${ meterValue.sampledValue[sampledValuesPerPhaseIndex].phase - }, connectorId ${connectorId}, transaction ${ + }, connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumPowerPerPhaseRounded}/${ meterValue.sampledValue[sampledValuesPerPhaseIndex].value @@ -609,7 +609,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumAmperage}/${ meterValue.sampledValue[sampledValuesIndex].value @@ -645,7 +645,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: phase ${ meterValue.sampledValue[sampledValuesPerPhaseIndex].phase - }, connectorId ${connectorId}, transaction ${ + }, connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumAmperage}/${ meterValue.sampledValue[sampledValuesPerPhaseIndex].value @@ -716,7 +716,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${Utils.roundTo( interval / (3600 * 1000), @@ -797,7 +797,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { Utils.isNullOrUndefined(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) ) { logger.error( - `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization` + `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization` ); chargingStation.getConnectorStatus(connectorId).chargingProfiles = []; } @@ -805,7 +805,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { Array.isArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) === false ) { logger.error( - `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization` + `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization` ); chargingStation.getConnectorStatus(connectorId).chargingProfiles = []; } diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index b16d5f0d..f0ad1ca6 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -244,7 +244,7 @@ export class OCPPServiceUtils { logger.warn( `${chargingStation.logPrefix()} OCPP ${ chargingStation.stationInfo.ocppVersion - } connector ${connectorId} status transition from '${ + } connector id ${connectorId} status transition from '${ chargingStation.getConnectorStatus(connectorId).status }' to '${status}' is not allowed` ); @@ -280,7 +280,7 @@ export class OCPPServiceUtils { const onPhaseStr = phase ? `on phase ${phase} ` : ''; if (Constants.SUPPORTED_MEASURANDS.includes(measurand) === false) { logger.warn( - `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}` + `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connector id ${connectorId}` ); return; } @@ -292,7 +292,7 @@ export class OCPPServiceUtils { )?.value?.includes(measurand) === false ) { logger.debug( - `${chargingStation.logPrefix()} Trying to get MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId} not found in '${ + `${chargingStation.logPrefix()} Trying to get MeterValues measurand '${measurand}' ${onPhaseStr}in template on connector id ${connectorId} not found in '${ StandardParametersKey.MeterValuesSampledData }' OCPP parameter` ); @@ -312,7 +312,7 @@ export class OCPPServiceUtils { ) === false ) { logger.warn( - `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}` + `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connector id ${connectorId}` ); } else if ( phase && @@ -343,12 +343,12 @@ export class OCPPServiceUtils { } } if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER) { - const errorMsg = `Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`; + const errorMsg = `Missing MeterValues for default measurand '${measurand}' in template on connector id ${connectorId}`; logger.error(`${chargingStation.logPrefix()} ${errorMsg}`); throw new BaseError(errorMsg); } logger.debug( - `${chargingStation.logPrefix()} No MeterValues for measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}` + `${chargingStation.logPrefix()} No MeterValues for measurand '${measurand}' ${onPhaseStr}in template on connector id ${connectorId}` ); } -- 2.34.1