From: Jérôme Benoit Date: Sun, 28 Aug 2022 14:56:07 +0000 (+0200) Subject: Uniformize log messages, take 2 X-Git-Tag: v1.1.68~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=91a4f151f35933f762d1287754a7463e12989b29;p=e-mobility-charging-stations-simulator.git Uniformize log messages, take 2 Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index bd23b37d..ff3b2601 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -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 diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 8978f0c8..4f058b72 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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; } } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 4f4db668..f069cdf6 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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; }