Uniformize log messages, take 2
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 28 Aug 2022 14:56:07 +0000 (16:56 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 28 Aug 2022 14:56:07 +0000 (16:56 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts

index bd23b37d9cdd7a57cc1a616e5a978c2284443a35..ff3b2601b8a7ba6ce9493272d06eb857a0db5109 100644 (file)
@@ -1515,7 +1515,7 @@ export default class ChargingStation {
     } catch (error) {
       // Log
       logger.error(
-        `${this.logPrefix()} Incoming OCPP '${
+        `${this.logPrefix()} Incoming OCPP command '${
           commandName ?? requestCommandName ?? null
         }' message '${data.toString()}' matching cached request '${JSON.stringify(
           this.requests.get(messageId)
@@ -1524,7 +1524,7 @@ export default class ChargingStation {
       );
       if (!(error instanceof OCPPError)) {
         logger.warn(
-          `${this.logPrefix()} Error thrown at incoming OCPP '${
+          `${this.logPrefix()} Error thrown at incoming OCPP command '${
             commandName ?? requestCommandName ?? null
           }' message '${data.toString()}' handling is not an OCPPError:`,
           error
index 8978f0c8805fcf4c01c733bad855415f84a60710..4f058b725fd6645a3bd4753efb5e85102564f1f3 100644 (file)
@@ -30,6 +30,8 @@ import Utils from '../utils/Utils';
 import type ChargingStation from './ChargingStation';
 import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
 
+const moduleName = 'ChargingStationUtils';
+
 export class ChargingStationUtils {
   private constructor() {
     // This is intentional
@@ -330,6 +332,7 @@ export class ChargingStationUtils {
     limit: number;
     matchingChargingProfile: ChargingProfile;
   } | null {
+    const debugLogMsg = `${logPrefix} ${moduleName}.getLimitFromChargingProfiles: Matching charging profile found for power limitation: %j`;
     for (const chargingProfile of chargingProfiles) {
       // Set helpers
       const currentMoment = moment();
@@ -373,10 +376,7 @@ export class ChargingStationUtils {
               limit: schedulePeriod.limit,
               matchingChargingProfile: chargingProfile,
             };
-            logger.debug(
-              `${logPrefix} Matching charging profile found for power limitation: %j`,
-              result
-            );
+            logger.debug(debugLogMsg, result);
             return result;
           }
           // Find the right schedule period
@@ -390,10 +390,7 @@ export class ChargingStationUtils {
               limit: lastButOneSchedule.limit,
               matchingChargingProfile: chargingProfile,
             };
-            logger.debug(
-              `${logPrefix} Matching charging profile found for power limitation: %j`,
-              result
-            );
+            logger.debug(debugLogMsg, result);
             return result;
           }
           // Keep it
@@ -409,10 +406,7 @@ export class ChargingStationUtils {
               limit: lastButOneSchedule.limit,
               matchingChargingProfile: chargingProfile,
             };
-            logger.debug(
-              `${logPrefix} Matching charging profile found for power limitation: %j`,
-              result
-            );
+            logger.debug(debugLogMsg, result);
             return result;
           }
         }
index 4f4db66848bd72b4c54dd9776e688ef727f7f3b2..f069cdf662212604cd0a1aeccc1eeba05ed5ae58 100644 (file)
@@ -762,6 +762,15 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
     const transactionConnectorId = commandPayload.connectorId;
     const connectorStatus = chargingStation.getConnectorStatus(transactionConnectorId);
     if (transactionConnectorId) {
+      const remoteStartTransactionLogMsg =
+        chargingStation.logPrefix() +
+        ' Transaction remotely STARTED on ' +
+        chargingStation.stationInfo.chargingStationId +
+        '#' +
+        transactionConnectorId.toString() +
+        " for idTag '" +
+        commandPayload.idTag +
+        "'";
       await chargingStation.ocppRequestService.requestHandler<
         OCPP16StatusNotificationRequest,
         OCPP16StatusNotificationResponse
@@ -825,16 +834,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
                   })
                 ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
               ) {
-                logger.debug(
-                  chargingStation.logPrefix() +
-                    ' Transaction remotely STARTED on ' +
-                    chargingStation.stationInfo.chargingStationId +
-                    '#' +
-                    transactionConnectorId.toString() +
-                    " for idTag '" +
-                    commandPayload.idTag +
-                    "'"
-                );
+                logger.debug(remoteStartTransactionLogMsg);
                 return Constants.OCPP_RESPONSE_ACCEPTED;
               }
               return this.notifyRemoteStartTransactionRejected(
@@ -875,16 +875,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               })
             ).idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED
           ) {
-            logger.debug(
-              chargingStation.logPrefix() +
-                ' Transaction remotely STARTED on ' +
-                chargingStation.stationInfo.chargingStationId +
-                '#' +
-                transactionConnectorId.toString() +
-                " for idTag '" +
-                commandPayload.idTag +
-                "'"
-            );
+            logger.debug(remoteStartTransactionLogMsg);
             return Constants.OCPP_RESPONSE_ACCEPTED;
           }
           return this.notifyRemoteStartTransactionRejected(
@@ -934,12 +925,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       chargingStation.logPrefix() +
         ' Remote starting transaction REJECTED on connector Id ' +
         connectorId.toString() +
-        ', idTag ' +
+        ", idTag '" +
         idTag +
-        ', availability ' +
+        "', availability '" +
         chargingStation.getConnectorStatus(connectorId).availability +
-        ', status ' +
-        chargingStation.getConnectorStatus(connectorId).status
+        "', status '" +
+        chargingStation.getConnectorStatus(connectorId).status +
+        "'"
     );
     return Constants.OCPP_RESPONSE_REJECTED;
   }