From: Jérôme Benoit Date: Thu, 26 Jan 2023 21:45:30 +0000 (+0100) Subject: Use arrow function for log messages prefixing X-Git-Tag: v1.1.93~35 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8b7072dca602c80ec6ef9a3463b6d53b43aa8fa5;p=e-mobility-charging-stations-simulator.git Use arrow function for log messages prefixing Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index b5058291..fd085890 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -106,7 +106,7 @@ export default class AuthorizedTagsCache { return authorizedTags; } - private logPrefix(file: string): string { + private logPrefix = (file: string): string => { return Utils.logPrefix(` Authorized tags cache for authorization file '${file}' |`); - } + }; } diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 0f26d3a2..dca2e060 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -434,13 +434,13 @@ export default class AutomaticTransactionGenerator extends AsyncResource { } } - private logPrefix(connectorId?: number): string { + private logPrefix = (connectorId?: number): string => { return Utils.logPrefix( ` ${this.chargingStation.stationInfo.chargingStationId} | ATG${ connectorId !== undefined ? ` on connector #${connectorId.toString()}` : '' }:` ); - } + }; private handleStartTransactionResponse( connectorId: number, diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index abd3093a..88b4b4c4 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -289,7 +289,7 @@ export class Bootstrap { ++this.numberOfChargingStations; } - private logPrefix(): string { + private logPrefix = (): string => { return Utils.logPrefix(' Bootstrap |'); - } + }; } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 514d50ce..b827b922 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -157,14 +157,14 @@ export default class ChargingStation { ); } - public logPrefix(): string { + public logPrefix = (): string => { return Utils.logPrefix( ` ${ this?.stationInfo?.chargingStationId ?? ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile()) } |` ); - } + }; public hasAuthorizedTags(): boolean { return !Utils.isEmptyArray( diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index aa696fcc..37987437 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -54,7 +54,7 @@ export default abstract class WorkerBroadcastChannel extends BroadcastChannel { return messageEvent; } - private logPrefix(modName: string, methodName: string): string { + private logPrefix = (modName: string, methodName: string): string => { return Utils.logPrefix(` Worker Broadcast Channel | ${modName}.${methodName}:`); - } + }; } diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index c85ccf2f..6d211828 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -283,7 +283,7 @@ export class OCPPServiceUtils { : numberValue * options.unitMultiplier; } - private static logPrefix(ocppVersion: OCPPVersion): string { + private static logPrefix = (ocppVersion: OCPPVersion): string => { return Utils.logPrefix(` OCPP ${ocppVersion} |`); - } + }; } diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index f475b8ef..50bdfb59 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -60,12 +60,12 @@ export default class UIHttpServer extends AbstractUIServer { } } - public logPrefix(modName?: string, methodName?: string, prefixSuffix?: string): string { + public logPrefix = (modName?: string, methodName?: string, prefixSuffix?: string): string => { const logMsgPrefix = prefixSuffix ? `UI HTTP Server ${prefixSuffix}` : 'UI HTTP Server'; const logMsg = modName && methodName ? ` ${logMsgPrefix} | ${modName}.${methodName}:` : ` ${logMsgPrefix} |`; return Utils.logPrefix(logMsg); - } + }; private requestListener(req: IncomingMessage, res: ServerResponse): void { this.authenticate(req, (err) => { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index d6240e31..c00b8c28 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -145,14 +145,14 @@ export default class UIWebSocketServer extends AbstractUIServer { } } - public logPrefix(modName?: string, methodName?: string, prefixSuffix?: string): string { + public logPrefix = (modName?: string, methodName?: string, prefixSuffix?: string): string => { const logMsgPrefix = prefixSuffix ? `UI WebSocket Server ${prefixSuffix}` : 'UI WebSocket Server'; const logMsg = modName && methodName ? ` ${logMsgPrefix} | ${modName}.${methodName}:` : ` ${logMsgPrefix} |`; return Utils.logPrefix(logMsg); - } + }; private broadcastToClients(message: string): void { for (const client of this.webSocketServer.clients) { diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 1dd0ee27..c00ad920 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -123,9 +123,9 @@ export default abstract class AbstractUIService { this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload)); } - public logPrefix(modName: string, methodName: string): string { + public logPrefix = (modName: string, methodName: string): string => { return this.uiServer.logPrefix(modName, methodName, this.version); - } + }; public deleteBroadcastChannelRequest(uuid: string): void { this.broadcastChannelRequests.delete(uuid); diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index ad1f85ba..1d3bb76c 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -290,7 +290,7 @@ export default class PerformanceStatistics { return timeSeries.map((timeSeriesItem) => timeSeriesItem.value); } - private logPrefix(): string { + private logPrefix = (): string => { return Utils.logPrefix(` ${this.objName} | Performance statistics`); - } + }; } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 8490be4e..e3daddf7 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -318,9 +318,9 @@ export default class Configuration { : SupervisionUrlDistribution.ROUND_ROBIN; } - private static logPrefix(): string { + private static logPrefix = (): string => { return `${new Date().toLocaleString()} Simulator configuration |`; - } + }; private static warnDeprecatedConfigurationKey( key: string, diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index f81acb1c..81026720 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -11,9 +11,9 @@ export default class Utils { // This is intentional } - public static logPrefix(prefixString = ''): string { + public static logPrefix = (prefixString = ''): string => { return `${new Date().toLocaleString()}${prefixString}`; - } + }; public static generateUUID(): string { return crypto.randomUUID();