Add OCPP commands payload logging in the logs
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index af23a1f4fcbdd55ac4c357dfc67c12e3c35d7e8e..ed3a8da7461d06bdeee98bbc6a8ba834de6f72aa 100644 (file)
@@ -16,7 +16,6 @@ import OCPPError from '../../exception/OCPPError';
 import type OCPPResponseService from './OCPPResponseService';
 import PerformanceStatistics from '../../performance/PerformanceStatistics';
 import Utils from '../../utils/Utils';
-import chalk from 'chalk';
 import logger from '../../utils/Logger';
 
 export default abstract class OCPPRequestService {
@@ -152,10 +151,24 @@ export default abstract class OCPPRequestService {
           if (this.chargingStation.isWebSocketConnectionOpened()) {
             // Yes: Send Message
             const beginId = PerformanceStatistics.beginMeasure(commandName);
-            console.log(chalk`{blue >> Sending message = ${messageToSend}}`);
             // FIXME: Handle sending error
             this.chargingStation.wsConnection.send(messageToSend);
             PerformanceStatistics.endMeasure(commandName, beginId);
+            let msgTypeStr: string;
+            switch (messageType) {
+              case MessageType.CALL_MESSAGE:
+                msgTypeStr = 'request';
+                break;
+              case MessageType.CALL_RESULT_MESSAGE:
+                msgTypeStr = 'response';
+                break;
+              case MessageType.CALL_ERROR_MESSAGE:
+                msgTypeStr = 'error';
+                break;
+            }
+            logger.debug(
+              `${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${msgTypeStr} payload: ${messageToSend}`
+            );
           } else if (!params.skipBufferingOnError) {
             // Buffer it
             this.chargingStation.bufferMessage(messageToSend);