refactor: uniformize log messages formatting
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 12:10:03 +0000 (14:10 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 28 Apr 2023 12:10:03 +0000 (14:10 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index d058866abae0da08c3d43937af6e3931e0872c6d..fb79ae259b9a0c56234553851e0f150b67e4ae9b 100644 (file)
@@ -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()}` : ''
         }`
       );
     }
index a14d20481950884b3c241e4ff0a0ee7f782604a7..49a61101533043ae15cb09c6783eb197bf452cfd 100644 (file)
@@ -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 -
index 424ee43a5a6a27a8b6e11bcf4849dc0186395716..642cb18cc4a82824ffa67cc451040bef55eca2df 100644 (file)
@@ -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;
   }
index a082653d7de498eb31b63d5ec34ef32863afe2fb..743455ff8ae783d86611b06272ddba8c7b9e8dee 100644 (file)
@@ -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<void> {
     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'
index 932d4515f6d0fcc7d0c259f3fe8ff000e11423ed..578699a7340f126d90cb3bd5e1c49b9eada36a37 100644 (file)
@@ -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 = [];
     }
index b16d5f0d4a8970df1259fe9b9ef74850d178c7e8..f0ad1ca668f84bd72060eb2cf57c7a1d7fe63d85 100644 (file)
@@ -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}`
     );
   }