From 44eb6026079c8dc2c77b10a96a42d0c0b2da7c8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 23 Jan 2023 13:50:55 +0100 Subject: [PATCH] Switch log messages to string literal MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/AuthorizedTagsCache.ts | 7 +- .../AutomaticTransactionGenerator.ts | 67 +++++++------- src/charging-station/Bootstrap.ts | 6 +- src/charging-station/ChargingStation.ts | 52 +++++------ src/charging-station/ChargingStationUtils.ts | 12 ++- .../WorkerBroadcastChannel.ts | 12 ++- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 39 +++----- .../ocpp/1.6/OCPP16ResponseService.ts | 90 +++++++------------ .../ocpp/2.0/OCPP20ResponseService.ts | 3 +- src/performance/PerformanceStatistics.ts | 11 +-- src/utils/Configuration.ts | 4 +- src/utils/Utils.ts | 8 +- ui/web/src/composables/UIClient.ts | 4 +- 13 files changed, 133 insertions(+), 182 deletions(-) diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index 0f702047..4f853a97 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -38,10 +38,7 @@ export default class AuthorizedTagsCache { if (filename && event === 'change') { try { logger.debug( - this.logPrefix(file) + - ' ' + - FileType.Authorization + - ' file have changed, reload' + `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload` ); this.deleteTags(file); this.deleteFSWatcher(file); @@ -104,7 +101,7 @@ export default class AuthorizedTagsCache { ); } } else { - logger.info(this.logPrefix(file) + ' No authorization file given)'); + logger.info(`${this.logPrefix(file)} No authorization file given`); } return authorizedTags; } diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 60760be1..3a1c6786 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -151,12 +151,12 @@ export default class AutomaticTransactionGenerator extends AsyncResource { private async internalStartConnector(connectorId: number): Promise { this.setStartConnectorStatus(connectorId); logger.info( - this.logPrefix(connectorId) + - ' started on connector and will run for ' + - Utils.formatDurationMilliSeconds( - this.connectorsStatus.get(connectorId).stopDate.getTime() - - this.connectorsStatus.get(connectorId).startDate.getTime() - ) + `${this.logPrefix( + connectorId + )} started on connector and will run for ${Utils.formatDurationMilliSeconds( + this.connectorsStatus.get(connectorId).stopDate.getTime() - + this.connectorsStatus.get(connectorId).startDate.getTime() + )}` ); while (this.connectorsStatus.get(connectorId).start === true) { if (new Date() > this.connectorsStatus.get(connectorId).stopDate) { @@ -165,16 +165,18 @@ export default class AutomaticTransactionGenerator extends AsyncResource { } if (this.chargingStation.isInAcceptedState() === false) { logger.error( - this.logPrefix(connectorId) + - ' entered in transaction loop while the charging station is not in accepted state' + `${this.logPrefix( + connectorId + )} entered in transaction loop while the charging station is not in accepted state` ); this.stopConnector(connectorId); break; } if (this.chargingStation.isChargingStationAvailable() === false) { logger.info( - this.logPrefix(connectorId) + - ' entered in transaction loop while the charging station is unavailable' + `${this.logPrefix( + connectorId + )} entered in transaction loop while the charging station is unavailable` ); this.stopConnector(connectorId); break; @@ -204,7 +206,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.configuration.minDelayBetweenTwoTransactions ) * 1000; logger.info( - this.logPrefix(connectorId) + ' waiting for ' + Utils.formatDurationMilliSeconds(wait) + `${this.logPrefix(connectorId)} waiting for ${Utils.formatDurationMilliSeconds(wait)}` ); await Utils.sleep(wait); const start = Utils.secureRandom(); @@ -218,18 +220,18 @@ export default class AutomaticTransactionGenerator extends AsyncResource { Utils.getRandomInteger(this.configuration.maxDuration, this.configuration.minDuration) * 1000; logger.info( - this.logPrefix(connectorId) + - ' transaction ' + - this.chargingStation.getConnectorStatus(connectorId).transactionId.toString() + - ' started and will stop in ' + - Utils.formatDurationMilliSeconds(waitTrxEnd) + `${this.logPrefix(connectorId)} transaction ${this.chargingStation + .getConnectorStatus(connectorId) + .transactionId.toString()} started and will stop in ${Utils.formatDurationMilliSeconds( + waitTrxEnd + )}` ); await Utils.sleep(waitTrxEnd); // Stop transaction logger.info( - this.logPrefix(connectorId) + - ' stop transaction ' + - this.chargingStation.getConnectorStatus(connectorId).transactionId.toString() + `${this.logPrefix(connectorId)} stop transaction ${this.chargingStation + .getConnectorStatus(connectorId) + .transactionId.toString()}` ); await this.stopTransaction(connectorId); } @@ -237,24 +239,23 @@ export default class AutomaticTransactionGenerator extends AsyncResource { this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions++; this.connectorsStatus.get(connectorId).skippedTransactions++; logger.info( - this.logPrefix(connectorId) + - ' skipped consecutively ' + - this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions.toString() + - '/' + - this.connectorsStatus.get(connectorId).skippedTransactions.toString() + - ' transaction(s)' + `${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus + .get(connectorId) + .skippedConsecutiveTransactions.toString()}/${this.connectorsStatus + .get(connectorId) + .skippedTransactions.toString()} transaction(s)` ); } this.connectorsStatus.get(connectorId).lastRunDate = new Date(); } this.connectorsStatus.get(connectorId).stoppedDate = new Date(); logger.info( - this.logPrefix(connectorId) + - ' stopped on connector and lasted for ' + - Utils.formatDurationMilliSeconds( - this.connectorsStatus.get(connectorId).stoppedDate.getTime() - - this.connectorsStatus.get(connectorId).startDate.getTime() - ) + `${this.logPrefix( + connectorId + )} stopped on connector and lasted for ${Utils.formatDurationMilliSeconds( + this.connectorsStatus.get(connectorId).stoppedDate.getTime() - + this.connectorsStatus.get(connectorId).startDate.getTime() + )}` ); logger.debug( `${this.logPrefix(connectorId)} connector status: %j`, @@ -386,7 +387,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource { const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId; logger.warn( `${this.logPrefix(connectorId)} stopping a not started transaction${ - transactionId ? ' ' + transactionId.toString() : '' + transactionId ? ` ${transactionId.toString()}` : '' }` ); } @@ -449,7 +450,7 @@ export default class AutomaticTransactionGenerator extends AsyncResource { if (startResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++; } else { - logger.warn(this.logPrefix(connectorId) + ' start transaction rejected'); + logger.warn(`${this.logPrefix(connectorId)} start transaction rejected`); this.connectorsStatus.get(connectorId).rejectedStartTransactionRequests++; } } diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 7b2db1c7..ca45d287 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -54,7 +54,7 @@ export class Bootstrap { this.workerScript = path.join( path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'), 'charging-station', - 'ChargingStationWorker' + path.extname(fileURLToPath(import.meta.url)) + `ChargingStationWorker${path.extname(fileURLToPath(import.meta.url))}` ); this.initialize(); Configuration.getUIServer().enabled === true && @@ -98,9 +98,7 @@ export class Bootstrap { } catch (error) { console.error( chalk.red( - 'Error at starting charging station with template file ' + - stationTemplateUrl.file + - ': ' + `Error at starting charging station with template file ${stationTemplateUrl.file}: ` ), error ); diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index e1d25740..7fdc9a95 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -146,14 +146,14 @@ export default class ChargingStation { private get wsConnectionUrl(): URL { return new URL( - (this.getSupervisionUrlOcppConfiguration() - ? ChargingStationConfigurationUtils.getConfigurationKey( - this, - this.getSupervisionUrlOcppKey() - ).value - : this.configuredSupervisionUrl.href) + - '/' + - this.stationInfo.chargingStationId + `${ + this.getSupervisionUrlOcppConfiguration() + ? ChargingStationConfigurationUtils.getConfigurationKey( + this, + this.getSupervisionUrlOcppKey() + ).value + : this.configuredSupervisionUrl.href + }/${this.stationInfo.chargingStationId}` ); } @@ -394,15 +394,15 @@ export default class ChargingStation { }); }, this.getHeartbeatInterval()); logger.info( - this.logPrefix() + - ' Heartbeat started every ' + - Utils.formatDurationMilliSeconds(this.getHeartbeatInterval()) + `${this.logPrefix()} Heartbeat started every ${Utils.formatDurationMilliSeconds( + this.getHeartbeatInterval() + )}` ); } else if (this.heartbeatSetInterval) { logger.info( - this.logPrefix() + - ' Heartbeat already started every ' + - Utils.formatDurationMilliSeconds(this.getHeartbeatInterval()) + `${this.logPrefix()} Heartbeat already started every ${Utils.formatDurationMilliSeconds( + this.getHeartbeatInterval() + )}` ); } else { logger.error( @@ -648,7 +648,7 @@ export default class ChargingStation { case OCPPVersion.VERSION_16: case OCPPVersion.VERSION_20: case OCPPVersion.VERSION_201: - protocol = 'ocpp' + ocppVersion; + protocol = `ocpp${ocppVersion}`; break; default: this.handleUnsupportedVersion(ocppVersion); @@ -977,7 +977,7 @@ export default class ChargingStation { private initialize(): void { this.configurationFile = path.join( path.dirname(this.templateFile.replace('station-templates', 'configurations')), - ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile()) + '.json' + `${ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile())}.json` ); this.stationInfo = this.getStationInfo(); this.saveStationInfo(); @@ -1644,16 +1644,16 @@ export default class ChargingStation { } private onPing(): void { - logger.debug(this.logPrefix() + ' Received a WS ping (rfc6455) from the server'); + logger.debug(`${this.logPrefix()} Received a WS ping (rfc6455) from the server`); } private onPong(): void { - logger.debug(this.logPrefix() + ' Received a WS pong (rfc6455) from the server'); + logger.debug(`${this.logPrefix()} Received a WS pong (rfc6455) from the server`); } private onError(error: WSError): void { this.closeWSConnection(); - logger.error(this.logPrefix() + ' WebSocket error:', error); + logger.error(`${this.logPrefix()} WebSocket error:`, error); } private getEnergyActiveImportRegister(connectorStatus: ConnectorStatus, rounded = false): number { @@ -1891,15 +1891,15 @@ export default class ChargingStation { } }, webSocketPingInterval * 1000); logger.info( - this.logPrefix() + - ' WebSocket ping started every ' + - Utils.formatDurationSeconds(webSocketPingInterval) + `${this.logPrefix()} WebSocket ping started every ${Utils.formatDurationSeconds( + webSocketPingInterval + )}` ); } else if (this.webSocketPingSetInterval) { logger.info( - this.logPrefix() + - ' WebSocket ping already started every ' + - Utils.formatDurationSeconds(webSocketPingInterval) + `${this.logPrefix()} WebSocket ping already started every ${Utils.formatDurationSeconds( + webSocketPingInterval + )}` ); } else { logger.error( @@ -2027,7 +2027,7 @@ export default class ChargingStation { ); await Utils.sleep(reconnectDelay); logger.error( - this.logPrefix() + ' WebSocket connection retry #' + this.autoReconnectRetryCount.toString() + `${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}` ); this.openWSConnection( { ...(this.stationInfo?.wsOptions ?? {}), handshakeTimeout: reconnectTimeout }, diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index ed12aa4a..c10a3a15 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -44,14 +44,12 @@ export class ChargingStationUtils { // In case of multiple instances: add instance index to charging station id const instanceIndex = process.env.CF_INSTANCE_INDEX ?? 0; const idSuffix = stationTemplate.nameSuffix ?? ''; - const idStr = '000000000' + index.toString(); + const idStr = `000000000${index.toString()}`; return stationTemplate?.fixedName ? stationTemplate.baseName - : stationTemplate.baseName + - '-' + - instanceIndex.toString() + - idStr.substring(idStr.length - 4) + - idSuffix; + : `${stationTemplate.baseName}-${instanceIndex.toString()}${idStr.substring( + idStr.length - 4 + )}${idSuffix}`; } public static getHashId(index: number, stationTemplate: ChargingStationTemplate): string { @@ -210,7 +208,7 @@ export class ChargingStationUtils { if (!Utils.isUndefined(template[key])) { logger.warn( `${logPrefix} Deprecated template key '${key}' usage in file '${templateFile}'${ - logMsgToAppend && '. ' + logMsgToAppend + logMsgToAppend && `. ${logMsgToAppend}` }` ); } diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index 652a27e1..aa696fcc 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -35,15 +35,19 @@ export default abstract class WorkerBroadcastChannel extends BroadcastChannel { protected validateMessageEvent(messageEvent: MessageEvent): MessageEvent | false { if (Array.isArray(messageEvent.data) === false) { logger.error( - this.logPrefix(moduleName, 'validateMessageEvent') + - ' Worker broadcast channel protocol message event data is not an array' + `${this.logPrefix( + moduleName, + 'validateMessageEvent' + )} Worker broadcast channel protocol message event data is not an array` ); return false; } if (Utils.validateUUID(messageEvent.data[0]) === false) { logger.error( - this.logPrefix(moduleName, 'validateMessageEvent') + - ' Worker broadcast channel protocol message event data UUID field is invalid' + `${this.logPrefix( + moduleName, + 'validateMessageEvent' + )} Worker broadcast channel protocol message event data UUID field is invalid` ); return false; } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index f62e0ef0..6f77cde0 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -337,7 +337,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ...args: any[] ) => Promise, chargingStation, - (commandPayload.type + 'Reset') as OCPP16StopTransactionReason + `${commandPayload.type}Reset` as OCPP16StopTransactionReason ) .catch(() => { /* This is intentional */ @@ -365,7 +365,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } if (connectorId === 0) { logger.error( - chargingStation.logPrefix() + ' Trying to unlock connector Id ' + connectorId.toString() + `${chargingStation.logPrefix()} Trying to unlock connector Id ${connectorId.toString()}` ); return OCPPConstants.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED; } @@ -694,15 +694,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ): Promise { const transactionConnectorId = commandPayload.connectorId; if (chargingStation.connectors.has(transactionConnectorId) === true) { - const remoteStartTransactionLogMsg = - chargingStation.logPrefix() + - ' Transaction remotely STARTED on ' + - chargingStation.stationInfo.chargingStationId + - '#' + - transactionConnectorId.toString() + - " for idTag '" + - commandPayload.idTag + - "'"; + const remoteStartTransactionLogMsg = `${chargingStation.logPrefix()} Transaction remotely STARTED on ${ + chargingStation.stationInfo.chargingStationId + }#${transactionConnectorId.toString()} for idTag '${commandPayload.idTag}'`; await chargingStation.ocppRequestService.requestHandler< OCPP16StatusNotificationRequest, OCPP16StatusNotificationResponse @@ -855,16 +849,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; } logger.warn( - chargingStation.logPrefix() + - ' Remote starting transaction REJECTED on connector Id ' + - connectorId.toString() + - ", idTag '" + - idTag + - "', availability '" + - chargingStation.getConnectorStatus(connectorId).availability + - "', status '" + - chargingStation.getConnectorStatus(connectorId).status + - "'" + `${chargingStation.logPrefix()} Remote starting transaction REJECTED on connector Id ${connectorId.toString()}, idTag '${idTag}', availability '${ + chargingStation.getConnectorStatus(connectorId).availability + }', status '${chargingStation.getConnectorStatus(connectorId).status}'` ); return OCPPConstants.OCPP_RESPONSE_REJECTED; } @@ -923,9 +910,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } } logger.warn( - chargingStation.logPrefix() + - ' Trying to remote stop a non existing transaction ' + - transactionId.toString() + `${chargingStation.logPrefix()} Trying to remote stop a non existing transaction ${transactionId.toString()}` ); return OCPPConstants.OCPP_RESPONSE_REJECTED; } @@ -1068,7 +1053,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer .readdirSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../')) .filter((file) => file.endsWith('.log')) .map((file) => path.join('./', file)); - const diagnosticsArchive = chargingStation.stationInfo.chargingStationId + '_logs.tar.gz'; + const diagnosticsArchive = `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`; tar.create({ gzip: true }, logFiles).pipe(fs.createWriteStream(diagnosticsArchive)); ftpClient = new Client(); const accessResponse = await ftpClient.access({ @@ -1123,7 +1108,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer throw new OCPPError( ErrorType.GENERIC_ERROR, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${ - uploadResponse?.code && '|' + uploadResponse?.code.toString() + uploadResponse?.code && `|${uploadResponse?.code.toString()}` }`, OCPP16IncomingRequestCommand.GET_DIAGNOSTICS ); @@ -1131,7 +1116,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer throw new OCPPError( ErrorType.GENERIC_ERROR, `Diagnostics transfer failed with error code ${accessResponse.code.toString()}${ - uploadResponse?.code && '|' + uploadResponse?.code.toString() + uploadResponse?.code && `|${uploadResponse?.code.toString()}` }`, OCPP16IncomingRequestCommand.GET_DIAGNOSTICS ); diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index effa3abd..330f6672 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -343,8 +343,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { : logger.info(logMsg); } else { logger.error( - chargingStation.logPrefix() + - ' Charging station boot notification response received: %j with undefined registration status', + `${chargingStation.logPrefix()} Charging station boot notification response received: %j with undefined registration status`, payload ); } @@ -365,24 +364,24 @@ export default class OCPP16ResponseService extends OCPPResponseService { break; } } - const isAuthorizeConnectorIdDefined = authorizeConnectorId !== undefined; + const authorizeConnectorIdDefined = authorizeConnectorId !== undefined; if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) { - isAuthorizeConnectorIdDefined && + authorizeConnectorIdDefined && (chargingStation.getConnectorStatus(authorizeConnectorId).idTagAuthorized = true); logger.debug( `${chargingStation.logPrefix()} IdTag '${requestPayload.idTag}' accepted${ - isAuthorizeConnectorIdDefined ? ` on connector ${authorizeConnectorId}` : '' + authorizeConnectorIdDefined ? ` on connector ${authorizeConnectorId}` : '' }` ); } else { - if (isAuthorizeConnectorIdDefined) { + if (authorizeConnectorIdDefined) { chargingStation.getConnectorStatus(authorizeConnectorId).idTagAuthorized = false; delete chargingStation.getConnectorStatus(authorizeConnectorId).authorizeIdTag; } logger.debug( `${chargingStation.logPrefix()} IdTag '${requestPayload.idTag}' rejected with status '${ payload.idTagInfo.status - }'${isAuthorizeConnectorIdDefined ? ` on connector ${authorizeConnectorId}` : ''}` + }'${authorizeConnectorIdDefined ? ` on connector ${authorizeConnectorId}` : ''}` ); } } @@ -403,9 +402,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { } if (!transactionConnectorId) { logger.error( - chargingStation.logPrefix() + - ' Trying to start a transaction on a non existing connector Id ' + - connectorId.toString() + `${chargingStation.logPrefix()} Trying to start a transaction on a non existing connector Id ${connectorId.toString()}` ); return; } @@ -417,11 +414,9 @@ export default class OCPP16ResponseService extends OCPPResponseService { chargingStation.getConnectorStatus(connectorId).idTagLocalAuthorized === false ) { logger.error( - chargingStation.logPrefix() + - ' Trying to start a transaction with a not local authorized idTag ' + - chargingStation.getConnectorStatus(connectorId).localAuthorizeIdTag + - ' on connector Id ' + - connectorId.toString() + `${chargingStation.logPrefix()} Trying to start a transaction with a not local authorized idTag ${ + chargingStation.getConnectorStatus(connectorId).localAuthorizeIdTag + } on connector Id ${connectorId.toString()}` ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); return; @@ -434,11 +429,9 @@ export default class OCPP16ResponseService extends OCPPResponseService { chargingStation.getConnectorStatus(connectorId).idTagAuthorized === false ) { logger.error( - chargingStation.logPrefix() + - ' Trying to start a transaction with a not authorized idTag ' + - chargingStation.getConnectorStatus(connectorId).authorizeIdTag + - ' on connector Id ' + - connectorId.toString() + `${chargingStation.logPrefix()} Trying to start a transaction with a not authorized idTag ${ + chargingStation.getConnectorStatus(connectorId).authorizeIdTag + } on connector Id ${connectorId.toString()}` ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); return; @@ -448,13 +441,11 @@ export default class OCPP16ResponseService extends OCPPResponseService { chargingStation.getConnectorStatus(connectorId).authorizeIdTag !== requestPayload.idTag ) { logger.error( - chargingStation.logPrefix() + - ' Trying to start a transaction with an idTag ' + - requestPayload.idTag + - ' different from the authorize request one ' + - chargingStation.getConnectorStatus(connectorId).authorizeIdTag + - ' on connector Id ' + - connectorId.toString() + `${chargingStation.logPrefix()} Trying to start a transaction with an idTag ${ + requestPayload.idTag + } different from the authorize request one ${ + chargingStation.getConnectorStatus(connectorId).authorizeIdTag + } on connector Id ${connectorId.toString()}` ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); return; @@ -464,23 +455,18 @@ export default class OCPP16ResponseService extends OCPPResponseService { chargingStation.getConnectorStatus(connectorId).localAuthorizeIdTag !== requestPayload.idTag ) { logger.error( - chargingStation.logPrefix() + - ' Trying to start a transaction with an idTag ' + - requestPayload.idTag + - ' different from the local authorized one ' + - chargingStation.getConnectorStatus(connectorId).localAuthorizeIdTag + - ' on connector Id ' + - connectorId.toString() + `${chargingStation.logPrefix()} Trying to start a transaction with an idTag ${ + requestPayload.idTag + } different from the local authorized one ${ + chargingStation.getConnectorStatus(connectorId).localAuthorizeIdTag + } on connector Id ${connectorId.toString()}` ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); return; } 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 ${connectorId.toString()}: %j`, chargingStation.getConnectorStatus(connectorId) ); return; @@ -538,16 +524,9 @@ export default class OCPP16ResponseService extends OCPPResponseService { }); chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.CHARGING; logger.info( - chargingStation.logPrefix() + - ' Transaction ' + - payload.transactionId.toString() + - ' STARTED on ' + - chargingStation.stationInfo.chargingStationId + - '#' + - connectorId.toString() + - " for idTag '" + - requestPayload.idTag + - "'" + `${chargingStation.logPrefix()} Transaction ${payload.transactionId.toString()} STARTED on ${ + chargingStation.stationInfo.chargingStationId + }#${connectorId.toString()} for idTag '${requestPayload.idTag}'` ); if (chargingStation.stationInfo.powerSharedByConnectors) { chargingStation.powerDivider++; @@ -565,14 +544,9 @@ export default class OCPP16ResponseService extends OCPPResponseService { ); } else { logger.warn( - chargingStation.logPrefix() + - ' Starting transaction id ' + - payload.transactionId.toString() + - " REJECTED with status '" + - payload.idTagInfo?.status + - "', idTag '" + - requestPayload.idTag + - "'" + `${chargingStation.logPrefix()} Starting transaction id ${payload.transactionId.toString()} REJECTED with status '${ + payload.idTagInfo?.status + }', idTag '${requestPayload.idTag}'` ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); } @@ -608,9 +582,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { ); if (!transactionConnectorId) { logger.error( - chargingStation.logPrefix() + - ' Trying to stop a non existing transaction ' + - requestPayload.transactionId.toString() + `${chargingStation.logPrefix()} Trying to stop a non existing transaction ${requestPayload.transactionId.toString()}` ); return; } diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index 6bc6a5c2..442c6c1d 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -180,8 +180,7 @@ export default class OCPP20ResponseService extends OCPPResponseService { : logger.info(logMsg); } else { logger.error( - chargingStation.logPrefix() + - ' Charging station boot notification response received: %j with undefined registration status', + `${chargingStation.logPrefix()} Charging station boot notification response received: %j with undefined registration status`, payload ); } diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index f3c4e5e6..ef9d393a 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -162,16 +162,13 @@ export default class PerformanceStatistics { this.logStatistics(); }, Configuration.getLogStatisticsInterval() * 1000); logger.info( - this.logPrefix() + - ' logged every ' + - Utils.formatDurationSeconds(Configuration.getLogStatisticsInterval()) + `${this.logPrefix()} logged every ${Utils.formatDurationSeconds( + Configuration.getLogStatisticsInterval() + )}` ); } else { logger.info( - this.logPrefix() + - ' log interval is set to ' + - Configuration.getLogStatisticsInterval().toString() + - '. Not logging statistics' + `${this.logPrefix()} log interval is set to ${Configuration.getLogStatisticsInterval().toString()}. Not logging statistics` ); } } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 0d0f68e7..f1f43bcf 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -328,13 +328,13 @@ export default class Configuration { ) { console.error( chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage in section '${sectionName}'${ - logMsgToAppend && '. ' + logMsgToAppend + logMsgToAppend && `. ${logMsgToAppend}` }}` ); } else if (!Configuration.isUndefined(Configuration.getConfig()[key])) { console.error( chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage${ - logMsgToAppend && '. ' + logMsgToAppend + logMsgToAppend && `. ${logMsgToAppend}` }}` ); } diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 203054dc..89119bc2 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -39,15 +39,15 @@ export default class Utils { let secondsStr = seconds.toString(); if (hours < 10) { - hoursStr = '0' + hours.toString(); + hoursStr = `0${hours.toString()}`; } if (minutes < 10) { - minutesStr = '0' + minutes.toString(); + minutesStr = `0${minutes.toString()}`; } if (seconds < 10) { - secondsStr = '0' + seconds.toString(); + secondsStr = `0${seconds.toString()}`; } - return hoursStr + ':' + minutesStr + ':' + secondsStr.substring(0, 6); + return `${hoursStr}:${minutesStr}:${secondsStr.substring(0, 6)}`; } public static formatDurationSeconds(duration: number): string { diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index cf989400..e78836fd 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -170,7 +170,7 @@ export default class UIClient { const response = JSON.parse(messageEvent.data) as ProtocolResponse; if (Array.isArray(response) === false) { - throw new Error('Response not an array: ' + JSON.stringify(response, null, 2)); + throw new Error(`Response not an array: ${JSON.stringify(response, null, 2)}`); } const [uuid, responsePayload] = response; @@ -188,7 +188,7 @@ export default class UIClient { } this.deleteResponseHandler(uuid); } else { - throw new Error('Not a response to a request: ' + JSON.stringify(response, null, 2)); + throw new Error(`Not a response to a request: ${JSON.stringify(response, null, 2)}`); } } } -- 2.34.1