From fda945c0eb6685d317506d0db9e4651186540442 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Thu, 22 Dec 2022 01:12:56 +0100 Subject: [PATCH 01/11] logger - perf optimizations --- src/integration/billing/BillingFacade.ts | 8 +-- src/integration/billing/BillingFactory.ts | 2 +- src/integration/billing/BillingIntegration.ts | 44 ++++++------- .../stripe/StripeBillingIntegration.ts | 56 ++++++++-------- src/utils/LightLogger.ts | 19 ++++++ src/utils/Logging.ts | 64 ++++++++++++++++++- 6 files changed, 135 insertions(+), 58 deletions(-) create mode 100644 src/utils/LightLogger.ts diff --git a/src/integration/billing/BillingFacade.ts b/src/integration/billing/BillingFacade.ts index 62c20d29b1..665e93d2be 100644 --- a/src/integration/billing/BillingFacade.ts +++ b/src/integration/billing/BillingFacade.ts @@ -34,7 +34,7 @@ export default class BillingFacade { }; } catch (error) { const message = `Billing - Start Transaction failed with Transaction ID '${transaction.id}'`; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.BILLING_TRANSACTION, @@ -66,7 +66,7 @@ export default class BillingFacade { } } catch (error) { const message = `Billing - Update Transaction failed with Transaction ID '${transaction.id}'`; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.BILLING_TRANSACTION, @@ -92,7 +92,7 @@ export default class BillingFacade { } } catch (error) { const message = `Billing - Stop Transaction failed with Transaction ID '${transaction.id}'`; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.BILLING_TRANSACTION, @@ -119,7 +119,7 @@ export default class BillingFacade { } } catch (error) { const message = `Billing - End Transaction failed with Transaction ID '${transaction.id}'`; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.BILLING_TRANSACTION, diff --git a/src/integration/billing/BillingFactory.ts b/src/integration/billing/BillingFactory.ts index f4f6543fae..17c8b42981 100644 --- a/src/integration/billing/BillingFactory.ts +++ b/src/integration/billing/BillingFactory.ts @@ -26,7 +26,7 @@ export default class BillingFactory { } return billingIntegrationImpl; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.BILLING, module: MODULE_NAME, method: 'getBillingImpl', diff --git a/src/integration/billing/BillingIntegration.ts b/src/integration/billing/BillingIntegration.ts index 76f367a7da..54c78d1ee9 100644 --- a/src/integration/billing/BillingIntegration.ts +++ b/src/integration/billing/BillingIntegration.ts @@ -45,7 +45,7 @@ export default abstract class BillingIntegration { let billingUser: BillingUser = null; try { billingUser = await this._synchronizeUser(user); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, actionOnUser: user, action: ServerAction.BILLING_SYNCHRONIZE_USER, @@ -54,7 +54,7 @@ export default abstract class BillingIntegration { }); return billingUser; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, actionOnUser: user, action: ServerAction.BILLING_SYNCHRONIZE_USER, @@ -71,14 +71,14 @@ export default abstract class BillingIntegration { try { billingUser = await this._synchronizeUser(user, true /* !forceMode */); if (user?.billingData?.customerID !== billingUser?.billingData?.customerID) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_FORCE_SYNCHRONIZE_USER, module: MODULE_NAME, method: 'forceSynchronizeUser', message: `CustomerID has been repaired - old value ${user?.billingData?.customerID} - ${billingUser?.billingData?.customerID}` }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_FORCE_SYNCHRONIZE_USER, actionOnUser: user, @@ -86,7 +86,7 @@ export default abstract class BillingIntegration { message: `Successfully forced the synchronization of user: '${user.id}' - '${user.email}'`, }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, actionOnUser: user, action: ServerAction.BILLING_FORCE_SYNCHRONIZE_USER, @@ -132,7 +132,7 @@ export default abstract class BillingIntegration { // Make sure to avoid trying to charge it again too soon if (!taskConfig?.forceOperation && moment(invoice.createdOn).isSame(moment(), 'day')) { actionsDone.inSuccess++; - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: invoice.user, @@ -146,7 +146,7 @@ export default abstract class BillingIntegration { // The new invoice may now have a different status - and this impacts the pagination skip--; // This is very important! } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: invoice.user, @@ -156,7 +156,7 @@ export default abstract class BillingIntegration { actionsDone.inSuccess++; } catch (error) { actionsDone.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: invoice.user, @@ -201,7 +201,7 @@ export default abstract class BillingIntegration { return true; } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TRANSACTION, actionOnUser: billingInvoice.user, @@ -313,7 +313,7 @@ export default abstract class BillingIntegration { } } catch (error) { // Catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_CHARGE_INVOICE, actionOnUser: billingInvoice.user, @@ -330,7 +330,7 @@ export default abstract class BillingIntegration { if (!Utils.isDevelopmentEnv()) { const timeSpent = this.computeTimeSpentInSeconds(transaction); if (timeSpent < Constants.AFIREV_MINIMAL_DURATION_THRESHOLD /* 2 minutes */) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: transaction.userID, @@ -342,7 +342,7 @@ export default abstract class BillingIntegration { return false; } if (transaction.stop.totalConsumptionWh < Constants.AFIREV_MINIMAL_CONSUMPTION_THRESHOLD /* 0.5 kW.h */) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: transaction.userID, @@ -427,21 +427,21 @@ export default abstract class BillingIntegration { // eslint-disable-next-line @typescript-eslint/member-ordering public async clearTestData(): Promise { // await this.checkConnection(); - stripe connection is useless to cleanup test data - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, module: MODULE_NAME, method: 'clearTestData', message: 'Starting test data cleanup' }); await this.clearAllInvoiceTestData(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, module: MODULE_NAME, method: 'clearTestData', message: 'Invoice Test data cleanup has been completed' }); await this.clearAllUsersTestData(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, module: MODULE_NAME, method: 'clearTestData', @@ -455,7 +455,7 @@ export default abstract class BillingIntegration { for (const invoice of invoices.result) { try { await this.clearInvoiceTestData(invoice); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, actionOnUser: invoice.user, @@ -463,7 +463,7 @@ export default abstract class BillingIntegration { message: `Successfully clear test data for invoice '${invoice.id}'` }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, actionOnUser: invoice.user, @@ -508,7 +508,7 @@ export default abstract class BillingIntegration { // Save to clear billing data await TransactionStorage.saveTransactionBillingData(this.tenant, transaction.id, transaction.billingData); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, module: MODULE_NAME, method: 'clearTransactionsTestData', @@ -525,7 +525,7 @@ export default abstract class BillingIntegration { for (const user of users) { try { await this.clearUserTestBillingData(user); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, actionOnUser: user, @@ -533,7 +533,7 @@ export default abstract class BillingIntegration { message: `Successfully cleared user test data for Invoice of User ID '${user.id}'` }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TEST_DATA_CLEANUP, actionOnUser: user, @@ -741,7 +741,7 @@ export default abstract class BillingIntegration { actionsDone.inSuccess++; } catch (error) { actionsDone.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TRANSFER_DISPATCH_FUNDS, module: MODULE_NAME, method: 'dispatchCollectedFunds', @@ -775,7 +775,7 @@ export default abstract class BillingIntegration { }; const transferID = await BillingStorage.saveTransfer(this.tenant, transferToSave); await TransactionStorage.updateTransactionsWithTransferData(this.tenant, collectedFundReport.transactionIDs, transferID); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TRANSFER_DISPATCH_FUNDS, module: MODULE_NAME, method: 'dispatchCollectedFunds', diff --git a/src/integration/billing/stripe/StripeBillingIntegration.ts b/src/integration/billing/stripe/StripeBillingIntegration.ts index 54b5b484ec..7f48d452e7 100644 --- a/src/integration/billing/stripe/StripeBillingIntegration.ts +++ b/src/integration/billing/stripe/StripeBillingIntegration.ts @@ -226,7 +226,7 @@ export default class StripeBillingIntegration extends BillingIntegration { requestParams.starting_after = taxes[taxes.length - 1].id; } } while (request.has_more); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TAXES, module: MODULE_NAME, method: 'getTaxes', @@ -234,7 +234,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }); } catch (error) { // catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TAXES, module: MODULE_NAME, method: 'getTaxes', @@ -256,7 +256,7 @@ export default class StripeBillingIntegration extends BillingIntegration { } } catch (error) { // catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TAXES, module: MODULE_NAME, method: 'getTaxRate', @@ -442,7 +442,7 @@ export default class StripeBillingIntegration extends BillingIntegration { await BillingStorage.saveInvoice(this.tenant, billingInvoice); throw operationResult.error; } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_CHARGE_INVOICE, actionOnUser: billingInvoice.user, @@ -539,7 +539,7 @@ export default class StripeBillingIntegration extends BillingIntegration { // Check billing data consistency const customerID = user?.billingData?.customerID; const paymentMethods: BillingPaymentMethod[] = await this.getStripePaymentMethods(user, customerID); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, user, action: ServerAction.BILLING_PAYMENT_METHODS, @@ -574,7 +574,7 @@ export default class StripeBillingIntegration extends BillingIntegration { const setupIntent: Stripe.SetupIntent = await this.stripe.setupIntents.create({ customer: customerID }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_SETUP_PAYMENT_METHOD, module: MODULE_NAME, method: 'createSetupIntent', @@ -588,7 +588,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }; } catch (error) { // catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_SETUP_PAYMENT_METHOD, actionOnUser: user, @@ -617,7 +617,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }; } await this.stripe.paymentMethods.update(paymentMethodId, paymentMethodUpdateParams); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_SETUP_PAYMENT_METHOD, module: MODULE_NAME, method: 'attachPaymentMethod', @@ -627,7 +627,7 @@ export default class StripeBillingIntegration extends BillingIntegration { await this.stripe.customers.update(customerID, { invoice_settings: { default_payment_method: paymentMethodId } }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_SETUP_PAYMENT_METHOD, module: MODULE_NAME, method: 'attachPaymentMethod', @@ -640,7 +640,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }; } catch (error) { // catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_SETUP_PAYMENT_METHOD, actionOnUser: user, @@ -677,7 +677,7 @@ export default class StripeBillingIntegration extends BillingIntegration { } while (response.has_more); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_PAYMENT_METHODS, actionOnUser: user, @@ -698,7 +698,7 @@ export default class StripeBillingIntegration extends BillingIntegration { const paymentMethod = await this.stripe.paymentMethods.retrieve(paymentMethodID); return this.convertToBillingPaymentMethod(paymentMethod, asDefault); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_PAYMENT_METHODS, module: MODULE_NAME, method: 'getStripePaymentMethod', @@ -735,7 +735,7 @@ export default class StripeBillingIntegration extends BillingIntegration { } // Detach payment method from the stripe customer const paymentMethod: Stripe.PaymentMethod = await this.stripe.paymentMethods.detach(paymentMethodId); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_DELETE_PAYMENT_METHOD, module: MODULE_NAME, method: 'detachStripePaymentMethod', @@ -748,7 +748,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }; } catch (error) { // catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_DELETE_PAYMENT_METHOD, module: MODULE_NAME, method: 'detachStripePaymentMethod', @@ -775,7 +775,7 @@ export default class StripeBillingIntegration extends BillingIntegration { // Well ... when in test mode we may allow to start the transaction if (!customerID) { // Not yet LIVE ... starting a transaction without a STRIPE CUSTOMER is allowed - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TRANSACTION, module: MODULE_NAME, method: 'startTransaction', @@ -958,7 +958,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }; } if (transaction.billingData?.stop?.status === BillingStatus.BILLED) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TRANSACTION, module: MODULE_NAME, method: 'endTransaction', @@ -972,7 +972,7 @@ export default class StripeBillingIntegration extends BillingIntegration { return transaction.billingData.stop; } if (!transaction.stop?.extraInactivityComputed) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING_TRANSACTION, module: MODULE_NAME, method: 'endTransaction', @@ -1010,7 +1010,7 @@ export default class StripeBillingIntegration extends BillingIntegration { const customerID: string = transaction.user?.billingData?.customerID; const customer = await this.getStripeCustomer(customerID); if (customer) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: transaction.userID, @@ -1034,7 +1034,7 @@ export default class StripeBillingIntegration extends BillingIntegration { }; } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: transaction.userID, @@ -1203,7 +1203,7 @@ export default class StripeBillingIntegration extends BillingIntegration { // Let's try to bill the stripe invoice using the default payment method of the customer operationResult = await this.chargeStripeInvoice(stripeInvoice.id); if (!operationResult?.succeeded && operationResult?.error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, user: user.id, action: ServerAction.BILLING_TRANSACTION, @@ -1364,7 +1364,7 @@ export default class StripeBillingIntegration extends BillingIntegration { status: BillingInvoiceStatus.OPEN, }); if (list && !Utils.isEmptyArray(list.data)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.USER_DELETE, actionOnUser: user, @@ -1379,7 +1379,7 @@ export default class StripeBillingIntegration extends BillingIntegration { status: BillingInvoiceStatus.DRAFT, }); if (list && !Utils.isEmptyArray(list.data)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.USER_DELETE, actionOnUser: user, @@ -1394,7 +1394,7 @@ export default class StripeBillingIntegration extends BillingIntegration { pending: true, }); if (itemsList && itemsList.data && itemsList.data.length > 0) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.USER_DELETE, actionOnUser: user, @@ -1541,7 +1541,7 @@ export default class StripeBillingIntegration extends BillingIntegration { try { await this.checkConnection(); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, user, action: ServerAction.BILLING, module: MODULE_NAME, method: 'precheckStartTransactionPrerequisites', @@ -1554,7 +1554,7 @@ export default class StripeBillingIntegration extends BillingIntegration { try { await this.checkTaxPrerequisites(); // Checks that the taxID is still valid } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, user, action: ServerAction.BILLING, module: MODULE_NAME, method: 'precheckStartTransactionPrerequisites', @@ -1571,7 +1571,7 @@ export default class StripeBillingIntegration extends BillingIntegration { // Check whether the customer has a default payment method await this.checkStripePaymentMethod(customer); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, user, action: ServerAction.BILLING, module: MODULE_NAME, method: 'precheckStartTransactionPrerequisites', @@ -1674,7 +1674,7 @@ export default class StripeBillingIntegration extends BillingIntegration { // This method is ONLY USED when repairing invoices - c.f.: RepairInvoiceInconsistencies migration task if (!billingInvoice.sessions) { // This should not happen - but it happened once! - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING, actionOnUser: billingInvoice.user, @@ -1706,7 +1706,7 @@ export default class StripeBillingIntegration extends BillingIntegration { } } catch (error) { // Catch stripe errors and send the information back to the client - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.BILLING, actionOnUser: billingInvoice.user, diff --git a/src/utils/LightLogger.ts b/src/utils/LightLogger.ts new file mode 100644 index 0000000000..3637574a16 --- /dev/null +++ b/src/utils/LightLogger.ts @@ -0,0 +1,19 @@ +import { Log, LogLevel } from '../types/Log'; + +import Logging from './Logging'; + +export default class LightLogger { + + private logLevel: LogLevel; + + public constructor(logLevel: LogLevel) { + this.logLevel = logLevel; + } + + public log(log: Log): void { + log.level = this.logLevel; + log.timestamp = new Date(); + Logging.lightLog(log); + } +} + diff --git a/src/utils/Logging.ts b/src/utils/Logging.ts index 4b348957ff..68749efea3 100644 --- a/src/utils/Logging.ts +++ b/src/utils/Logging.ts @@ -10,6 +10,7 @@ import BackendError from '../exception/BackendError'; import Configuration from '../utils/Configuration'; import Constants from './Constants'; import { HTTPError } from '../types/HTTPError'; +import LightLogger from './LightLogger'; import LogConfiguration from '../types/configuration/LogConfiguration'; import LogStorage from '../storage/mongodb/LogStorage'; import { OCPIResult } from '../types/ocpi/OCPIResult'; @@ -32,6 +33,62 @@ export default class Logging { private static logConfig: LogConfiguration; private static traceConfig: TraceConfiguration; + public static isLevelEnabled(expectedLogLevel: LogLevel): boolean { + // Check the configuration for the actual log level being enabled + const logConfig = Logging.getConfiguration(); + const logLevelLetter = logConfig.logLevel ? logConfig.logLevel : 'D'; + const logLevel = logLevelLetter as LogLevel; + switch (logLevel) { + case LogLevel.NONE: + return false; + case LogLevel.INFO: + if (expectedLogLevel === LogLevel.DEBUG) { + return false; + } + break; + case LogLevel.WARNING: + if (expectedLogLevel === LogLevel.INFO || expectedLogLevel === LogLevel.DEBUG) { + return false; + } + break; + case LogLevel.ERROR: + if (expectedLogLevel === LogLevel.INFO || expectedLogLevel === LogLevel.WARNING || expectedLogLevel === LogLevel.DEBUG) { + return false; + } + break; + case LogLevel.DEBUG: + default: + break; + } + return true; + } + + public static lightLog(log: Log): void { + Logging.log(log).catch(() => { /* Intentional */ }); + } + + public static beError(): LightLogger { + return Logging.beThatLevel(LogLevel.ERROR); + } + + public static beWarning(): LightLogger { + return Logging.beThatLevel(LogLevel.WARNING); + } + + public static beInfo(): LightLogger { + return Logging.beThatLevel(LogLevel.INFO); + } + + public static beDebug(): LightLogger { + return Logging.beThatLevel(LogLevel.DEBUG); + } + + public static beThatLevel(expectedLogLevel: LogLevel): LightLogger { + if (Logging.isLevelEnabled(expectedLogLevel)) { + return new LightLogger(expectedLogLevel); + } + } + public static getConfiguration(): LogConfiguration { if (!this.logConfig) { this.logConfig = Configuration.getLogConfig(); @@ -898,9 +955,10 @@ export default class Logging { // Check Log Level const logConfig = Logging.getConfiguration(); // Default Log Level - const logLevel = logConfig.logLevel ? logConfig.logLevel : LogLevel.DEBUG; + const logLevelAsString = logConfig.logLevel ? logConfig.logLevel : 'D'; + const logLevel = logLevelAsString as LogLevel; // Log Level - switch (LogLevel[logLevel]) { + switch (logLevel) { // No log at all case LogLevel.NONE: return; @@ -928,7 +986,7 @@ export default class Logging { break; } // Timestamp - log.timestamp = new Date(); + log.timestamp = log.timestamp || new Date(); // Host log.host = Utils.getHostName(); if (log.detailedMessages) { From 363e6cb8b877386a2e0ff2a28ea4dacee0b863ab Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Thu, 22 Dec 2022 09:58:00 +0100 Subject: [PATCH 02/11] logger - perf improvements --- src/async-task/AsyncTaskBuilder.ts | 2 +- src/async-task/AsyncTaskManager.ts | 14 ++-- src/async-task/TenantAsyncTask.ts | 16 ++--- src/async-task/tasks/ImportHelper.ts | 2 +- src/async-task/tasks/TagsImportAsyncTask.ts | 6 +- src/async-task/tasks/UsersImportAsyncTask.ts | 6 +- src/authorization/Authorizations.ts | 2 +- src/bootstrap/LocalCarCatalogBootstrap.ts | 6 +- src/client/ocpi/CpoOCPIClient.ts | 32 ++++----- src/client/ocpi/EmspOCPIClient.ts | 10 +-- src/client/ocpi/OCPIClient.ts | 10 +-- src/client/ocpi/OCPIClientFactory.ts | 8 +-- .../json/JsonRestChargingStationClient.ts | 12 ++-- .../ocpp/soap/SoapChargingStationClient.ts | 16 ++--- src/client/oicp/CpoOICPClient.ts | 42 ++++++------ src/client/oicp/OICPClientFactory.ts | 4 +- src/integration/asset/AssetFactory.ts | 2 +- .../greencom/GreencomAssetIntegration.ts | 2 +- .../asset/iothink/IothinkAssetIntegration.ts | 2 +- .../asset/lacroix/LacroixAssetIntegration.ts | 2 +- .../schneider/SchneiderAssetIntegration.ts | 2 +- .../asset/wit/WitAssetIntegration.ts | 2 +- .../MercedesCarConnectorIntegration.ts | 8 +-- .../TargaTelematicsConnector.ts | 2 +- .../TronityCarConnectorIntegration.ts | 4 +- src/integration/car/CarIntegration.ts | 6 +- .../ev-database/EVDatabaseCarIntegration.ts | 6 +- .../ChargingStationVendorIntegration.ts | 30 ++++----- src/integration/pricing/PricingEngine.ts | 8 +-- .../BuiltInPricingIntegration.ts | 8 +-- src/integration/refund/RefundFactory.ts | 2 +- .../sap-concur/SapConcurRefundIntegration.ts | 20 +++--- .../SmartChargingIntegration.ts | 6 +- .../SapSmartChargingIntegration.ts | 20 +++--- src/locking/LockingManager.ts | 14 ++-- src/migration/MigrationHandler.ts | 12 ++-- src/migration/TenantMigrationTask.ts | 6 +- .../AddCompanyIDToChargingStationsTask.ts | 2 +- .../tasks/AddCompanyIDToTransactionsTask.ts | 2 +- ...elTemplateToChargingStationTemplateTask.ts | 4 +- src/migration/tasks/AddUserIDToCarsTask.ts | 2 +- .../AlignEntitiesWithOrganizationIDsTask.ts | 4 +- src/migration/tasks/MigrateSimplePricing.ts | 2 +- .../tasks/RemoveDuplicateTagVisualIDsTask.ts | 2 +- .../tasks/RepairInvoiceInconsistencies.ts | 10 +-- .../tasks/RepairTransactionBillingData.ts | 10 +-- .../RepairTransactionPricedAtZeroTask.ts | 6 +- .../RestoreDataIntegrityInSiteUsersTask.ts | 2 +- .../tasks/UpdateEmailsToLowercaseTask.ts | 2 +- src/notification/NotificationHandler.ts | 44 ++++++------- .../email/EMailNotificationTask.ts | 12 ++-- .../RemotePushNotificationTask.ts | 2 +- src/scheduler/SchedulerManager.ts | 8 +-- src/scheduler/SchedulerTask.ts | 6 +- src/scheduler/TenantSchedulerTask.ts | 16 ++--- .../tasks/BillPendingTransactionTask.ts | 14 ++-- .../tasks/CheckAndComputeSmartChargingTask.ts | 6 +- .../tasks/CheckChargingStationTemplateTask.ts | 6 +- .../tasks/CheckOfflineChargingStationsTask.ts | 2 +- .../tasks/CloseTransactionsInProgressTask.ts | 4 +- .../tasks/LoggingDatabaseTableCleanupTask.ts | 8 +-- .../SynchronizeRefundTransactionsTask.ts | 10 +-- src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts | 8 +-- .../tasks/ocpi/OCPICheckLocationsTask.ts | 8 +-- .../tasks/ocpi/OCPICheckSessionsTask.ts | 8 +-- src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts | 8 +-- .../tasks/ocpi/OCPIPullLocationsTask.ts | 8 +-- .../tasks/ocpi/OCPIPullSessionsTask.ts | 8 +-- .../tasks/ocpi/OCPIPullTokensTask.ts | 8 +-- src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts | 14 ++-- .../tasks/ocpi/OCPIPushEVSEStatusesTask.ts | 8 +-- .../tasks/ocpi/OCPIPushTokensTask.ts | 8 +-- .../tasks/oicp/OICPPushEvseDataTask.ts | 8 +-- .../tasks/oicp/OICPPushEvseStatusTask.ts | 8 +-- src/server/ServerUtils.ts | 2 +- src/server/ocpi/OCPIFacade.ts | 4 +- src/server/ocpi/OCPIUtils.ts | 6 +- src/server/ocpi/service/OCPIUtilsService.ts | 6 +- .../v2.1.1/CPOEMSPCredentialsService.ts | 16 ++--- .../service/cpo/v2.1.1/CPOCommandsService.ts | 32 ++++----- .../emsp/v2.1.1/EMSPCommandsService.ts | 4 +- src/server/ocpp/json/JsonOCPPServer.ts | 64 +++++++++--------- .../ocpp/json/web-socket/WSConnection.ts | 2 +- src/server/ocpp/services/OCPPService.ts | 66 +++++++++---------- src/server/ocpp/soap/SoapOCPPServer.ts | 4 +- src/server/ocpp/utils/OCPPCommon.ts | 12 ++-- src/server/ocpp/utils/OCPPUtils.ts | 62 ++++++++--------- src/server/ocpp/validator/OCPPValidator.ts | 6 +- src/server/odata/ODataRestAdapter.ts | 2 +- src/server/odata/odata-schema/ODataSchema.ts | 2 +- src/server/oicp/AbstractOICPService.ts | 8 +-- src/server/oicp/OICPFacade.ts | 4 +- .../CPORemoteAuthorizationsEndpoint.ts | 22 +++---- src/server/rest/RestServerService.ts | 4 +- src/server/rest/v1/service/AssetService.ts | 8 +-- src/server/rest/v1/service/AuthService.ts | 14 ++-- src/server/rest/v1/service/BillingService.ts | 8 +-- src/server/rest/v1/service/CarService.ts | 6 +- .../rest/v1/service/ChargingStationService.ts | 20 +++--- .../service/ChargingStationTemplateService.ts | 6 +- src/server/rest/v1/service/CompanyService.ts | 6 +- .../rest/v1/service/ConnectionService.ts | 4 +- .../rest/v1/service/OCPIEndpointService.ts | 16 ++--- .../rest/v1/service/OICPEndpointService.ts | 18 ++--- src/server/rest/v1/service/PricingService.ts | 8 +-- .../v1/service/RegistrationTokenService.ts | 8 +-- src/server/rest/v1/service/SettingService.ts | 6 +- src/server/rest/v1/service/SiteAreaService.ts | 12 ++-- src/server/rest/v1/service/SiteService.ts | 12 ++-- src/server/rest/v1/service/TagService.ts | 28 ++++---- src/server/rest/v1/service/TenantService.ts | 8 +-- .../rest/v1/service/TransactionService.ts | 12 ++-- src/server/rest/v1/service/UserService.ts | 28 ++++---- src/server/rest/v1/service/UtilsService.ts | 2 +- src/start.ts | 11 ++-- src/storage/mongodb/MongoDBStorage.ts | 24 +++---- src/storage/mongodb/SiteAreaStorage.ts | 2 +- src/storage/mongodb/TagStorage.ts | 2 +- src/storage/mongodb/TransactionStorage.ts | 2 +- src/utils/Logging.ts | 8 +++ test/api/SecurityTest.ts | 32 ++++----- 121 files changed, 643 insertions(+), 636 deletions(-) diff --git a/src/async-task/AsyncTaskBuilder.ts b/src/async-task/AsyncTaskBuilder.ts index c8adac2703..d81d1854a0 100644 --- a/src/async-task/AsyncTaskBuilder.ts +++ b/src/async-task/AsyncTaskBuilder.ts @@ -25,7 +25,7 @@ export default class AsyncTaskBuilder { // Save await AsyncTaskStorage.saveAsyncTask(asyncTask as AsyncTask); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'createAndSaveAsyncTasks', diff --git a/src/async-task/AsyncTaskManager.ts b/src/async-task/AsyncTaskManager.ts index b67835e7a9..5d9dba6d0c 100644 --- a/src/async-task/AsyncTaskManager.ts +++ b/src/async-task/AsyncTaskManager.ts @@ -54,7 +54,7 @@ export default class AsyncTaskManager { public static async handleAsyncTasks(): Promise { let failedToAcquireLock = false; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -75,7 +75,7 @@ export default class AsyncTaskManager { { status: AsyncTaskStatus.PENDING }, Constants.DB_PARAMS_MAX_LIMIT); // Process them if (!Utils.isEmptyArray(asyncTasks.result)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -98,7 +98,7 @@ export default class AsyncTaskManager { asyncTask.lastChangedOn = asyncTask.execTimestamp; await AsyncTaskStorage.saveAsyncTask(asyncTask); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -115,7 +115,7 @@ export default class AsyncTaskManager { await AsyncTaskStorage.saveAsyncTask(asyncTask); processedTask.inSuccess++; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -130,7 +130,7 @@ export default class AsyncTaskManager { asyncTask.lastChangedOn = new Date(); await AsyncTaskStorage.saveAsyncTask(asyncTask); // Log error - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'handleAsyncTasks', action: ServerAction.ASYNC_TASK, @@ -162,7 +162,7 @@ export default class AsyncTaskManager { void AsyncTaskManager.handleAsyncTasks(); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -201,7 +201,7 @@ export default class AsyncTaskManager { case AsyncTasks.OCPI_PUSH_EVSE_STATUSES: return new OCPIPushEVSEStatusesAsyncTask(asyncTask, correlationID); default: - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', diff --git a/src/async-task/TenantAsyncTask.ts b/src/async-task/TenantAsyncTask.ts index 913d6a30dd..86c219155a 100644 --- a/src/async-task/TenantAsyncTask.ts +++ b/src/async-task/TenantAsyncTask.ts @@ -23,7 +23,7 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { (taskSettings.task.disableAllTasks || !Utils.isEmptyArray(taskSettings.task.disableTasksInEnv) && taskSettings.task.disableTasksInEnv.includes(currentTaskEnv))) { // Tasks are disabled for this environment isTaskExecutionDisabled = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -43,7 +43,7 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { } // Check if tenant task needs to run on a specific env if (tenant.taskExecutionEnv && tenant.taskExecutionEnv !== currentTaskEnv) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -54,13 +54,13 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { } const tenantCorrelationID = Utils.generateShortNonUniqueID(); const startTimeInTenant = moment(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', message: `The Task '${this.getAsyncTask().name}~${this.getCorrelationID()}~${tenantCorrelationID}' is running for Tenant ${Utils.buildTenantName(tenant)}...` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -74,14 +74,14 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { // Hook await this.afterExecuteTenantAsyncTask(tenant); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', message: `Error while running the Task '${this.getAsyncTask().name}~${this.getCorrelationID()}~${tenantCorrelationID}' for Tenant ${Utils.buildTenantName(tenant)}: ${error.message as string}`, detailedMessages: { error: error.stack } }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -91,13 +91,13 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { } // Log Total Processing Time in Tenant const totalTimeSecsInTenant = moment.duration(moment().diff(startTimeInTenant)).asSeconds(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', message: `The Task '${this.getAsyncTask().name}~${this.getCorrelationID()}~${tenantCorrelationID}' has been run successfully in ${totalTimeSecsInTenant} secs for Tenant ${Utils.buildTenantName(tenant)}` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', diff --git a/src/async-task/tasks/ImportHelper.ts b/src/async-task/tasks/ImportHelper.ts index e0883efc8f..661d039772 100644 --- a/src/async-task/tasks/ImportHelper.ts +++ b/src/async-task/tasks/ImportHelper.ts @@ -140,7 +140,7 @@ export default class ImportHelper { await UserStorage.addSiteToUser(tenant, user.id, importedSiteID); } else { // Site does not exist - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'executeAsyncTask', diff --git a/src/async-task/tasks/TagsImportAsyncTask.ts b/src/async-task/tasks/TagsImportAsyncTask.ts index 550912d519..d4f41cfcb2 100644 --- a/src/async-task/tasks/TagsImportAsyncTask.ts +++ b/src/async-task/tasks/TagsImportAsyncTask.ts @@ -43,7 +43,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { // Get total number of Tags to import const totalTagsToImport = await TagStorage.getImportedTagsCount(tenant); if (totalTagsToImport > 0) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.TAGS_IMPORT, module: MODULE_NAME, method: 'processTenant', @@ -66,7 +66,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { importedTag.errorDescription = error.message; result.inError++; await TagStorage.saveImportedTag(tenant, importedTag); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.TAGS_IMPORT, module: MODULE_NAME, method: 'processTenant', @@ -77,7 +77,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { } if (!Utils.isEmptyArray(importedTags.result) && (result.inError + result.inSuccess) > 0) { const intermediateDurationSecs = Math.round((new Date().getTime() - startTime) / 1000); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.TAGS_IMPORT, module: MODULE_NAME, method: 'processTenant', diff --git a/src/async-task/tasks/UsersImportAsyncTask.ts b/src/async-task/tasks/UsersImportAsyncTask.ts index 400351c935..000411d703 100644 --- a/src/async-task/tasks/UsersImportAsyncTask.ts +++ b/src/async-task/tasks/UsersImportAsyncTask.ts @@ -42,7 +42,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { // Get total number of Users to import const totalUsersToImport = await UserStorage.getImportedUsersCount(tenant); if (totalUsersToImport > 0) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'processTenant', @@ -66,7 +66,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { result.inError++; // Update it await UserStorage.saveImportedUser(tenant, importedUser); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'executeAsyncTask', @@ -77,7 +77,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { } if (importedUsers.result.length > 0 && (result.inError + result.inSuccess) > 0) { const intermediateDurationSecs = Math.round((new Date().getTime() - startTime) / 1000); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'processTenant', diff --git a/src/authorization/Authorizations.ts b/src/authorization/Authorizations.ts index 76b5a03f2d..c80c39492b 100644 --- a/src/authorization/Authorizations.ts +++ b/src/authorization/Authorizations.ts @@ -946,7 +946,7 @@ export default class Authorizations { if (remoteAuthorization && OCPIUtils.isAuthorizationValid(remoteAuthorization.timestamp)) { // Check Tag ID if (remoteAuthorization.tagId === tag.ocpiToken?.uid) { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, message: `${Utils.buildConnectorInfo(connector.connectorId, transaction?.id)} Valid Remote Authorization found for Tag ID '${tag.ocpiToken.uid}'`, diff --git a/src/bootstrap/LocalCarCatalogBootstrap.ts b/src/bootstrap/LocalCarCatalogBootstrap.ts index ff4c2f1d77..87daede0d1 100644 --- a/src/bootstrap/LocalCarCatalogBootstrap.ts +++ b/src/bootstrap/LocalCarCatalogBootstrap.ts @@ -54,7 +54,7 @@ export default class LocalCarCatalogBootstrap { created++; } catch (error) { const message = `Error while importing the local Car ID '${carCatalog.id}': ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile', @@ -66,7 +66,7 @@ export default class LocalCarCatalogBootstrap { } } catch (error) { const message = `Error while importing the local Cars: ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile', @@ -77,7 +77,7 @@ export default class LocalCarCatalogBootstrap { // Log in the default tenant if (created > 0) { const message = `${created} local Car(s) catalog created in the default tenant`; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS, message, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile', diff --git a/src/client/ocpi/CpoOCPIClient.ts b/src/client/ocpi/CpoOCPIClient.ts index 13fa38b693..b71cf35e72 100644 --- a/src/client/ocpi/CpoOCPIClient.ts +++ b/src/client/ocpi/CpoOCPIClient.ts @@ -117,7 +117,7 @@ export default class CpoOCPIClient extends OCPIClient { } const numberOfTags = response.data.data.length as number; totalNumberOfTags += numberOfTags; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_GET_TOKENS, message: `${numberOfTags.toString()} Tokens retrieved from ${tokensUrl}`, @@ -162,7 +162,7 @@ export default class CpoOCPIClient extends OCPIClient { } const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_GET_TOKENS, message: `${numberOfTags.toString()} token(s) processed in ${executionDurationLoopSecs}s - Total of ${totalNumberOfTags} token(s) processed in ${executionDurationTotalLoopSecs}s`, @@ -239,7 +239,7 @@ export default class CpoOCPIClient extends OCPIClient { detailedMessages: { locationReference, authorizationInfo } }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_AUTHORIZE_TOKEN, @@ -284,7 +284,7 @@ export default class CpoOCPIClient extends OCPIClient { transaction.ocpiData = { session: ocpiSession }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_START_SESSION, @@ -330,7 +330,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_PUSH_SESSIONS, @@ -375,7 +375,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_STOP_SESSION, @@ -441,7 +441,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, @@ -451,7 +451,7 @@ export default class CpoOCPIClient extends OCPIClient { }); return true; } - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, @@ -758,7 +758,7 @@ export default class CpoOCPIClient extends OCPIClient { { concurrency: Constants.OCPI_MAX_PARALLEL_REQUESTS }); const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_UPDATE_STATUS, message: `${evses.length} EVSE Status(es) processed in ${executionDurationLoopSecs}s in Location '${location.name}' - Total of ${totalNumberOfEvses} EVSE(s) processed in ${executionDurationTotalLoopSecs}s`, @@ -862,7 +862,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation as ChargingStation), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_UPDATE_STATUS, @@ -896,7 +896,7 @@ export default class CpoOCPIClient extends OCPIClient { }); // Create if it does not exit if (response.data.status_code === 3001) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -918,7 +918,7 @@ export default class CpoOCPIClient extends OCPIClient { const cdr = response.data.data as OCPICdr; if (cdr) { // CDR checked - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -929,7 +929,7 @@ export default class CpoOCPIClient extends OCPIClient { return true; } } - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -964,7 +964,7 @@ export default class CpoOCPIClient extends OCPIClient { if (OCPIUtilsService.isSuccessResponse(response.data)) { const session = response.data.data as OCPISession; if (session) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -975,7 +975,7 @@ export default class CpoOCPIClient extends OCPIClient { return true; } } - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -1020,7 +1020,7 @@ export default class CpoOCPIClient extends OCPIClient { detailedMessages: { location, ocpiLocation } }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_LOCATIONS, message: `Location '${location.name}' with ID '${location.id}' checked successfully`, diff --git a/src/client/ocpi/EmspOCPIClient.ts b/src/client/ocpi/EmspOCPIClient.ts index 78f9e02cd8..b93a19490f 100644 --- a/src/client/ocpi/EmspOCPIClient.ts +++ b/src/client/ocpi/EmspOCPIClient.ts @@ -99,7 +99,7 @@ export default class EmspOCPIClient extends OCPIClient { currentSkip += Constants.DB_RECORD_COUNT_DEFAULT; const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, message: `${tokens.count.toString()} token(s) pushed in ${executionDurationLoopSecs}s - Total of ${totalNumberOfTokens} token(s) pushed in ${executionDurationTotalLoopSecs}s`, @@ -188,7 +188,7 @@ export default class EmspOCPIClient extends OCPIClient { } const numberOfLocations = response.data.data.length as number; totalNumberOfLocations += numberOfLocations; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_GET_TOKENS, message: `${numberOfLocations.toString()} Tokens retrieved from ${locationsUrl}`, @@ -237,7 +237,7 @@ export default class EmspOCPIClient extends OCPIClient { } const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, message: `${numberOfLocations.toString()} location(s) processed in ${executionDurationLoopSecs}s - Total of ${totalNumberOfLocations} location(s) processed in ${executionDurationTotalLoopSecs}s`, @@ -471,7 +471,7 @@ export default class EmspOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, ...LoggingHelper.getChargingStationProperties(chargingStation), action: ServerAction.OCPI_EMSP_START_SESSION, @@ -527,7 +527,7 @@ export default class EmspOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_EMSP_STOP_SESSION, diff --git a/src/client/ocpi/OCPIClient.ts b/src/client/ocpi/OCPIClient.ts index 72eb7387f2..5e36abb9c2 100644 --- a/src/client/ocpi/OCPIClient.ts +++ b/src/client/ocpi/OCPIClient.ts @@ -169,7 +169,7 @@ export default abstract class OCPIClient { } public async getVersions(): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_GET_VERSIONS, message: `Get OCPI Versions at ${this.ocpiEndpoint.baseUrl}`, @@ -188,7 +188,7 @@ export default abstract class OCPIClient { } public async getEndpointVersions(): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_GET_ENDPOINT_VERSIONS, message: `Get OCPI Services at ${this.ocpiEndpoint.versionUrl}`, @@ -267,7 +267,7 @@ export default abstract class OCPIClient { private async deleteCredentials(): Promise { // Get credentials url const credentialsUrl = this.getEndpointUrl('credentials', ServerAction.OCPI_CREATE_CREDENTIALS); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CREATE_CREDENTIALS, message: `Delete Credentials at ${credentialsUrl}`, @@ -288,7 +288,7 @@ export default abstract class OCPIClient { // Get credentials url const credentialsUrl = this.getEndpointUrl('credentials', ServerAction.OCPI_CREATE_CREDENTIALS); const credentials = await OCPIUtils.buildOcpiCredentialObject(this.tenant, this.ocpiEndpoint.localToken, this.ocpiEndpoint.role); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CREATE_CREDENTIALS, message: `Post Credentials at ${credentialsUrl}`, @@ -310,7 +310,7 @@ export default abstract class OCPIClient { // Get credentials url const credentialsUrl = this.getEndpointUrl('credentials', ServerAction.OCPI_UPDATE_CREDENTIALS); const credentials = await OCPIUtils.buildOcpiCredentialObject(this.tenant, this.ocpiEndpoint.localToken, this.ocpiEndpoint.role); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_UPDATE_CREDENTIALS, message: `Put Credentials at ${credentialsUrl}`, diff --git a/src/client/ocpi/OCPIClientFactory.ts b/src/client/ocpi/OCPIClientFactory.ts index 37084e7fc4..f2fabab363 100644 --- a/src/client/ocpi/OCPIClientFactory.ts +++ b/src/client/ocpi/OCPIClientFactory.ts @@ -22,7 +22,7 @@ export default class OCPIClientFactory { if (Utils.isTenantComponentActive(tenant, TenantComponents.OCPI)) { const ocpiSettings = await SettingStorage.getOCPISettings(tenant); if (!ocpiSettings && ocpiSettings.ocpi) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_SETTINGS, module: MODULE_NAME, method: 'getOcpiClient', @@ -37,7 +37,7 @@ export default class OCPIClientFactory { return new EmspOCPIClient(tenant, ocpiSettings.ocpi, ocpiEndpoint); } } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_SETTINGS, module: MODULE_NAME, method: 'getOcpiClient', @@ -52,7 +52,7 @@ export default class OCPIClientFactory { const client = await OCPIClientFactory.getOcpiClient(tenant, ocpiEndpoint); return client as CpoOCPIClient; } - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CLIENT_INITIALIZATION, module: MODULE_NAME, method: 'getCpoOcpiClient', @@ -65,7 +65,7 @@ export default class OCPIClientFactory { const client = await OCPIClientFactory.getOcpiClient(tenant, ocpiEndpoint); return client as EmspOCPIClient; } - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CLIENT_INITIALIZATION, module: MODULE_NAME, method: 'getEmspOcpiClient', diff --git a/src/client/ocpp/json/JsonRestChargingStationClient.ts b/src/client/ocpp/json/JsonRestChargingStationClient.ts index 8e7cc9728b..58fcce968b 100644 --- a/src/client/ocpp/json/JsonRestChargingStationClient.ts +++ b/src/client/ocpp/json/JsonRestChargingStationClient.ts @@ -119,7 +119,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Extract Current Command const triggeringCommand: Command = request[2]; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -145,7 +145,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Opened // eslint-disable-next-line @typescript-eslint/no-misused-promises this.wsConnection.onopen = async () => { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -161,7 +161,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Closed // eslint-disable-next-line @typescript-eslint/no-misused-promises this.wsConnection.onclose = async (code: number) => { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -176,7 +176,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Handle Error Message // eslint-disable-next-line @typescript-eslint/no-misused-promises this.wsConnection.onerror = async (error: Error) => { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -202,7 +202,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Check message type if (messageType === OCPPMessageType.CALL_ERROR_MESSAGE) { // Error message - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -224,7 +224,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient this.closeConnection(); } else { // Error message - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, diff --git a/src/client/ocpp/soap/SoapChargingStationClient.ts b/src/client/ocpp/soap/SoapChargingStationClient.ts index 73610caff9..d6437c9c2a 100644 --- a/src/client/ocpp/soap/SoapChargingStationClient.ts +++ b/src/client/ocpp/soap/SoapChargingStationClient.ts @@ -56,7 +56,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { // Create SOAP client soap.createClient(chargingStationWdsl, options, async (error, client) => { if (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: scsc.tenant.id, action: ServerAction.CHARGING_STATION_CLIENT_INITIALIZATION, siteID: scsc.chargingStation.siteID, @@ -96,7 +96,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { 'remoteStopTransactionRequest': params }); if (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_REMOTE_STOP_TRANSACTION, siteID: this.chargingStation.siteID, @@ -135,7 +135,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { const { error, result, envelope } = await this.client.RemoteStartTransaction(params); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_REMOTE_START_TRANSACTION, siteID: this.chargingStation.siteID, @@ -175,7 +175,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_UNLOCK_CONNECTOR, siteID: this.chargingStation.siteID, @@ -215,7 +215,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_RESET, siteID: this.chargingStation.siteID, @@ -253,7 +253,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { const { error, result, envelope } = await this.client.ClearCache({ clearCacheRequest: {} }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_CLEAR_CACHE, siteID: this.chargingStation.siteID, @@ -300,7 +300,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { const { error, result, envelope } = await this.client.GetConfiguration(request); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_GET_CONFIGURATION, siteID: this.chargingStation.siteID, @@ -344,7 +344,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, diff --git a/src/client/oicp/CpoOICPClient.ts b/src/client/oicp/CpoOICPClient.ts index 3a66039025..3c3c4b75e6 100644 --- a/src/client/oicp/CpoOICPClient.ts +++ b/src/client/oicp/CpoOICPClient.ts @@ -80,7 +80,7 @@ export default class CpoOICPClient extends OICPClient { transaction.oicpData = { session: oicpSession }; - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_SESSIONS, @@ -159,7 +159,7 @@ export default class CpoOICPClient extends OICPClient { // Stop if (transaction.tagID !== OICPDefaultTagId.RemoteIdentification) { const response = await this.authorizeStop(transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_SESSIONS, @@ -529,7 +529,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_DATA, message: `${evses.length} EVSEs have been pushed successfully`, @@ -571,7 +571,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!pushEvseStatusResponse?.Result || pushEvseStatusResponse?.Result !== true) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_STATUSES, message: this.buildOICPChargingNotificationErrorMessage(pushEvseStatusResponse, requestError), @@ -583,7 +583,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_STATUSES, message: `${evseStatuses.length} EVSE Statuses have been pushed successfully`, @@ -628,7 +628,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (requestError) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_AUTHORIZE_START, message: this.buildOICPChargingNotificationErrorMessage(authorizeResponse, requestError), @@ -641,7 +641,7 @@ export default class CpoOICPClient extends OICPClient { }); } if (authorizeResponse?.AuthorizationStatus !== OICPAuthorizationStatus.Authorized) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_AUTHORIZE_START, module: MODULE_NAME, method: 'authorizeStart', @@ -649,7 +649,7 @@ export default class CpoOICPClient extends OICPClient { detailedMessages: { authorize: payload, response: authorizeResponse } }); } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_AUTHORIZE_START, message: `OICP Tag ID '${tagID}' has been authorized`, @@ -694,7 +694,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (requestError) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: user, @@ -709,7 +709,7 @@ export default class CpoOICPClient extends OICPClient { }); } if (authorizeResponse?.AuthorizationStatus !== OICPAuthorizationStatus.Authorized) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: user, @@ -719,7 +719,7 @@ export default class CpoOICPClient extends OICPClient { detailedMessages: { authorize: payload, response: authorizeResponse } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: user, @@ -800,7 +800,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!pushCdrResponse?.Result || pushCdrResponse?.Result !== true) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_CDRS, @@ -813,7 +813,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_CDRS, @@ -871,7 +871,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!notificationStartResponse?.Result || notificationStartResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_START, @@ -884,7 +884,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_START, @@ -946,7 +946,7 @@ export default class CpoOICPClient extends OICPClient { } transaction.oicpData.session.last_progress_notification = new Date(); if (!notificationProgressResponse?.Result || notificationProgressResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_PROGRESS, @@ -959,7 +959,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_PROGRESS, @@ -1034,7 +1034,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!notificationEndResponse?.Result || notificationEndResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_END, @@ -1047,7 +1047,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_END, @@ -1102,7 +1102,7 @@ export default class CpoOICPClient extends OICPClient { requestError = err; } if (!notificationErrorResponse?.Result || notificationErrorResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_ERROR, @@ -1142,7 +1142,7 @@ export default class CpoOICPClient extends OICPClient { } private async pingEvseEndpoint(): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_DATA, message: `Ping Hubject at ${this.getEndpointUrl('evses',ServerAction.OICP_PUSH_EVSE_DATA)}`, diff --git a/src/client/oicp/OICPClientFactory.ts b/src/client/oicp/OICPClientFactory.ts index 7854998070..25a41c2432 100644 --- a/src/client/oicp/OICPClientFactory.ts +++ b/src/client/oicp/OICPClientFactory.ts @@ -20,7 +20,7 @@ export default class OICPClientFactory { if (Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) { const oicpSettings = await SettingStorage.getOICPSettings(tenant); if (!oicpSettings && oicpSettings.oicp) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_SETTINGS, module: MODULE_NAME, method: 'getOicpClient', @@ -41,7 +41,7 @@ export default class OICPClientFactory { const client = await OICPClientFactory.getOicpClient(tenant, oicpEndpoint); return client as CpoOICPClient; } - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_SETTINGS, module: MODULE_NAME, method: 'getCpoOicpClient', diff --git a/src/integration/asset/AssetFactory.ts b/src/integration/asset/AssetFactory.ts index e6c5dbf02b..0b55e7871f 100644 --- a/src/integration/asset/AssetFactory.ts +++ b/src/integration/asset/AssetFactory.ts @@ -45,7 +45,7 @@ export default class AssetFactory { return assetIntegrationImpl; } } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.ASSET, module: MODULE_NAME, method: 'getAssetImpl', diff --git a/src/integration/asset/greencom/GreencomAssetIntegration.ts b/src/integration/asset/greencom/GreencomAssetIntegration.ts index f1cb4c0aa6..1b3966081d 100644 --- a/src/integration/asset/greencom/GreencomAssetIntegration.ts +++ b/src/integration/asset/greencom/GreencomAssetIntegration.ts @@ -46,7 +46,7 @@ export default class GreencomAssetIntegration extends AssetIntegration GreenCom web service has been called successfully`, diff --git a/src/integration/asset/iothink/IothinkAssetIntegration.ts b/src/integration/asset/iothink/IothinkAssetIntegration.ts index 82ae80a4c8..0ea28ea43f 100644 --- a/src/integration/asset/iothink/IothinkAssetIntegration.ts +++ b/src/integration/asset/iothink/IothinkAssetIntegration.ts @@ -48,7 +48,7 @@ export default class IothinkAssetIntegration extends AssetIntegration Iothink web service has been called successfully`, diff --git a/src/integration/asset/lacroix/LacroixAssetIntegration.ts b/src/integration/asset/lacroix/LacroixAssetIntegration.ts index eebcfdd767..4c78cf4021 100644 --- a/src/integration/asset/lacroix/LacroixAssetIntegration.ts +++ b/src/integration/asset/lacroix/LacroixAssetIntegration.ts @@ -64,7 +64,7 @@ export default class LacroixAssetIntegration extends AssetIntegration Lacroix web service has been called successfully`, diff --git a/src/integration/asset/schneider/SchneiderAssetIntegration.ts b/src/integration/asset/schneider/SchneiderAssetIntegration.ts index 1530b5f03b..9cf7328075 100644 --- a/src/integration/asset/schneider/SchneiderAssetIntegration.ts +++ b/src/integration/asset/schneider/SchneiderAssetIntegration.ts @@ -43,7 +43,7 @@ export default class SchneiderAssetIntegration extends AssetIntegration Schneider web service has been called successfully`, diff --git a/src/integration/asset/wit/WitAssetIntegration.ts b/src/integration/asset/wit/WitAssetIntegration.ts index dab98f9fbb..105a5aa7ca 100644 --- a/src/integration/asset/wit/WitAssetIntegration.ts +++ b/src/integration/asset/wit/WitAssetIntegration.ts @@ -48,7 +48,7 @@ export default class WitAssetIntegration extends AssetIntegration headers: this.buildAuthHeader(token) } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.RETRIEVE_ASSET_CONSUMPTION, message: `${asset.name} > WIT web service has been called successfully`, diff --git a/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts b/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts index 370f167a55..a4a228ee03 100644 --- a/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts +++ b/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts @@ -76,7 +76,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra public async createConnection(userID: string, data: any): Promise { try { - await Logging.logDebug({ + Logging.beDebug()?.log({ user: userID, tenantID: this.tenant.id, module: MODULE_NAME, method: 'createConnection', @@ -95,7 +95,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra 'Authorization': `Basic ${Buffer.from(this.connection.mercedesConnection.clientId + ':' + await Cypher.decrypt(this.tenant, this.connection.mercedesConnection.clientSecret)).toString('base64')}` }, }); - await Logging.logDebug({ + Logging.beDebug()?.log({ user: userID, tenantID: this.tenant.id, module: MODULE_NAME, method: 'createConnection', @@ -144,7 +144,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra headers: { 'Authorization': 'Bearer ' + connection.data.access_token } } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.CAR_CONNECTOR, message: `${car.vin} > Mercedes web service has been called successfully`, @@ -201,7 +201,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra 'Authorization': `Basic ${Buffer.from(this.connection.mercedesConnection.clientId + ':' + await Cypher.decrypt(this.tenant, this.connection.mercedesConnection.clientSecret)).toString('base64')}` } }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, user: userID, action: ServerAction.CAR_CONNECTOR, diff --git a/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts b/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts index aa1e59a1b1..a8aeee9cf1 100644 --- a/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts +++ b/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts @@ -46,7 +46,7 @@ export default class TargaTelematicsCarConnectorIntegration extends CarConnector headers: { 'Authorization': 'Bearer ' + connectionToken } } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.CAR_CONNECTOR, message: `${car.vin} > Targa Telematics web service has been called successfully`, diff --git a/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts b/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts index 177a07821a..6f71336e13 100644 --- a/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts +++ b/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts @@ -38,7 +38,7 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat public async getCurrentSoC(car: Car): Promise { if (Utils.isNullOrUndefined(car.carConnectorData.carConnectorMeterID)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, module: MODULE_NAME, method: 'getCurrentSoC', @@ -57,7 +57,7 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat headers: { 'Authorization': 'Bearer ' + connectionToken } } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.CAR_CONNECTOR, message: `${car.vin} > Tronity web service has been called successfully`, diff --git a/src/integration/car/CarIntegration.ts b/src/integration/car/CarIntegration.ts index f046b8fa0e..d6b4295c75 100644 --- a/src/integration/car/CarIntegration.ts +++ b/src/integration/car/CarIntegration.ts @@ -41,7 +41,7 @@ export default abstract class CarIntegration { externalCar.id = await CarStorage.saveCarCatalog(externalCar); actionsDone.inSuccess++; // Log - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'synchronizeCarCatalogs', @@ -75,7 +75,7 @@ export default abstract class CarIntegration { await CarStorage.saveCarCatalog(externalCar); actionsDone.inSuccess++; // Log - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'synchronizeCarCatalogs', @@ -84,7 +84,7 @@ export default abstract class CarIntegration { } } catch (error) { actionsDone.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'synchronizeCarCatalogs', diff --git a/src/integration/car/ev-database/EVDatabaseCarIntegration.ts b/src/integration/car/ev-database/EVDatabaseCarIntegration.ts index 6eb573d6ea..7c7917fc98 100644 --- a/src/integration/car/ev-database/EVDatabaseCarIntegration.ts +++ b/src/integration/car/ev-database/EVDatabaseCarIntegration.ts @@ -22,7 +22,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration { public async getCarCatalogs(): Promise { const evDatabaseConfig = Configuration.getEVDatabaseConfig(); if (!evDatabaseConfig) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, message: 'No configuration is provided to access the EVDatabase system, skipping', module: MODULE_NAME, method: 'getCarCatalogs', @@ -95,7 +95,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration { const base64Image = Buffer.from(response.data).toString('base64'); image = 'data:' + response.headers['content-type'] + ';base64,' + base64Image; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'getCarCatalogThumb', @@ -114,7 +114,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration { const encodedImage = await response.getBase64Async(imageMIME); return encodedImage; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'getCarCatalogImage', diff --git a/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts b/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts index 6fb3eae206..ba6c46f984 100644 --- a/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts +++ b/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts @@ -37,7 +37,7 @@ export default abstract class ChargingStationVendorIntegration { const numberOfPhases = Utils.getNumberOfConnectedPhases(chargingStation, chargePoint); const numberOfConnectors = chargePoint ? chargePoint.connectorIDs.length : chargingStation.connectors.length; if (chargePoint.excludeFromPowerLimitation) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_LIMIT_POWER, @@ -48,7 +48,7 @@ export default abstract class ChargingStationVendorIntegration { return { status: OCPPConfigurationStatus.NOT_SUPPORTED }; } if (!chargePoint.ocppParamForPowerLimitation) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_LIMIT_POWER, @@ -88,7 +88,7 @@ export default abstract class ChargingStationVendorIntegration { const ocppLimitAmpValue = this.convertLimitAmpPerPhase(chargingStation, chargePoint, 0, maxAmps * ocppParamValueMultiplier); let result: OCPPChangeConfigurationResponse; try { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_LIMIT_POWER, @@ -133,7 +133,7 @@ export default abstract class ChargingStationVendorIntegration { const connector = Utils.getConnectorFromID(chargingStation, connectorID); if (connector) { connector.amperageLimit = this.convertLimitAmpToAllPhases(chargingStation, chargePoint, connectorID, Utils.convertToInt(ocppParamValue) / ocppParamValueDivider); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_PARAM_UPDATE, @@ -187,7 +187,7 @@ export default abstract class ChargingStationVendorIntegration { }); // Call each connector? if (result.status !== OCPPChargingProfileStatus.ACCEPTED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_UPDATE, @@ -214,7 +214,7 @@ export default abstract class ChargingStationVendorIntegration { }); return result; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_UPDATE, @@ -261,7 +261,7 @@ export default abstract class ChargingStationVendorIntegration { }); // Call each connector? if (result.status !== OCPPClearChargingProfileStatus.ACCEPTED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -288,7 +288,7 @@ export default abstract class ChargingStationVendorIntegration { }); return result; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -340,7 +340,7 @@ export default abstract class ChargingStationVendorIntegration { result.chargingSchedule = this.convertFromVendorChargingSchedule(chargingStation, chargePoint, result.connectorId, result.chargingSchedule); return result; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_GET_COMPOSITE_SCHEDULE, @@ -433,7 +433,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, connectorLimitAmps), limitSource: ConnectorCurrentLimitSource.STATIC_LIMITATION, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -445,7 +445,7 @@ export default abstract class ChargingStationVendorIntegration { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -460,7 +460,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: limitDefaultMaxPower, limitSource: ConnectorCurrentLimitSource.CONNECTOR }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -609,7 +609,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, Utils.convertToInt(schedulePeriod.limit)), limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -627,7 +627,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, Utils.convertToInt(lastButOneSchedule.limit)), limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -646,7 +646,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, Utils.convertToInt(lastButOneSchedule.limit)), limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, diff --git a/src/integration/pricing/PricingEngine.ts b/src/integration/pricing/PricingEngine.ts index 61913d75dc..a71b329e50 100644 --- a/src/integration/pricing/PricingEngine.ts +++ b/src/integration/pricing/PricingEngine.ts @@ -25,7 +25,7 @@ export default class PricingEngine { // pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, pricingContext, PricingEntity.COMPANY, transaction.companyID)); pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, pricingContext, PricingEntity.TENANT, tenant.id)); if (!pricingContext.timezone) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, @@ -43,7 +43,7 @@ export default class PricingEngine { }, pricingDefinitions }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, @@ -75,7 +75,7 @@ export default class PricingEngine { private static async getPricingDefinitions4Entity(tenant: Tenant, pricingContext: PricingContext, entityType: PricingEntity, entityID: string): Promise { if (!entityID) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, @@ -94,7 +94,7 @@ export default class PricingEngine { ).map((pricingDefinition) => PricingEngine.shrinkPricingDefinition(pricingDefinition) ); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, diff --git a/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts b/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts index a986caf383..3ba45ba0a8 100644 --- a/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts +++ b/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts @@ -23,7 +23,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, module: MODULE_NAME, @@ -41,7 +41,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, module: MODULE_NAME, @@ -55,7 +55,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, module: MODULE_NAME, @@ -69,7 +69,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { if (!PricingHelper.checkContextConsistency(pricingContext)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: this.tenant.id, module: MODULE_NAME, diff --git a/src/integration/refund/RefundFactory.ts b/src/integration/refund/RefundFactory.ts index 4877679987..37997af5a0 100644 --- a/src/integration/refund/RefundFactory.ts +++ b/src/integration/refund/RefundFactory.ts @@ -25,7 +25,7 @@ export default class RefundFactory { } return refundIntegrationImpl; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.REFUND, module: MODULE_NAME, diff --git a/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts b/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts index 14d357fcda..42459ddfab 100644 --- a/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts +++ b/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts @@ -106,7 +106,7 @@ export default class SapConcurRefundIntegration extends RefundIntegration { try { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, module: MODULE_NAME, method: 'createConnection', action: ServerAction.REFUND, message: `Request Concur access token for User ID '${userID}'` @@ -125,7 +125,7 @@ export default class SapConcurRefundIntegration extends RefundIntegration chargingStation.siteAreaID === siteArea.id); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > No charging station used, so no need to call the Smart Charging service`, @@ -116,7 +116,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio const url = await this.buildOptimizerUrl(sourceSiteArea); // Check at least one car if (request.state.cars.length === 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > No car connected so no need to call the SAP Smart Charging service`, @@ -125,7 +125,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio }); return; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > Call the SAP Smart Charging service...`, @@ -138,7 +138,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio Accept: 'application/json', } }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > SAP Smart Charging service has been called successfully`, @@ -148,7 +148,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio // Build charging profiles from result const chargingProfiles = await this.buildChargingProfilesFromOptimizerResponse( sourceSiteArea, siteAreas.result, response.data); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > Charging Profiles have been built successfully`, @@ -338,7 +338,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio // Transaction in progress? if (!connector.currentTransactionID) { // Should not happen - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, @@ -352,7 +352,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio const currentTransaction = transactions.find((transaction) => transaction.id === connector.currentTransactionID); if (!currentTransaction) { // Should not happen - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, @@ -370,7 +370,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio // Get Asset consumption const assetConsumptionInWatts = await this.getAssetConsumptionInWatts(siteArea); if (siteArea.maximumPower !== siteArea.maximumPower - assetConsumptionInWatts) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${siteArea.name} > limit of ${siteArea.maximumPower} W has been adjusted to ${Math.round(siteArea.maximumPower - assetConsumptionInWatts)} W due Asset Consumption`, @@ -482,7 +482,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio } // Found unsupported chargers if (siteMaxAmps !== rootFuse.fusePhase1 + rootFuse.fusePhase2 + rootFuse.fusePhase3) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${siteArea.name} > limit of ${siteMaxAmps} Amps has been lowered to ${Math.round(rootFuse.fusePhase1 + rootFuse.fusePhase2 + rootFuse.fusePhase3)} Amps due to unsupported charging stations currently being used`, @@ -935,7 +935,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio } } if (removedChargingProfiles > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${siteArea.name} > ${removedChargingProfiles} Charging Profiles have been already applied and will be removed from charging profile schedule`, diff --git a/src/locking/LockingManager.ts b/src/locking/LockingManager.ts index 6101cdb430..fbea696984 100644 --- a/src/locking/LockingManager.ts +++ b/src/locking/LockingManager.ts @@ -16,7 +16,7 @@ export default class LockingManager { public static async acquire(lock: Lock, timeoutSecs = 0, retry = true): Promise { try { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -36,7 +36,7 @@ export default class LockingManager { detailedMessages: { lock, timeoutSecs, retry } }); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -50,7 +50,7 @@ export default class LockingManager { if (retry && await LockingManager.checkAndReleaseExpiredLock(lock)) { return LockingManager.acquire(lock, timeoutSecs, false); } - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -66,7 +66,7 @@ export default class LockingManager { // Delete const result = await LockingStorage.deleteLock(lock.id); if (!result) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'release', action: ServerAction.LOCKING, @@ -75,7 +75,7 @@ export default class LockingManager { }); return false; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'release', action: ServerAction.LOCKING, @@ -156,7 +156,7 @@ export default class LockingManager { try { // Remove the lock await LockingManager.release(lockInDB); - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -166,7 +166,7 @@ export default class LockingManager { Utils.isDevelopmentEnv() && Logging.logConsoleWarning(`The lock '${lock.entity}' ('${lock.key}') of type '${lock.type}' in Tenant ID ${lock.tenantID} has expired and was released successfully`); return true; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, diff --git a/src/migration/MigrationHandler.ts b/src/migration/MigrationHandler.ts index 5bf4955c55..4eb4b2290b 100644 --- a/src/migration/MigrationHandler.ts +++ b/src/migration/MigrationHandler.ts @@ -18,7 +18,7 @@ export default class MigrationHandler { if (await LockingManager.acquire(migrationLock)) { try { const startTime = moment(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -49,14 +49,14 @@ export default class MigrationHandler { } // Log Total Processing Time const totalTimeSecs = moment.duration(moment().diff(startTime)).asSeconds(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', message: `The ${processAsyncTasksOnly ? 'asynchronous' : 'synchronous'} migration has been run in ${totalTimeSecs} secs` }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -80,7 +80,7 @@ export default class MigrationHandler { try { // Log Start Task let logMsg = `${currentMigrationTask.isAsynchronous() ? 'Asynchronous' : 'Synchronous'} Migration Task '${currentMigrationTask.getName()}' Version '${currentMigrationTask.getVersion()}' is running...`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'executeTask', @@ -104,7 +104,7 @@ export default class MigrationHandler { durationSecs: totalTaskTimeSecs }); logMsg = `${currentMigrationTask.isAsynchronous() ? 'Asynchronous' : 'Synchronous'} Migration Task '${currentMigrationTask.getName()}' Version '${currentMigrationTask.getVersion()}' has run with success in ${totalTaskTimeSecs} secs`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'executeTask', @@ -114,7 +114,7 @@ export default class MigrationHandler { Utils.isDevelopmentEnv() && Logging.logConsoleDebug(logMsg); } catch (error) { const logMsg = `${currentMigrationTask.isAsynchronous() ? 'Asynchronous' : 'Synchronous'} Migration Task '${currentMigrationTask.getName()}' Version '${currentMigrationTask.getVersion()}' has failed with error: ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'executeTask', diff --git a/src/migration/TenantMigrationTask.ts b/src/migration/TenantMigrationTask.ts index 578f5628d6..22c5b74e72 100644 --- a/src/migration/TenantMigrationTask.ts +++ b/src/migration/TenantMigrationTask.ts @@ -15,7 +15,7 @@ export default abstract class TenantMigrationTask extends MigrationTask { for (const tenant of tenants.result) { const tenantCorrelationID = Utils.generateShortNonUniqueID(); const startTimeInTenant = moment(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -25,7 +25,7 @@ export default abstract class TenantMigrationTask extends MigrationTask { // Migrate await this.migrateTenant(tenant); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -35,7 +35,7 @@ export default abstract class TenantMigrationTask extends MigrationTask { } // Log Total Processing Time const totalTimeSecsInTenant = moment.duration(moment().diff(startTimeInTenant)).asSeconds(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', diff --git a/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts b/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts index 7ccaf443ec..fe310260c2 100644 --- a/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts +++ b/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts @@ -49,7 +49,7 @@ export default class AddCompanyIDToChargingStationsTask extends TenantMigrationT } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AddCompanyIDToTransactionsTask.ts b/src/migration/tasks/AddCompanyIDToTransactionsTask.ts index 0b3bed5724..f29df87978 100644 --- a/src/migration/tasks/AddCompanyIDToTransactionsTask.ts +++ b/src/migration/tasks/AddCompanyIDToTransactionsTask.ts @@ -49,7 +49,7 @@ export default class AddCompanyIDToTransactionsTask extends TenantMigrationTask } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts b/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts index 8885317dd9..d4bb559f08 100644 --- a/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts +++ b/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts @@ -17,7 +17,7 @@ export default class AddLevelTemplateToChargingStationTemplateTask extends Migra for (const template of templates) { if (template.template) { // skip this one as it has already ran - continue + continue; } // Put _id in id const and get template without id const { @@ -47,7 +47,7 @@ export default class AddLevelTemplateToChargingStationTemplateTask extends Migra }, ); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrate', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AddUserIDToCarsTask.ts b/src/migration/tasks/AddUserIDToCarsTask.ts index 11af90b226..562f07de48 100644 --- a/src/migration/tasks/AddUserIDToCarsTask.ts +++ b/src/migration/tasks/AddUserIDToCarsTask.ts @@ -35,7 +35,7 @@ export default class AddUserIDToCarsTask extends TenantMigrationTask { } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts b/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts index 55b33f3823..7ebafa767b 100644 --- a/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts +++ b/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts @@ -30,7 +30,7 @@ export default class AlignEntitiesWithOrganizationIDsTask extends TenantMigratio updated += await SiteAreaStorage.updateEntitiesWithOrganizationIDs( tenant, foundSite.companyID.toString(), siteArea.siteID.toString(), siteArea._id.toString()); } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, @@ -41,7 +41,7 @@ export default class AlignEntitiesWithOrganizationIDsTask extends TenantMigratio } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/MigrateSimplePricing.ts b/src/migration/tasks/MigrateSimplePricing.ts index 254ad75eac..4b3aca90d3 100644 --- a/src/migration/tasks/MigrateSimplePricing.ts +++ b/src/migration/tasks/MigrateSimplePricing.ts @@ -17,7 +17,7 @@ export default class SimplePricingMigrationTask extends TenantMigrationTask { const pricingSetting = await SettingStorage.getSettingByIdentifier(tenant, TenantComponents.PRICING); if (pricingSetting?.content?.type === PricingSettingsType.SIMPLE) { await this.createDefaultPricingDefinition(tenant, pricingSetting.content.simple); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts b/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts index b30e494b9d..df35d90735 100644 --- a/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts +++ b/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts @@ -49,7 +49,7 @@ export default class RemoveDuplicateTagVisualIDsTask extends TenantMigrationTask } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/RepairInvoiceInconsistencies.ts b/src/migration/tasks/RepairInvoiceInconsistencies.ts index 3dbef59364..2534ba41e2 100644 --- a/src/migration/tasks/RepairInvoiceInconsistencies.ts +++ b/src/migration/tasks/RepairInvoiceInconsistencies.ts @@ -18,7 +18,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { const billingImpl = await BillingFactory.getBillingImpl(tenant); if (billingImpl && billingImpl instanceof StripeBillingIntegration) { await this.repairInvoices(tenant, billingImpl); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, @@ -26,7 +26,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, module: MODULE_NAME, method: 'repairInvoices', @@ -68,7 +68,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { try { // Skip invoices that are already PAID or not relevant for the current billing process if (!billingInvoice.sessions) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -76,7 +76,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { message: `Attempt to repair invoice: '${billingInvoice.id}' - '${billingInvoice.number}' ` }); await billingImpl.repairInvoice(billingInvoice); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -85,7 +85,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, diff --git a/src/migration/tasks/RepairTransactionBillingData.ts b/src/migration/tasks/RepairTransactionBillingData.ts index d9855e3589..ad608bf579 100644 --- a/src/migration/tasks/RepairTransactionBillingData.ts +++ b/src/migration/tasks/RepairTransactionBillingData.ts @@ -18,7 +18,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { const billingImpl = await BillingFactory.getBillingImpl(tenant); if (billingImpl && billingImpl instanceof StripeBillingIntegration) { await this.repairTransactionsBillingData(tenant, billingImpl); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, @@ -26,7 +26,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, module: MODULE_NAME, method: 'repairInvoices', @@ -66,7 +66,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { skip += limit; for (const billingInvoice of invoices.result) { try { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -74,7 +74,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { message: `Attempt to repair transaction's billing data for invoice: '${billingInvoice.id}' - '${billingInvoice.number}' ` }); await billingImpl.repairTransactionsBillingData(billingInvoice); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -82,7 +82,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { message: `Transaction's billing data has been repaired for invoice: '${billingInvoice.id}' - '${billingInvoice.number}' ` }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, diff --git a/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts b/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts index 39ead9fc19..428a5b31d7 100644 --- a/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts +++ b/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts @@ -46,7 +46,7 @@ export default class RepairTransactionPricedAtZero extends TenantMigrationTask { await this.loadSimplePricingSettings(tenant); if (transactionsMDB.length > 0 && this.pricingSettings?.simple?.price > 0) { let message = `${transactionsMDB.length} Transaction(s) are going to be repaired in Tenant ${Utils.buildTenantName(tenant)}...`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrateTenant', @@ -57,7 +57,7 @@ export default class RepairTransactionPricedAtZero extends TenantMigrationTask { const numberOfProcessedTransactions = transactionsUpdated.inError + transactionsUpdated.inSuccess; if (numberOfProcessedTransactions > 0 && (numberOfProcessedTransactions % 100) === 0) { message = `> ${transactionsUpdated.inError + transactionsUpdated.inSuccess}/${transactionsMDB.length} - Transaction consumptions recomputed in Tenant ${Utils.buildTenantName(tenant)}`; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrateTenant', @@ -78,7 +78,7 @@ export default class RepairTransactionPricedAtZero extends TenantMigrationTask { transactionsUpdated.inSuccess++; } catch (error) { transactionsUpdated.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrateTenant', diff --git a/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts b/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts index 246bf41044..e1b88a9c48 100644 --- a/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts +++ b/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts @@ -47,7 +47,7 @@ export default class RestoreDataIntegrityInSiteUsersTask extends TenantMigration } // Log in the default tenant if (deleted > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/UpdateEmailsToLowercaseTask.ts b/src/migration/tasks/UpdateEmailsToLowercaseTask.ts index 86889ca148..4cd636e746 100644 --- a/src/migration/tasks/UpdateEmailsToLowercaseTask.ts +++ b/src/migration/tasks/UpdateEmailsToLowercaseTask.ts @@ -22,7 +22,7 @@ export default class UpdateEmailsToLowercaseTask extends TenantMigrationTask { ) as UpdateResult; if (updateResult.modifiedCount > 0) { // Log in the default tenant - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/notification/NotificationHandler.ts b/src/notification/NotificationHandler.ts index f0eb1006ce..a9cb7e43b6 100644 --- a/src/notification/NotificationHandler.ts +++ b/src/notification/NotificationHandler.ts @@ -119,7 +119,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendEndOfCharge(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendEndOfCharge', @@ -164,7 +164,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendOptimalChargeReached(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendOptimalChargeReached', @@ -209,7 +209,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendEndOfSession(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendEndOfSession', @@ -254,7 +254,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendEndOfSignedSession(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendEndOfSignedSession', @@ -417,7 +417,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendVerificationEmail( sourceData, user, tenant, NotificationSeverity.INFO); } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendVerificationEmail', action: ServerAction.VERIFY_EMAIL, @@ -490,7 +490,7 @@ export default class NotificationHandler { sourceData, adminUser, tenant, NotificationSeverity.ERROR); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendChargingStationStatusError', @@ -593,7 +593,7 @@ export default class NotificationHandler { sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendSessionStarted', @@ -643,7 +643,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOCPIPatchChargingStationsStatusesError', action: ServerAction.PATCH_EVSE_STATUS_ERROR, @@ -687,7 +687,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOICPPatchChargingStationsStatusesError', action: ServerAction.PATCH_EVSE_STATUS_ERROR, @@ -731,7 +731,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOICPPatchChargingStationsError', action: ServerAction.PATCH_EVSE_ERROR, @@ -766,7 +766,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendUserAccountInactivity( sourceData, user, tenant, NotificationSeverity.INFO); } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendUserAccountInactivity', action: ServerAction.USER_ACCOUNT_INACTIVITY, @@ -810,7 +810,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendPreparingSessionNotStarted(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendPreparingSessionNotStarted', @@ -855,7 +855,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOfflineChargingStations', action: ServerAction.OFFLINE_CHARGING_STATIONS, @@ -898,7 +898,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingSynchronizationFailed', action: ServerAction.BILLING_USER_SYNCHRONIZATION_FAILED, @@ -941,7 +941,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingInvoicesSynchronizationFailed', action: ServerAction.BILLING_INVOICE_SYNCHRONIZATION_FAILED, @@ -984,7 +984,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingPeriodicOperationFailed', action: ServerAction.BILLING_PERFORM_OPERATIONS, @@ -1027,7 +1027,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_OBJECT.id, module: MODULE_NAME, method: 'sendCarsSynchronizationFailed', action: ServerAction.CAR_CATALOG_SYNCHRONIZATION_FAILED, @@ -1071,7 +1071,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendComputeAndApplyChargingProfilesFailed', @@ -1146,7 +1146,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendSessionNotStarted(sourceData, sourceData.user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendSessionNotStarted', @@ -1185,7 +1185,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingNewInvoiceNotification', action: ServerAction.BILLING_NEW_INVOICE, @@ -1260,7 +1260,7 @@ export default class NotificationHandler { // Success if (extraParams.user) { // User - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, siteID: extraParams.chargingStation?.siteID, siteAreaID: extraParams.chargingStation?.siteAreaID, @@ -1273,7 +1273,7 @@ export default class NotificationHandler { }); } else { // Admin - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, siteID: extraParams.chargingStation?.siteID, siteAreaID: extraParams.chargingStation?.siteAreaID, diff --git a/src/notification/email/EMailNotificationTask.ts b/src/notification/email/EMailNotificationTask.ts index d32bf0eb06..8fba4c1125 100644 --- a/src/notification/email/EMailNotificationTask.ts +++ b/src/notification/email/EMailNotificationTask.ts @@ -243,7 +243,7 @@ export default class EMailNotificationTask implements NotificationTask { // Email configuration sanity checks if (!this.smtpMainClientInstance) { // No suitable main SMTP server configuration found to send the email - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -258,7 +258,7 @@ export default class EMailNotificationTask implements NotificationTask { } if (useSmtpClientBackup && !this.smtpBackupClientInstance) { // No suitable backup SMTP server configuration found or activated to send the email - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -285,7 +285,7 @@ export default class EMailNotificationTask implements NotificationTask { }); if (Utils.isDevelopmentEnv()) { // Do not send mail in Dev mode - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id ? tenant.id : Constants.DEFAULT_TENANT_ID, action: ServerAction.EMAIL_NOTIFICATION, module: MODULE_NAME, method: 'sendEmail', @@ -306,7 +306,7 @@ export default class EMailNotificationTask implements NotificationTask { // Send the message const messageSent: Message = await smtpClient.sendAsync(messageToSend); // Email sent successfully - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id ? tenant.id : Constants.DEFAULT_TENANT_ID, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -323,7 +323,7 @@ export default class EMailNotificationTask implements NotificationTask { } }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id ? tenant.id : Constants.DEFAULT_TENANT_ID, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -425,7 +425,7 @@ export default class EMailNotificationTask implements NotificationTask { html: emailContent.html, }; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, ...LoggingHelper.getSourceDataProperties(sourceData), action: ServerAction.EMAIL_NOTIFICATION, diff --git a/src/notification/remote-push-notification/RemotePushNotificationTask.ts b/src/notification/remote-push-notification/RemotePushNotificationTask.ts index 91c7968a59..d6d84c456b 100644 --- a/src/notification/remote-push-notification/RemotePushNotificationTask.ts +++ b/src/notification/remote-push-notification/RemotePushNotificationTask.ts @@ -469,7 +469,7 @@ export default class RemotePushNotificationTask implements NotificationTask { return Promise.resolve(); } if (!user?.mobileData?.mobileToken) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, diff --git a/src/scheduler/SchedulerManager.ts b/src/scheduler/SchedulerManager.ts index bb8f7e3d0c..ae78cf3248 100644 --- a/src/scheduler/SchedulerManager.ts +++ b/src/scheduler/SchedulerManager.ts @@ -43,7 +43,7 @@ export default class SchedulerManager { // Keep the conf SchedulerManager.schedulerConfig = schedulerConfig; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'init', @@ -53,7 +53,7 @@ export default class SchedulerManager { for (const task of SchedulerManager.schedulerConfig.tasks) { // Active? if (!task.active) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'init', @@ -65,7 +65,7 @@ export default class SchedulerManager { if (schedulerTask) { // Register task to cron engine cron.schedule(task.periodicity, () => SchedulerManager.runTask(schedulerTask, task)); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'init', @@ -146,7 +146,7 @@ export default class SchedulerManager { case 'DispatchCollectedFundsTask': return new DispatchCollectedFundsTask(); default: - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'createTask', diff --git a/src/scheduler/SchedulerTask.ts b/src/scheduler/SchedulerTask.ts index 8410143fd6..6ff7e3db8b 100644 --- a/src/scheduler/SchedulerTask.ts +++ b/src/scheduler/SchedulerTask.ts @@ -21,7 +21,7 @@ export default abstract class SchedulerTask { if (scheduledTaskLock) { try { const startTime = moment(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'run', @@ -35,7 +35,7 @@ export default abstract class SchedulerTask { // Hook await this.afterTaskRun(config); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'run', @@ -45,7 +45,7 @@ export default abstract class SchedulerTask { } // Log Total Processing Time const totalTimeSecs = moment.duration(moment().diff(startTime)).asSeconds(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'run', diff --git a/src/scheduler/TenantSchedulerTask.ts b/src/scheduler/TenantSchedulerTask.ts index ffee0dbd70..1a1f2014a8 100644 --- a/src/scheduler/TenantSchedulerTask.ts +++ b/src/scheduler/TenantSchedulerTask.ts @@ -23,7 +23,7 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { (taskSettings.task.disableAllTasks || !Utils.isEmptyArray(taskSettings.task.disableTasksInEnv) && taskSettings.task.disableTasksInEnv.includes(currentTaskEnv))) { // Tasks are disabled for this environment isTaskExecutionDisabled = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -43,7 +43,7 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { } // Check if tenant task needs to run on a specific environment if (tenant.taskExecutionEnv && tenant.taskExecutionEnv !== currentTaskEnv) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -54,13 +54,13 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { } const tenantCorrelationID = Utils.generateShortNonUniqueID(); const startTimeInTenant = moment(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', message: `The Task '${this.getName()}~${this.getCorrelationID()}~${tenantCorrelationID}' is running for Tenant ${Utils.buildTenantName(tenant)}...` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -74,14 +74,14 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { // Hook await this.afterProcessTenant(tenant, config); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', message: `Error while running the Task '${this.getName()}~${this.getCorrelationID()}~${tenantCorrelationID}' for Tenant ${Utils.buildTenantName(tenant)}: ${error.message as string}`, detailedMessages: { error: error.stack } }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -91,13 +91,13 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { } // Log Total Processing Time in Tenant const totalTimeSecsInTenant = moment.duration(moment().diff(startTimeInTenant)).asSeconds(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', message: `The Task '${this.getName()}~${this.getCorrelationID()}~${tenantCorrelationID}' has been run successfully in ${totalTimeSecsInTenant} secs for Tenant ${Utils.buildTenantName(tenant)}` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', diff --git a/src/scheduler/tasks/BillPendingTransactionTask.ts b/src/scheduler/tasks/BillPendingTransactionTask.ts index dad30128c8..e98b0cec69 100644 --- a/src/scheduler/tasks/BillPendingTransactionTask.ts +++ b/src/scheduler/tasks/BillPendingTransactionTask.ts @@ -43,7 +43,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } ]).toArray(); if (!Utils.isEmptyArray(transactionsMDB)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -56,7 +56,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { // Get Transaction const transaction = await TransactionStorage.getTransaction(tenant, transactionMDB._id, { withUser: true, withChargingStation: true }); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -67,7 +67,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { // Get Charging Station const chargingStation = transaction.chargeBox; if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -87,7 +87,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } // Check for the billing status if (transaction.billingData?.stop?.status !== BillingStatus.PENDING) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -97,7 +97,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } // Avoid billing again! if (transaction.billingData?.stop?.invoiceID) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -112,7 +112,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { await BillingFacade.processEndTransaction(tenant, transaction, transaction.user); // Save await TransactionStorage.saveTransaction(tenant, transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, actionOnUser: transaction.user, @@ -120,7 +120,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { message: `The billing process has been started for transaction '${transaction.id}'`, }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', diff --git a/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts b/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts index 8b7d4e92b9..37bfccf9d1 100644 --- a/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts +++ b/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts @@ -29,7 +29,7 @@ export default class CheckAndComputeSmartChargingTask extends TenantSchedulerTas const smartCharging = await SmartChargingFactory.getSmartChargingImpl(tenant); if (!smartCharging) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processTenant', action: ServerAction.CHECK_AND_APPLY_SMART_CHARGING, @@ -40,7 +40,7 @@ export default class CheckAndComputeSmartChargingTask extends TenantSchedulerTas await smartCharging.computeAndApplyChargingProfiles(siteArea); } catch (error) { // Log error - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processTenant', action: ServerAction.CHECK_AND_APPLY_SMART_CHARGING, @@ -53,7 +53,7 @@ export default class CheckAndComputeSmartChargingTask extends TenantSchedulerTas } } } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'processTenant', action: ServerAction.CHECK_AND_APPLY_SMART_CHARGING, diff --git a/src/scheduler/tasks/CheckChargingStationTemplateTask.ts b/src/scheduler/tasks/CheckChargingStationTemplateTask.ts index 61d4650bc7..ae7c68c04d 100644 --- a/src/scheduler/tasks/CheckChargingStationTemplateTask.ts +++ b/src/scheduler/tasks/CheckChargingStationTemplateTask.ts @@ -34,7 +34,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas let updated = 0; // Bypass perf tenant if (tenant.subdomain === 'testperf') { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'applyTemplateToChargingStations', @@ -57,7 +57,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas updated++; } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -68,7 +68,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas } } if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'applyTemplateToChargingStations', diff --git a/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts b/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts index 4c93124e1d..8067f870a4 100644 --- a/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts +++ b/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts @@ -45,7 +45,7 @@ export default class CheckOfflineChargingStationsTask extends TenantSchedulerTas } // Charging Station is still connected: ignore it if (ocppHeartbeatConfiguration) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OFFLINE_CHARGING_STATION, diff --git a/src/scheduler/tasks/CloseTransactionsInProgressTask.ts b/src/scheduler/tasks/CloseTransactionsInProgressTask.ts index a5d8983545..e80c721435 100644 --- a/src/scheduler/tasks/CloseTransactionsInProgressTask.ts +++ b/src/scheduler/tasks/CloseTransactionsInProgressTask.ts @@ -34,7 +34,7 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask // Soft stop transaction await ocppService.softStopTransaction(tenant, transaction, transaction.chargeBox, transaction.siteArea); result.inSuccess++; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, @@ -45,7 +45,7 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask }); } catch (error) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.TRANSACTION_SOFT_STOP, diff --git a/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts b/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts index b4e5bd2022..c88e9b0803 100644 --- a/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts +++ b/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts @@ -47,14 +47,14 @@ export default class LoggingDatabaseTableCleanupTask extends TenantSchedulerTask // Delete const result = await LogStorage.deleteLogs(tenant, deleteUpToDate); if (result.acknowledged) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.LOGS_CLEANUP, module: MODULE_NAME, method: 'deleteLogs', message: `${result.deletedCount} Log(s) have been deleted before '${moment(deleteUpToDate).format('DD/MM/YYYY h:mm A')}'` }); } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.LOGS_CLEANUP, module: MODULE_NAME, method: 'deleteLogs', @@ -90,14 +90,14 @@ export default class LoggingDatabaseTableCleanupTask extends TenantSchedulerTask // Delete Logs const result = await PerformanceStorage.deletePerformanceRecords({ deleteUpToDate }); if (result.acknowledged) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.PERFORMANCES_CLEANUP, module: MODULE_NAME, method: 'deletePerformanceRecords', message: `${result.deletedCount} Performance Record(s) have been deleted before '${moment(deleteUpToDate).format('DD/MM/YYYY h:mm A')}'` }); } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.PERFORMANCES_CLEANUP, module: MODULE_NAME, method: 'deletePerformanceRecords', diff --git a/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts b/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts index 98e49ed8ab..bc5d113526 100644 --- a/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts +++ b/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts @@ -17,7 +17,7 @@ const MODULE_NAME = 'SynchronizeRefundTransactionsTask'; export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTask { public async processTenant(tenant: Tenant, config: TaskConfig): Promise { if (!Utils.isTenantComponentActive(tenant, TenantComponents.REFUND)) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'run', @@ -28,7 +28,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa // Get Concur Settings const refundConnector = await RefundFactory.getRefundImpl(tenant); if (!refundConnector) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'run', @@ -46,7 +46,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa { ...Constants.DB_PARAMS_MAX_LIMIT, sort: { 'userID': 1, 'refundData.reportId': 1 } }); if (!Utils.isEmptyArray(transactions.result)) { // Process them - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'processTenant', @@ -78,7 +78,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa } } // Log result - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'processTenant', @@ -86,7 +86,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa }); } else { // Process them - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'processTenant', diff --git a/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts index 76027bc2eb..c97a997b86 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts @@ -40,7 +40,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -49,7 +49,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -57,7 +57,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -67,7 +67,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Check CDRs const result = await ocpiClient.checkCdrs(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, diff --git a/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts index f9f97eb453..36c4703434 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts @@ -40,7 +40,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -49,7 +49,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -57,7 +57,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -67,7 +67,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Check Locations const result = await ocpiClient.checkLocations(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, diff --git a/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts index 1cc32f4389..f5a76dd3a4 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts @@ -40,7 +40,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -49,7 +49,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -57,7 +57,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -67,7 +67,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Check Sessions const result = await ocpiClient.checkSessions(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, diff --git a/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts index 26aafb2278..e0d03d77e7 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts @@ -41,7 +41,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -50,7 +50,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -58,7 +58,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpointatch', @@ -68,7 +68,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Pull CDRs const result = await ocpiClient.pullCdrs(true); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpoint', diff --git a/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts index fad3084a51..92a29b972f 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts @@ -40,7 +40,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -49,7 +49,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -57,7 +57,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -67,7 +67,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Pull Locations const result = await ocpiClient.pullLocations(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', diff --git a/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts index d0e1ddfaa9..85e93a6de6 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts @@ -40,7 +40,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, @@ -49,7 +49,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, @@ -57,7 +57,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, @@ -67,7 +67,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Pull Sessions const result = await ocpiClient.pullSessions(true); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, diff --git a/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts b/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts index a453172eee..6716a17dde 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts @@ -40,7 +40,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, @@ -49,7 +49,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, @@ -57,7 +57,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, @@ -67,7 +67,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Pull Tokens const result = await ocpiClient.pullTokens(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, diff --git a/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts index 7c2906f901..185fb89962 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts @@ -41,7 +41,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { } ]).toArray(); if (!Utils.isEmptyArray(transactionsMDB)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -55,7 +55,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { // Get Transaction const transaction = await TransactionStorage.getTransaction(tenant, transactionMDB._id, { withUser: true }); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -64,7 +64,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { continue; } if (transaction.ocpiData?.cdr) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -75,7 +75,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { // Get Charging Station const chargingStation = await ChargingStationStorage.getChargingStation(tenant, transaction.chargeBoxID, { withSiteArea: true }); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -86,7 +86,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { // Get Tag const tag = await TagStorage.getTag(tenant, transaction.tagID); if (!tag) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -98,7 +98,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { await OCPIFacade.processEndTransaction(tenant, transaction, chargingStation, chargingStation.siteArea, transaction.user, ServerAction.OCPI_CPO_PUSH_CDRS); // Save await TransactionStorage.saveTransactionOcpiData(tenant, transaction.id, transaction.ocpiData); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, actionOnUser: (transaction.user ? transaction.user : null), @@ -107,7 +107,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { detailedMessages: { cdr: transaction.ocpiData.cdr } }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', diff --git a/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts b/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts index 6e8fb59dc3..b6dac32dbc 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts @@ -40,7 +40,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, @@ -49,7 +49,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, @@ -57,7 +57,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, @@ -67,7 +67,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Push EVSE statuses const sendResult = await ocpiClient.pushChargingStationStatuses(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, diff --git a/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts b/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts index 54a864ebaa..6829291f10 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts @@ -40,7 +40,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -49,7 +49,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -57,7 +57,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -67,7 +67,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Push Tokens const result = await ocpiClient.pushTokens(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', diff --git a/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts b/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts index 0ebec59080..8e21967d32 100644 --- a/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts +++ b/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts @@ -40,7 +40,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { try { // Check if OICP endpoint is registered if (oicpEndpoint.status !== OICPRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, @@ -49,7 +49,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { return; } if (!oicpEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, @@ -57,7 +57,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, @@ -67,7 +67,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { const oicpClient = await OICPClientFactory.getCpoOicpClient(tenant, oicpEndpoint); // Send EVSEs const sendEVSEDataResult = await oicpClient.sendEVSEs(!Utils.isUndefined(config.partial) ? config.partial : false); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, diff --git a/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts b/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts index b118cad2a4..c840c3283c 100644 --- a/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts +++ b/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts @@ -40,7 +40,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { try { // Check if OICP endpoint is registered if (oicpEndpoint.status !== OICPRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, @@ -49,7 +49,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { return; } if (!oicpEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, @@ -57,7 +57,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, @@ -67,7 +67,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { const oicpClient = await OICPClientFactory.getCpoOicpClient(tenant, oicpEndpoint); // Send EVSE statuses const sendEVSEStatusResult = await oicpClient.sendEVSEStatuses(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, diff --git a/src/server/ServerUtils.ts b/src/server/ServerUtils.ts index 62b246a69b..c4191c1d37 100644 --- a/src/server/ServerUtils.ts +++ b/src/server/ServerUtils.ts @@ -12,7 +12,7 @@ export class ServerUtils { protocol: ServerProtocol, hostname: string, port: number): Promise { const logMsg = `${serverType} Server listening on '${protocol}://${hostname}:${port}'`; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: serverModuleName, method: methodName, action: ServerAction.STARTUP, diff --git a/src/server/ocpi/OCPIFacade.ts b/src/server/ocpi/OCPIFacade.ts index 17a958eddd..ce229de5bb 100644 --- a/src/server/ocpi/OCPIFacade.ts +++ b/src/server/ocpi/OCPIFacade.ts @@ -52,7 +52,7 @@ export default class OCPIFacade { // Update OCPI Session await ocpiClient.updateSession(transaction); } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processUpdateTransaction', @@ -120,7 +120,7 @@ export default class OCPIFacade { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'updateConnectorStatus', diff --git a/src/server/ocpi/OCPIUtils.ts b/src/server/ocpi/OCPIUtils.ts index 12387bf34b..296818addf 100644 --- a/src/server/ocpi/OCPIUtils.ts +++ b/src/server/ocpi/OCPIUtils.ts @@ -239,7 +239,7 @@ export default class OCPIUtils { try { await OCPIUtils.updateCreateChargingStationWithEmspLocation(tenant, location, site, siteArea, evse, action); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action, module: MODULE_NAME, method: 'processEMSPLocationChargingStations', message: `Error while processing the EVSE UID '${evse.uid}' (ID '${evse.evse_id}') in Location '${location.name}'`, @@ -265,7 +265,7 @@ export default class OCPIUtils { // Delete Charging Station if (currentChargingStation && evse.status === OCPIEvseStatus.REMOVED) { await ChargingStationStorage.deleteChargingStation(tenant, currentChargingStation.id); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(currentChargingStation), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processEMSPLocationChargingStation', @@ -278,7 +278,7 @@ export default class OCPIUtils { currentChargingStation, evse, location, site, siteArea, action); await ChargingStationStorage.saveChargingStation(tenant, chargingStation); await ChargingStationStorage.saveChargingStationOcpiData(tenant, chargingStation.id, chargingStation.ocpiData); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processEMSPLocationChargingStation', diff --git a/src/server/ocpi/service/OCPIUtilsService.ts b/src/server/ocpi/service/OCPIUtilsService.ts index b25fe7c97d..6119dd29c4 100644 --- a/src/server/ocpi/service/OCPIUtilsService.ts +++ b/src/server/ocpi/service/OCPIUtilsService.ts @@ -321,7 +321,7 @@ export default class OCPIUtilsService { } // Check the CDR if (transaction?.ocpiData?.cdr?.id) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, @@ -333,7 +333,7 @@ export default class OCPIUtilsService { } // Check the Session Status if (transaction?.ocpiData?.session?.status === OCPISessionStatus.COMPLETED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, @@ -445,7 +445,7 @@ export default class OCPIUtilsService { } // Session in the past if (moment(session.last_updated).isBefore(transaction.lastConsumption.timestamp)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, diff --git a/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts b/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts index 7de3403615..43e7c1bc55 100644 --- a/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts +++ b/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts @@ -25,7 +25,7 @@ export default class CPOEMSPCredentialsService { token = req.headers.authorization.split(' ')[1]; } // Log body - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleDeleteCredentials', action, message: 'Received OCPI unregister endpoint', @@ -52,7 +52,7 @@ export default class CPOEMSPCredentialsService { const { tenant, ocpiEndpoint } = req; // Get payload const credential = req.body as OCPICredential; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Received credential object', @@ -73,7 +73,7 @@ export default class CPOEMSPCredentialsService { token = req.headers.authorization.split(' ')[1]; } // Log body - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Received token', @@ -86,7 +86,7 @@ export default class CPOEMSPCredentialsService { ocpiEndpoint.partyId = credential.party_id; ocpiEndpoint.businessDetails = credential.business_details; // Log updated ocpi endpoint - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'OCPI Server found and updated with credential object', @@ -102,7 +102,7 @@ export default class CPOEMSPCredentialsService { }, }); // Log available OCPI Versions - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Available OCPI Versions', @@ -125,7 +125,7 @@ export default class CPOEMSPCredentialsService { ocpiEndpoint.version = version.version; ocpiEndpoint.versionUrl = version.url; // Log correct OCPI service found - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Correct OCPI version found', @@ -149,7 +149,7 @@ export default class CPOEMSPCredentialsService { } }); // Log available OCPI services - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Available OCPI services', @@ -184,7 +184,7 @@ export default class CPOEMSPCredentialsService { // Build credential object const respCredential = await OCPIUtils.buildOcpiCredentialObject(tenant, ocpiEndpoint.localToken, ocpiEndpoint.role, versionUrl); // Log available OCPI Versions - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Response with credential object', diff --git a/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts b/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts index 35e3a31544..ff911b51ea 100644 --- a/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts +++ b/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts @@ -92,7 +92,7 @@ export default class CPOCommandsService { localToken = await OCPIUtilsService.updateCreateTagWithEmspToken(tenant, startSession.token, localToken, emspUser, action); } if (!localToken?.active || !localToken.ocpiToken?.valid) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, message: `Token ID '${startSession.token.uid}' is either not active or invalid`, @@ -101,7 +101,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (Utils.isNullOrUndefined(localToken.user) || localToken.user?.issuer) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, message: `Invalid user associated to Token ID '${startSession.token.uid}'`, @@ -113,7 +113,7 @@ export default class CPOCommandsService { const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationEvseUid( tenant, startSession.location_id, startSession.evse_uid); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, message: `Charging Station with EVSE ID '${startSession.evse_uid}' and Location ID '${startSession.location_id}' does not exist`, @@ -125,7 +125,7 @@ export default class CPOCommandsService { const connectorID = Utils.convertToInt(OCPIUtils.getConnectorIDFromEvseID(startSession.evse_uid)); const connector = Utils.getConnectorFromID(chargingStation, connectorID); if (!connector) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -135,7 +135,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (!chargingStation.issuer || !chargingStation.public) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -146,7 +146,7 @@ export default class CPOCommandsService { } if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.PREPARING) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -162,7 +162,7 @@ export default class CPOCommandsService { (authorization) => authorization.connectorId === connector.connectorId); if (existingAuthorization) { if (OCPIUtils.isAuthorizationValid(existingAuthorization.timestamp)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -203,7 +203,7 @@ export default class CPOCommandsService { } const transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant, stopSession.session_id); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, message: `Transaction with Session ID '${stopSession.session_id}' does not exists`, @@ -212,7 +212,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (!transaction.issuer) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, @@ -222,7 +222,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (transaction.stop) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, @@ -233,7 +233,7 @@ export default class CPOCommandsService { } const chargingStation = await ChargingStationStorage.getChargingStation(tenant, transaction.chargeBoxID); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, @@ -278,7 +278,7 @@ export default class CPOCommandsService { try { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartTransaction', action, @@ -296,7 +296,7 @@ export default class CPOCommandsService { await CPOCommandsService.sendCommandResponse(tenant, action, startSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartTransaction', action, @@ -311,7 +311,7 @@ export default class CPOCommandsService { try { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopTransaction', action, @@ -328,7 +328,7 @@ export default class CPOCommandsService { await CPOCommandsService.sendCommandResponse(tenant, action, stopSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopTransaction', action, @@ -343,7 +343,7 @@ export default class CPOCommandsService { const payload: OCPICommandResponse = { result: responseType }; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendCommandResponse', action, message: `Post command response at ${responseUrl}`, diff --git a/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts b/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts index 6f70ce7f35..4e9002357d 100644 --- a/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts +++ b/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts @@ -39,7 +39,7 @@ export default class EMSPCommandsService { case OCPICommandType.RESERVE_NOW: case OCPICommandType.UNLOCK_CONNECTOR: if (req.body?.result !== OCPICommandResponseType.ACCEPTED) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: EMSPCommandsService.getAction(command), message: `OCPI Callback '${req.body?.result as string}' received for Command '${command}' with ID '${commandId}'`, @@ -47,7 +47,7 @@ export default class EMSPCommandsService { detailedMessages: { response: req.body } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: EMSPCommandsService.getAction(command), message: `OCPI Callback '${req.body?.result as string}' received for Command '${command}' with ID '${commandId}'`, diff --git a/src/server/ocpp/json/JsonOCPPServer.ts b/src/server/ocpp/json/JsonOCPPServer.ts index a91fc6aeaa..c343f20d32 100644 --- a/src/server/ocpp/json/JsonOCPPServer.ts +++ b/src/server/ocpp/json/JsonOCPPServer.ts @@ -136,13 +136,13 @@ export default class JsonOCPPServer extends OCPPServer { const jsonWebSocket = this.jsonWSConnections.get(`${tenant.id}~${chargingStation.id}`); if (!jsonWebSocket) { const message = 'No opened Web Socket connection found'; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'getChargingStationClient', action: ServerAction.WS_SERVER_CONNECTION, message }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: chargingStation.id, module: MODULE_NAME, method: 'getChargingStationClient', @@ -169,7 +169,7 @@ export default class JsonOCPPServer extends OCPPServer { // INFO: Cannot use Logging in this method as uWebSocket will fail in using req/res objects :S // Check URI (/OCPP16/// or /REST///) if (!url.startsWith('/OCPP16') && !url.startsWith('/REST')) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'onUpgrade', action: ServerAction.WS_SERVER_CONNECTION, @@ -181,7 +181,7 @@ export default class JsonOCPPServer extends OCPPServer { // Check Protocol (ocpp1.6 / rest) const protocol = req.getHeader('sec-websocket-protocol'); if (url.startsWith('/OCPP16') && (protocol !== WSServerProtocol.OCPP16)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'onUpgrade', action: ServerAction.WS_SERVER_CONNECTION, @@ -192,7 +192,7 @@ export default class JsonOCPPServer extends OCPPServer { return; } if (url.startsWith('/REST') && (protocol !== WSServerProtocol.REST)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'onUpgrade', action: ServerAction.WS_SERVER_CONNECTION, @@ -214,7 +214,7 @@ export default class JsonOCPPServer extends OCPPServer { res.writeStatus('500'); res.end(message); this.isDebug() && Logging.logConsoleDebug(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.WS_SERVER_CONNECTION, module: MODULE_NAME, method: 'onUpgrade', @@ -269,7 +269,7 @@ export default class JsonOCPPServer extends OCPPServer { if (protocol === WSServerProtocol.REST) { wsConnection = new JsonRestWSConnection(wsWrapper); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.WS_SERVER_CONNECTION_OPEN, module: MODULE_NAME, method: 'checkAndStoreWSOpenedConnection', message: `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' is being checked ('${wsWrapper.url}')`, @@ -290,13 +290,13 @@ export default class JsonOCPPServer extends OCPPServer { // Check already existing WS Connection await this.checkAndCloseIdenticalOpenedWSConnection(wsWrapper, wsConnection); const message = `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' has been accepted in ${Utils.computeTimeDurationSecs(timeStart)} secs`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION_OPEN, module: MODULE_NAME, method: 'checkAndStoreWSOpenedConnection', message, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getWSWrapperProperties(wsWrapper), action: ServerAction.WS_SERVER_CONNECTION_OPEN, module: MODULE_NAME, method: 'checkAndStoreWSOpenedConnection', message, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } @@ -322,7 +322,7 @@ export default class JsonOCPPServer extends OCPPServer { const result = await this.pingWebSocket(existingWSWrapper); if (result.ok) { // Close the old WS and keep the new incoming one - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION, module: MODULE_NAME, method: 'checkAndCloseIdenticalOpenedWSConnection', @@ -385,14 +385,14 @@ export default class JsonOCPPServer extends OCPPServer { } } catch (error) { const logMessage = `${WebSocketAction.MESSAGE} > WS Connection ID '${wsWrapper.guid}' got error while processing WS Message: ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getWSWrapperProperties(wsWrapper), action: ServerAction.WS_SERVER_MESSAGE, module: MODULE_NAME, method: 'onMessage', message: logMessage, detailedMessages: { message, isBinary, wsWrapper: this.getWSWrapperData(wsWrapper), error: error.stack } }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -410,7 +410,7 @@ export default class JsonOCPPServer extends OCPPServer { const wsExistingConnection = this.getWSConnectionFromProtocolAndID(wsWrapper.protocol, wsWrapper.key); if (!wsExistingConnection) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -425,7 +425,7 @@ export default class JsonOCPPServer extends OCPPServer { // Should have the same GUID const wsExistingWrapper = wsExistingConnection.getWS(); if (wsExistingWrapper.guid !== wsWrapper.guid) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -436,7 +436,7 @@ export default class JsonOCPPServer extends OCPPServer { // Ping const result = await this.pingWebSocket(wsExistingWrapper); if (result.ok) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -448,7 +448,7 @@ export default class JsonOCPPServer extends OCPPServer { await this.closeWebSocket(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsExistingWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.MESSAGE} > Existing WS Connection ID '${wsExistingWrapper.guid}' has been closed successfully by server (duplicate WS Connection)`); } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -465,13 +465,13 @@ export default class JsonOCPPServer extends OCPPServer { private async logWSConnectionClosed(wsWrapper: WSWrapper, action: ServerAction, code: number, message: string): Promise { this.isDebug() && Logging.logConsoleDebug(message); if (wsWrapper.tenantID) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getWSWrapperProperties(wsWrapper), action, module: MODULE_NAME, method: 'logWSConnectionClosed', message: message, detailedMessages: { code, message, wsWrapper: this.getWSWrapperData(wsWrapper) } }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'logWSConnectionClosed', @@ -485,7 +485,7 @@ export default class JsonOCPPServer extends OCPPServer { const maxNumberOfTrials = 10; let numberOfTrials = 0; const timeStart = Date.now(); - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'waitForWSLockToRelease', @@ -500,7 +500,7 @@ export default class JsonOCPPServer extends OCPPServer { numberOfTrials++; // Message has been processed if (!this.runningWSRequestsMessages[wsWrapper.url]) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'waitForWSLockToRelease', @@ -514,7 +514,7 @@ export default class JsonOCPPServer extends OCPPServer { // Handle remaining trial if (numberOfTrials >= maxNumberOfTrials) { // Abnormal situation: The lock should not be taken for so long! - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'waitForWSLockToRelease', @@ -543,7 +543,7 @@ export default class JsonOCPPServer extends OCPPServer { wsWrapper.nbrPingFailed++; // Close WS if (wsWrapper.nbrPingFailed >= Constants.WS_MAX_NBR_OF_FAILED_PINGS) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION_PING, module: MODULE_NAME, method: 'pingWebSocket', @@ -553,7 +553,7 @@ export default class JsonOCPPServer extends OCPPServer { await this.closeWebSocket(WebSocketAction.PING, ServerAction.WS_SERVER_CONNECTION_PING, wsWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.PING} > WS Connection ID '${wsWrapper.guid}' has been closed by server after ${wsWrapper.nbrPingFailed} failed ping`); } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION_PING, module: MODULE_NAME, method: 'pingWebSocket', @@ -577,7 +577,7 @@ export default class JsonOCPPServer extends OCPPServer { await this.logWSConnectionClosed(wsWrapper, action, code, message); } catch (error) { // Just log and ignore issue - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'closeWebSocket', @@ -594,7 +594,7 @@ export default class JsonOCPPServer extends OCPPServer { // Reference a Json WebSocket connection object if (wsWrapper.protocol === WSServerProtocol.OCPP16) { this.jsonWSConnections.set(wsConnection.getID(), wsConnection as JsonWSConnection); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'setWSConnection', @@ -604,7 +604,7 @@ export default class JsonOCPPServer extends OCPPServer { } if (wsWrapper.protocol === WSServerProtocol.REST) { this.jsonRestWSConnections.set(wsConnection.getID(), wsConnection as JsonRestWSConnection); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'setWSConnection', @@ -645,7 +645,7 @@ export default class JsonOCPPServer extends OCPPServer { if (existingWsWrapper.guid === wsWrapper.guid) { // Remove from WS Cache wsConnections.delete(wsConnection.getID()); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'setWSConnection', @@ -654,7 +654,7 @@ export default class JsonOCPPServer extends OCPPServer { }); } else { // WS Connection not identical - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'removeWSConnection', @@ -664,7 +664,7 @@ export default class JsonOCPPServer extends OCPPServer { } } else { // WS Connection not found - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'removeWSConnection', @@ -691,7 +691,7 @@ export default class JsonOCPPServer extends OCPPServer { numberOfCurrentRequests += Object.keys(currentOcppRequests).length; } // Log Stats on number of WS Connections - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.WS_SERVER_CONNECTION, module: MODULE_NAME, method: 'monitorWSConnections', message: `${this.jsonWSConnections.size} WS connections, ${this.jsonRestWSConnections.size} REST connections, ${this.runningWSMessages} Messages, ${Object.keys(this.runningWSRequestsMessages).length} Requests, ${this.waitingWSMessages} queued WS Message(s)`, @@ -755,14 +755,14 @@ export default class JsonOCPPServer extends OCPPServer { const message = `Total of ${wsConnectionKeys.length} ${type} WS connection(s) pinged in ${Utils.computeTimeDurationSecs(timeStart)} secs: ${validConnections.length} valid, ${invalidConnections.length} invalid`; this.isDebug() && Logging.logConsoleDebug(message); if (invalidConnections.length) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'checkAndCleanupWebSockets', action: ServerAction.WS_SERVER_CONNECTION_PING, message, detailedMessages: { invalidConnections, /* validConnections */ } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'checkAndCleanupWebSockets', action: ServerAction.WS_SERVER_CONNECTION_PING, diff --git a/src/server/ocpp/json/web-socket/WSConnection.ts b/src/server/ocpp/json/web-socket/WSConnection.ts index 90102d624d..1771993344 100644 --- a/src/server/ocpp/json/web-socket/WSConnection.ts +++ b/src/server/ocpp/json/web-socket/WSConnection.ts @@ -234,7 +234,7 @@ export default abstract class WSConnection { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.siteID, siteAreaID: this.siteAreaID, diff --git a/src/server/ocpp/services/OCPPService.ts b/src/server/ocpp/services/OCPPService.ts index 84439ff8c9..9f0ce8a694 100644 --- a/src/server/ocpp/services/OCPPService.ts +++ b/src/server/ocpp/services/OCPPService.ts @@ -86,7 +86,7 @@ export default class OCPPService { setTimeout(async () => { await OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation); }, Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_BOOT_NOTIFICATION, @@ -126,7 +126,7 @@ export default class OCPPService { heartbeat.timezone = Utils.getTimezone(chargingStation.coordinates); // Save Heart Beat await OCPPStorage.saveHeartbeat(tenant, heartbeat); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleHeartbeat', @@ -156,7 +156,7 @@ export default class OCPPService { this.enrichOCPPRequest(chargingStation, statusNotification, false); // Skip connectorId = 0 case if (statusNotification.connectorId <= 0) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STATUS_NOTIFICATION, @@ -186,7 +186,7 @@ export default class OCPPService { // Handle Charging Station's specificities this.filterMeterValuesOnSpecificChargingStations(tenant, chargingStation, normalizedMeterValues); if (Utils.isEmptyArray(normalizedMeterValues.values)) { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleMeterValues', @@ -242,7 +242,7 @@ export default class OCPPService { // Yes: Trigger Smart Charging await this.triggerSmartCharging(tenant, chargingStation.siteArea); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_METER_VALUES, @@ -272,7 +272,7 @@ export default class OCPPService { this.enrichAuthorize(user, chargingStation, headers, authorize); // Save await OCPPStorage.saveAuthorize(tenant, authorize); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleAuthorize', @@ -309,7 +309,7 @@ export default class OCPPService { this.enrichOCPPRequest(chargingStation, diagnosticsStatusNotification); // Save it await OCPPStorage.saveDiagnosticsStatusNotification(tenant, diagnosticsStatusNotification); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_DIAGNOSTICS_STATUS_NOTIFICATION, @@ -338,7 +338,7 @@ export default class OCPPService { await ChargingStationStorage.saveChargingStationFirmwareStatus(tenant, chargingStation.id, firmwareStatusNotification.status); // Save it await OCPPStorage.saveFirmwareStatusNotification(tenant, firmwareStatusNotification); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleFirmwareStatusNotification', @@ -395,7 +395,7 @@ export default class OCPPService { await ChargingStationStorage.saveChargingStation(tenant, chargingStation); // Notify NotificationHelper.notifyStartTransaction(tenant, newTransaction, chargingStation, user); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleStartTransaction', @@ -433,7 +433,7 @@ export default class OCPPService { this.enrichOCPPRequest(chargingStation, dataTransfer); // Save it await OCPPStorage.saveDataTransfer(tenant, dataTransfer); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleDataTransfer', @@ -502,7 +502,7 @@ export default class OCPPService { NotificationHelper.notifyStopTransaction(tenant, chargingStation, transaction, user, alternateUser); // Recompute the Smart Charging Plan await this.triggerSmartChargingStopTransaction(tenant, chargingStation, transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleStopTransaction', @@ -668,7 +668,7 @@ export default class OCPPService { // Trigger Smart Charging await this.triggerSmartCharging(tenant, chargingStation.siteArea); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'triggerSmartChargingStopTransaction', @@ -692,7 +692,7 @@ export default class OCPPService { for (const chargingProfile of chargingProfiles.result) { try { await OCPPUtils.clearAndDeleteChargingProfile(tenant, chargingProfile); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -701,7 +701,7 @@ export default class OCPPService { detailedMessages: { chargingProfile } }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -744,7 +744,7 @@ export default class OCPPService { await ChargingStationStorage.saveChargingStation(tenant, chargingStation); // Process Smart Charging await this.processSmartChargingFromStatusNotification(tenant, chargingStation, connector, previousStatus); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'processConnectorStatusNotification', @@ -766,7 +766,7 @@ export default class OCPPService { // Trigger Smart Charging await this.triggerSmartCharging(tenant, chargingStation.siteArea); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'processSmartChargingStatusNotification', @@ -810,7 +810,7 @@ export default class OCPPService { // Same Status Notification? } else if (Utils.objectAllPropertiesAreEqual(statusNotification, connector, ['status', 'info', 'errorCode', 'vendorErrorCode'])) { ignoreStatusNotification = true; - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STATUS_NOTIFICATION, @@ -850,7 +850,7 @@ export default class OCPPService { await TransactionStorage.saveTransaction(tenant, lastTransaction); } } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndUpdateLastCompletedTransactionFromStatusNotification', @@ -862,7 +862,7 @@ export default class OCPPService { // Clear Connector Runtime Data OCPPUtils.clearChargingStationConnectorRuntimeData(chargingStation, lastTransaction.connectorId); } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(lastTransaction), tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndUpdateLastCompletedTransactionFromStatusNotification', @@ -897,7 +897,7 @@ export default class OCPPService { Utils.createDecimal(currentStatusNotifTimestamp.getTime()).minus(transactionStopTimestamp.getTime()).div(1000).floor().toNumber(); // Negative inactivity if (transaction.stop.extraInactivitySecs < 0) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndComputeTransactionExtraInactivityFromStatusNotification', @@ -915,7 +915,7 @@ export default class OCPPService { ); // Build extra inactivity consumption await OCPPUtils.buildAndPriceExtraConsumptionInactivity(tenant, user, chargingStation, transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, user: transaction.userID, @@ -927,7 +927,7 @@ export default class OCPPService { } } else { // No extra inactivity - connector status is not set to FINISHING - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, user: transaction.userID, @@ -961,7 +961,7 @@ export default class OCPPService { if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.FINISHING && // TODO: To remove after fix of ABB bug having Finishing status with an Error Code to avoid spamming Admins connector.errorCode !== ChargePointErrorCode.NO_ERROR) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STATUS_NOTIFICATION, @@ -1192,7 +1192,7 @@ export default class OCPPService { meterValues.values = meterValues.values.filter(async (meterValue) => { // Remove Sample Clock if (meterValue.attribute && meterValue.attribute.context === OCPPReadingContext.SAMPLE_CLOCK) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'filterMeterValuesOnSpecificChargingStations', @@ -1297,7 +1297,7 @@ export default class OCPPService { // Has consumption? if (activeTransaction.currentTotalConsumptionWh <= 0) { // No consumption: delete - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'stopOrDeleteActiveTransactions', @@ -1325,7 +1325,7 @@ export default class OCPPService { }, false, true); if (result.idTagInfo.status === OCPPAuthorizationStatus.INVALID) { // Cannot stop it - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'stopOrDeleteActiveTransactions', @@ -1336,7 +1336,7 @@ export default class OCPPService { }); } else { // Stopped - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'stopOrDeleteActiveTransactions', @@ -1713,7 +1713,7 @@ export default class OCPPService { stopTransaction: OCPPStopTransactionRequestExtended): Promise { // Ignore it (DELTA bug)? if (stopTransaction.transactionId === 0) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'bypassStopTransaction', @@ -1767,7 +1767,7 @@ export default class OCPPService { } // Received Meter Values after the Transaction End Meter Value if (transaction.transactionEndReceived) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'getTransactionFromMeterValues', @@ -1783,7 +1783,7 @@ export default class OCPPService { // Get the OCPP Client const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'abortOngoingTransactionInMeterValues', @@ -1797,7 +1797,7 @@ export default class OCPPService { transactionId: meterValues.transactionId }); if (result.status === OCPPRemoteStartStopStatus.ACCEPTED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'abortOngoingTransactionInMeterValues', @@ -1806,7 +1806,7 @@ export default class OCPPService { detailedMessages: { meterValues } }); } else { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'abortOngoingTransactionInMeterValues', @@ -1867,7 +1867,7 @@ export default class OCPPService { } else if (transaction.lastConsumption) { // The consumption should be the same if (transaction.lastConsumption.value !== stopTransaction.meterStop) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STOP_TRANSACTION, diff --git a/src/server/ocpp/soap/SoapOCPPServer.ts b/src/server/ocpp/soap/SoapOCPPServer.ts index 997ecbce44..76ce42f3b6 100644 --- a/src/server/ocpp/soap/SoapOCPPServer.ts +++ b/src/server/ocpp/soap/SoapOCPPServer.ts @@ -72,7 +72,7 @@ export default class SoapOCPPServer extends OCPPServer { } private async handleSoapServerMessage(ocppVersion: OCPPVersion, request: any, methodName: string) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'handleSoapServerMessage', action: ServerAction.EXPRESS_SERVER, @@ -84,7 +84,7 @@ export default class SoapOCPPServer extends OCPPServer { private async handleSoapServerLog(ocppVersion: OCPPVersion, type: string, data: any) { // Do not log 'Info' if (type === 'replied') { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'handleSoapServerLog', action: ServerAction.EXPRESS_SERVER, diff --git a/src/server/ocpp/utils/OCPPCommon.ts b/src/server/ocpp/utils/OCPPCommon.ts index bad25b8252..e26fa1bab5 100644 --- a/src/server/ocpp/utils/OCPPCommon.ts +++ b/src/server/ocpp/utils/OCPPCommon.ts @@ -35,7 +35,7 @@ export default class OCPPCommon { await OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation); } if (triggerConditionalReset && result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -52,7 +52,7 @@ export default class OCPPCommon { try { // Get the OCPP Configuration const ocppConfiguration = await OCPPCommon.requestChargingStationOcppParameters(tenant, chargingStation, {}); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -90,7 +90,7 @@ export default class OCPPCommon { } // Save configuration await ChargingStationStorage.saveOcppParameters(tenant, chargingStationOcppParameters); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -118,7 +118,7 @@ export default class OCPPCommon { } let resetResult = await chargingStationClient.reset({ type: resetType }); if (resetResult.status === OCPPResetStatus.REJECTED) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_RESET, @@ -126,7 +126,7 @@ export default class OCPPCommon { message: `Error at ${resetType} Rebooting charging station`, }); if (hardResetFallback && resetType !== OCPPResetType.HARD) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_RESET, @@ -135,7 +135,7 @@ export default class OCPPCommon { }); resetResult = await chargingStationClient.reset({ type: OCPPResetType.HARD }); if (resetResult.status === OCPPResetStatus.REJECTED) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_RESET, diff --git a/src/server/ocpp/utils/OCPPUtils.ts b/src/server/ocpp/utils/OCPPUtils.ts index 3be8399e03..82d3f9c022 100644 --- a/src/server/ocpp/utils/OCPPUtils.ts +++ b/src/server/ocpp/utils/OCPPUtils.ts @@ -482,7 +482,7 @@ export default class OCPPUtils { // Meter Value is in the past if (transaction.lastConsumption?.timestamp && meterValue.timestamp && moment(meterValue?.timestamp).isBefore(moment(transaction?.lastConsumption?.timestamp))) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'createConsumptionsFromMeterValues', @@ -795,7 +795,7 @@ export default class OCPPUtils { // Add unknown Connector ID chargingStation.chargePoints[0].connectorIDs.push(connector.connectorId); } - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -821,7 +821,7 @@ export default class OCPPUtils { } // Not found but not master/salve if (!foundTemplateConnector) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -874,7 +874,7 @@ export default class OCPPUtils { await OCPPUtils.setConnectorPhaseAssignment(tenant, chargingStation, connector, numberOfPhases); } // Success - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -885,7 +885,7 @@ export default class OCPPUtils { return true; } // No Connector in Template - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -896,7 +896,7 @@ export default class OCPPUtils { return false; } // No Template - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -920,7 +920,7 @@ export default class OCPPUtils { } public static async applyTemplateOcppParametersToChargingStation(tenant: Tenant, chargingStation: ChargingStation): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -932,7 +932,7 @@ export default class OCPPUtils { Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS, OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation), `Time out error (${Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS} ms): Cannot update Charging Station with Template's OCPP Parameters`); if (result.status !== OCPPConfigurationStatus.ACCEPTED) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -945,7 +945,7 @@ export default class OCPPUtils { Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS, OCPPUtils.updateChargingStationOcppParametersWithTemplate(tenant, chargingStation), `Time out error (${Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS} ms): Cannot update Charging Station with Template's OCPP Parameters`); if (result.status === OCPPConfigurationStatus.ACCEPTED) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -953,7 +953,7 @@ export default class OCPPUtils { message: 'Charging Station has been successfully updated with Template\'s OCPP Parameters', }); } else { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -984,7 +984,7 @@ export default class OCPPUtils { await this.clearAndDeleteChargingProfile(tenant, chargingProfile); actionsResponse.inSuccess++; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, siteID: chargingProfile.chargingStation?.siteID, siteAreaID: chargingProfile.chargingStation?.siteAreaID, @@ -1039,7 +1039,7 @@ export default class OCPPUtils { try { await chargingStationVendor.clearChargingProfile(tenant, chargingStation, chargingProfile); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -1051,7 +1051,7 @@ export default class OCPPUtils { } // Delete from database await ChargingStationStorage.deleteChargingProfile(tenant, chargingProfile.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -1136,7 +1136,7 @@ export default class OCPPUtils { } // Save const chargingProfileID = await ChargingStationStorage.saveChargingProfile(tenant, chargingProfile); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_UPDATE, @@ -1268,7 +1268,7 @@ export default class OCPPUtils { // Must have a valid connection Token token = await OCPPUtils.ensureChargingStationHasValidConnectionToken(action, tenant, chargingStationID, tokenID); // Ok, set it - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, module: MODULE_NAME, method: 'checkAndGetChargingStationData', @@ -1320,7 +1320,7 @@ export default class OCPPUtils { const currentOcppParameters = (await ChargingStationStorage.getOcppParameters(tenant, chargingStation.id)).result; if (Utils.isEmptyArray(chargingStation.ocppStandardParameters) && Utils.isEmptyArray(chargingStation.ocppVendorParameters)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1340,7 +1340,7 @@ export default class OCPPUtils { // Check Value if (currentOcppParam && currentOcppParam.value === ocppParameter.value) { // Ok: Already the good value - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1356,7 +1356,7 @@ export default class OCPPUtils { }, false); if (result.status === OCPPConfigurationStatus.ACCEPTED) { updatedOcppParameters.inSuccess++; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1366,7 +1366,7 @@ export default class OCPPUtils { } else if (result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { updatedOcppParameters.inSuccess++; rebootRequired = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1375,7 +1375,7 @@ export default class OCPPUtils { }); } else { updatedOcppParameters.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1385,7 +1385,7 @@ export default class OCPPUtils { } } catch (error) { updatedOcppParameters.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1433,7 +1433,7 @@ export default class OCPPUtils { // Log const instantPower = Utils.truncTo(Utils.createDecimal(connector.currentInstantWatts).div(1000).toNumber(), 3); const totalConsumption = Utils.truncTo(Utils.createDecimal(connector.currentTotalConsumptionWh).div(1000).toNumber(), 3); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'updateChargingStationConnectorRuntimeDataWithTransaction', @@ -1512,7 +1512,7 @@ export default class OCPPUtils { }; // Do not apply template if manual configured if (chargingStation.manualConfiguration) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1527,7 +1527,7 @@ export default class OCPPUtils { if (chargingStationTemplate) { // Already updated? if (chargingStation.templateHash !== chargingStationTemplate.hash) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1550,7 +1550,7 @@ export default class OCPPUtils { // Update chargingStation.templateHash = chargingStationTemplate.hash; templateUpdateResult.chargingStationUpdated = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1559,7 +1559,7 @@ export default class OCPPUtils { detailedMessages: { templateUpdateResult, chargingStationTemplate, chargingStation } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1575,7 +1575,7 @@ export default class OCPPUtils { } } } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1633,7 +1633,7 @@ export default class OCPPUtils { if (matchFirmware && matchOcpp) { for (const parameter in ocppParameters.parameters) { if (OCPPUtils.isOcppParamForPowerLimitationKey(parameter, chargingStation)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1644,7 +1644,7 @@ export default class OCPPUtils { continue; } if (Constants.OCPP_HEARTBEAT_KEYS.includes(parameter)) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1663,7 +1663,7 @@ export default class OCPPUtils { } } // Not found - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1710,7 +1710,7 @@ export default class OCPPUtils { } } // Not found - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, diff --git a/src/server/ocpp/validator/OCPPValidator.ts b/src/server/ocpp/validator/OCPPValidator.ts index d04285ee24..a9d05b93ee 100644 --- a/src/server/ocpp/validator/OCPPValidator.ts +++ b/src/server/ocpp/validator/OCPPValidator.ts @@ -112,7 +112,7 @@ export default class OCPPValidator extends SchemaValidator { // Check Connector ID if (meterValues.connectorId === 0) { // KEBA: Connector ID must be > 0 according to OCPP - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenantID, module: MODULE_NAME, method: 'validateMeterValues', @@ -125,7 +125,7 @@ export default class OCPPValidator extends SchemaValidator { // Check if the transaction ID matches with the one on the Connector const foundConnector = Utils.getConnectorFromID(chargingStation, meterValues.connectorId); if (!foundConnector) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenantID, module: MODULE_NAME, method: 'validateMeterValues', @@ -140,7 +140,7 @@ export default class OCPPValidator extends SchemaValidator { if (meterValues.transactionId === 0 && foundConnector.currentTransactionID > 0) { // Reuse Transaction ID from Connector meterValues.transactionId = foundConnector.currentTransactionID; - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenantID, module: MODULE_NAME, method: 'validateMeterValues', diff --git a/src/server/odata/ODataRestAdapter.ts b/src/server/odata/ODataRestAdapter.ts index 648f0d7378..078bd3633c 100644 --- a/src/server/odata/ODataRestAdapter.ts +++ b/src/server/odata/ODataRestAdapter.ts @@ -97,7 +97,7 @@ export default class ODataRestAdapter { } } catch (error) { // Add logging - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.user.tenantID, module: MODULE_NAME, method: 'query', action: ServerAction.ODATA_SERVER, diff --git a/src/server/odata/odata-schema/ODataSchema.ts b/src/server/odata/odata-schema/ODataSchema.ts index e41221636a..a00c038c71 100644 --- a/src/server/odata/odata-schema/ODataSchema.ts +++ b/src/server/odata/odata-schema/ODataSchema.ts @@ -42,7 +42,7 @@ export default class ODataSchema { } } catch (error) { // Add logging: login info - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'getSchema', action: ServerAction.ODATA_SERVER, diff --git a/src/server/oicp/AbstractOICPService.ts b/src/server/oicp/AbstractOICPService.ts index 246baa4acf..b6e25fa560 100644 --- a/src/server/oicp/AbstractOICPService.ts +++ b/src/server/oicp/AbstractOICPService.ts @@ -103,7 +103,7 @@ export default abstract class AbstractOICPService { // Handle request action (endpoint) const endpoint = registeredEndpoints.get(endpointName); if (endpoint) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: endpointName, message: `>> OICP Request ${req.method} ${req.originalUrl}`, @@ -112,7 +112,7 @@ export default abstract class AbstractOICPService { }); const response = await endpoint.process(req, res, next, tenant); if (response) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: endpointName, message: `<< OICP Response ${req.method} ${req.originalUrl}`, @@ -121,7 +121,7 @@ export default abstract class AbstractOICPService { }); res.json(response); } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: endpointName, message: `<< OICP Endpoint ${req.method} ${req.originalUrl} not implemented`, @@ -139,7 +139,7 @@ export default abstract class AbstractOICPService { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.user && req.user.tenantID ? req.user.tenantID : Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: endpointName, message: `<< OICP Response Error ${req.method} ${req.originalUrl}`, diff --git a/src/server/oicp/OICPFacade.ts b/src/server/oicp/OICPFacade.ts index 3204ac2d68..19f48244fc 100644 --- a/src/server/oicp/OICPFacade.ts +++ b/src/server/oicp/OICPFacade.ts @@ -58,7 +58,7 @@ export default class OICPFacade { // Update OICP Session await oicpClient.updateSession(transaction); } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processUpdateTransaction', @@ -128,7 +128,7 @@ export default class OICPFacade { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'updateConnectorStatus', diff --git a/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts b/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts index 876a6dc5a5..1a63f5fa9a 100644 --- a/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts +++ b/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts @@ -61,7 +61,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { const connector = chargingStationConnector.connector; const chargingStation = chargingStationConnector.chargingStation; if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Charging Station ID '${authorizeRemoteStart.EvseID}' not found`, @@ -70,7 +70,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `EVSE for EvseID '${authorizeRemoteStart.EvseID}' not found`); } if (!connector) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Connector for Charging Station ID '${authorizeRemoteStart.EvseID}' not found`, @@ -79,7 +79,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `EVSE for EvseID '${authorizeRemoteStart.EvseID}' not found`); } if (!chargingStation.issuer || !chargingStation.public) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Charging Station ID '${authorizeRemoteStart.EvseID}' cannot be used with OICP`, @@ -88,7 +88,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `EVSE '${authorizeRemoteStart.EvseID}' cannot be used with OICP`); } if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.PREPARING) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Charging Station ID '${authorizeRemoteStart.EvseID}' is not available`, @@ -108,7 +108,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { // Check if authorization of different user is valid if (OICPUtils.isAuthorizationValid(existingAuthorization.timestamp)) { // Current remote authorization fails due to valid remote authorization of different user - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, @@ -155,7 +155,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { session.providerID = authorizeRemoteStop.ProviderID; const transaction = await TransactionStorage.getOICPTransactionBySessionID(tenant, authorizeRemoteStop.SessionID); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, message: `OICP Transaction ID '${authorizeRemoteStop.SessionID}' does not exists`, @@ -164,7 +164,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `Transaction with OICP Transaction ID '${authorizeRemoteStop.SessionID}' does not exists`); } if (!transaction.issuer) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, message: `OICP Transaction ID '${authorizeRemoteStop.SessionID}' has been issued locally`, @@ -173,7 +173,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `Transaction with OICP Transaction ID '${authorizeRemoteStop.SessionID}' has been issued locally`); } if (transaction.stop) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, message: `OICP Transaction ID '${authorizeRemoteStop.SessionID}' is already stopped`, @@ -183,7 +183,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { } const chargingStation = await ChargingStationStorage.getChargingStation(tenant, transaction.chargeBoxID); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, @@ -204,7 +204,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { connector: Connector, authorizeRemoteStart: OICPAuthorizeRemoteStartCpoReceive): Promise { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, @@ -222,7 +222,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { private async remoteStopTransaction(tenant: Tenant, chargingStation: ChargingStation, transactionId: number): Promise { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, diff --git a/src/server/rest/RestServerService.ts b/src/server/rest/RestServerService.ts index 8c25795ee9..b373d1442d 100644 --- a/src/server/rest/RestServerService.ts +++ b/src/server/rest/RestServerService.ts @@ -253,7 +253,7 @@ export default class RestServerService { try { // Parse the action const action = req.params.action as ServerAction; - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, message: `REST Endpoint 'restServiceUtil' should not be used for action '${action}'`, action: ServerAction.DEPRECATED_REST_ENDPOINT, @@ -311,7 +311,7 @@ export default class RestServerService { // Parse the action const action = req.params.action as ServerAction; // Old endpoint: should not be used - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: req.tenant?.id, message: `REST Endpoint 'restServiceSecured' should not be used for action '${action}'`, action: ServerAction.DEPRECATED_REST_ENDPOINT, diff --git a/src/server/rest/v1/service/AssetService.ts b/src/server/rest/v1/service/AssetService.ts index 574f7a6f04..b5875c8ab9 100644 --- a/src/server/rest/v1/service/AssetService.ts +++ b/src/server/rest/v1/service/AssetService.ts @@ -166,7 +166,7 @@ export default class AssetService { res.json(Object.assign({ connectionIsValid: true }, Constants.REST_RESPONSE_SUCCESS)); } catch (error) { // KO - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCheckAssetConnection', @@ -292,7 +292,7 @@ export default class AssetService { // Delete await AssetStorage.deleteAsset(req.tenant, asset.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getAssetProperties(asset), tenantID: req.tenant.id, user: req.user, @@ -422,7 +422,7 @@ export default class AssetService { // Save newAsset.id = await AssetStorage.saveAsset(req.tenant, newAsset); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getAssetProperties(newAsset), tenantID: req.tenant.id, user: req.user, @@ -469,7 +469,7 @@ export default class AssetService { asset.lastChangedOn = new Date(); await AssetStorage.saveAsset(req.tenant, asset); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getAssetProperties(asset), tenantID: req.tenant.id, user: req.user, diff --git a/src/server/rest/v1/service/AuthService.ts b/src/server/rest/v1/service/AuthService.ts index 8a35a2fcd4..d41054d36c 100644 --- a/src/server/rest/v1/service/AuthService.ts +++ b/src/server/rest/v1/service/AuthService.ts @@ -77,7 +77,7 @@ export default class AuthService { // Yes: Check date to reset pass if (user.passwordBlockedUntil && moment(user.passwordBlockedUntil).isBefore(moment())) { // Time elapsed: activate the account again - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.user.tenantID, actionOnUser: user, module: MODULE_NAME, method: 'handleLogIn', action: action, @@ -199,7 +199,7 @@ export default class AuthService { }; await TagStorage.saveTag(req.tenant, tag); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: newUser, action: action, module: MODULE_NAME, @@ -249,7 +249,7 @@ export default class AuthService { const resetHash = Utils.generateUUID(); // Init Password info await UserStorage.saveUserPassword(tenant, user.id, { passwordResetHash: resetHash }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, user: user, action: action, module: MODULE_NAME, @@ -295,7 +295,7 @@ export default class AuthService { if (user.status === UserStatus.LOCKED) { await UserStorage.saveUserStatus(tenant, user.id, UserStatus.ACTIVE); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, user: user, action: action, module: MODULE_NAME, @@ -440,7 +440,7 @@ export default class AuthService { // Save User Verification Account await UserStorage.saveUserAccountVerification(req.tenant, user.id, { verificationToken: null, verifiedAt: new Date() }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: user, action: action, module: MODULE_NAME, method: 'handleVerifyEmail', @@ -517,7 +517,7 @@ export default class AuthService { // Get existing verificationToken verificationToken = user.verificationToken; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: user, action: action, @@ -590,7 +590,7 @@ export default class AuthService { public static async userLoginSucceeded(action: ServerAction, tenant: Tenant, user: User, req: Request, res: Response, next: NextFunction): Promise { // Password / Login OK - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, user: user, module: MODULE_NAME, method: 'checkUserLogin', diff --git a/src/server/rest/v1/service/BillingService.ts b/src/server/rest/v1/service/BillingService.ts index 98eaad30be..799d5c7355 100644 --- a/src/server/rest/v1/service/BillingService.ts +++ b/src/server/rest/v1/service/BillingService.ts @@ -59,7 +59,7 @@ export default class BillingService { res.json(operationResult); } catch (error) { // Ko - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleClearBillingTestData', @@ -96,7 +96,7 @@ export default class BillingService { res.json(Object.assign({ connectionIsValid: true }, Constants.REST_RESPONSE_SUCCESS)); } catch (error) { // Ko - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCheckBillingConnection', @@ -296,7 +296,7 @@ export default class BillingService { const user: User = await UtilsService.checkAndGetUserAuthorization(req.tenant, req.user, filteredRequest.userID, Action.READ, action); // Invoke the billing implementation const paymentMethods: BillingPaymentMethod[] = await billingImpl.getPaymentMethods(user); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user, action: ServerAction.BILLING_PAYMENT_METHODS, @@ -339,7 +339,7 @@ export default class BillingService { // Invoke the billing implementation const operationResult: BillingOperationResult = await billingImpl.deletePaymentMethod(user, filteredRequest.paymentMethodId); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSite', message: `Payment Method '${filteredRequest.paymentMethodId}' has been deleted successfully`, diff --git a/src/server/rest/v1/service/CarService.ts b/src/server/rest/v1/service/CarService.ts index a589055a5d..b5d5d5d16b 100644 --- a/src/server/rest/v1/service/CarService.ts +++ b/src/server/rest/v1/service/CarService.ts @@ -242,7 +242,7 @@ export default class CarService { }; // Save newCar.id = await CarStorage.saveCar(req.tenant, newCar); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, ...LoggingHelper.getCarProperties(newCar), user: req.user, module: MODULE_NAME, method: 'handleCreateCar', @@ -323,7 +323,7 @@ export default class CarService { if (setDefaultCarToOldUserID) { await CarService.setDefaultCarForUser(req.tenant, setDefaultCarToOldUserID); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, ...LoggingHelper.getCarProperties(car), user: req.user, module: MODULE_NAME, method: 'handleUpdateCar', @@ -405,7 +405,7 @@ export default class CarService { if (car.default) { await CarService.setDefaultCarForUser(req.tenant, car.userID); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getCarProperties(car), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteCar', diff --git a/src/server/rest/v1/service/ChargingStationService.ts b/src/server/rest/v1/service/ChargingStationService.ts index 017d1c9869..d1b3c81494 100644 --- a/src/server/rest/v1/service/ChargingStationService.ts +++ b/src/server/rest/v1/service/ChargingStationService.ts @@ -87,7 +87,7 @@ export default class ChargingStationService { // Check and Apply Charging Station templates await ChargingStationService.checkAndApplyChargingStationTemplate( action, req.tenant, chargingStation, req.user, resetAndApplyTemplate); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, action, user: req.user, module: MODULE_NAME, method: 'handleUpdateChargingStationParams', @@ -164,7 +164,7 @@ export default class ChargingStationService { detailedMessages: { result }, }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, action, user: req.user, @@ -397,7 +397,7 @@ export default class ChargingStationService { // Delete physically await ChargingStationStorage.deleteChargingStation(req.tenant, chargingStation.id); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteChargingStation', message: `Charging Station '${chargingStation.id}' has been deleted successfully`, @@ -864,7 +864,7 @@ export default class ChargingStationService { } // OCPP Command with status if (Utils.objectHasProperty(result, 'status') && ![OCPPStatus.ACCEPTED, OCPPUnlockStatus.UNLOCKED].includes(result.status)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, user: req.user, @@ -874,7 +874,7 @@ export default class ChargingStationService { }); } else { // OCPP Command with no status - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, user: req.user, @@ -1321,7 +1321,7 @@ export default class ChargingStationService { result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { // Reboot? if (result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, action, user: req.user, @@ -1389,7 +1389,7 @@ export default class ChargingStationService { await ocpiClient.patchChargingStationStatus(chargingStation, status); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'updateChargingStationRoaming', action, @@ -1421,7 +1421,7 @@ export default class ChargingStationService { site, chargingStation.siteArea, chargingStation, options), actionType); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'updateChargingStationRoaming', action, @@ -1453,7 +1453,7 @@ export default class ChargingStationService { site, siteArea, chargingStation, options), OICPActionType.DELETE); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'deactivateChargingStationRoaming', action, @@ -1690,7 +1690,7 @@ export default class ChargingStationService { detailedMessages: { result: chargingProfiles[index] } }); } - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, user, diff --git a/src/server/rest/v1/service/ChargingStationTemplateService.ts b/src/server/rest/v1/service/ChargingStationTemplateService.ts index e749391ed3..c464c7b424 100644 --- a/src/server/rest/v1/service/ChargingStationTemplateService.ts +++ b/src/server/rest/v1/service/ChargingStationTemplateService.ts @@ -34,7 +34,7 @@ export default class ChargingStationTemplateService { } }; newChargingStationTemplate.id = await ChargingStationTemplateStorage.saveChargingStationTemplate(newChargingStationTemplate); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateChargingStationTemplate', message: `ChargingStationTemplate '${newChargingStationTemplate.id}' has been created successfully`, @@ -99,7 +99,7 @@ export default class ChargingStationTemplateService { const chargingStationTemplate = await UtilsService.checkAndGetChargingStationTemplateAuthorization(req.tenant, req.user, chargingStationTemplateID, Action.DELETE, action); // Delete await ChargingStationTemplateStorage.deleteChargingStationTemplate(req.tenant, chargingStationTemplate.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteChargingStationTemplate', message: `Charging Station Template'${chargingStationTemplate.id}' has been deleted successfully`, @@ -129,7 +129,7 @@ export default class ChargingStationTemplateService { chargingStationTemplate.lastChangedOn = new Date(); // Save await ChargingStationTemplateStorage.saveChargingStationTemplate(chargingStationTemplate); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateChargingStationTemplate', message: `'${chargingStationTemplate.id}' has been updated successfully`, diff --git a/src/server/rest/v1/service/CompanyService.ts b/src/server/rest/v1/service/CompanyService.ts index daceb2b644..136f92a69d 100644 --- a/src/server/rest/v1/service/CompanyService.ts +++ b/src/server/rest/v1/service/CompanyService.ts @@ -30,7 +30,7 @@ export default class CompanyService { req.tenant, req.user, companyID, Action.DELETE, action); // Delete await CompanyStorage.deleteCompany(req.tenant, company.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteCompany', message: `Company '${company.name}' has been deleted successfully`, @@ -163,7 +163,7 @@ export default class CompanyService { } // Save newCompany.id = await CompanyStorage.saveCompany(req.tenant, newCompany); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateCompany', message: `Company '${newCompany.id}' has been created successfully`, @@ -203,7 +203,7 @@ export default class CompanyService { company.lastChangedOn = new Date(); // Update Company await CompanyStorage.saveCompany(req.tenant, company, Utils.objectHasProperty(filteredRequest, 'logo') ? true : false); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateCompany', message: `Company '${company.name}' has been updated successfully`, diff --git a/src/server/rest/v1/service/ConnectionService.ts b/src/server/rest/v1/service/ConnectionService.ts index 7f12d1f2fa..aff28cd8d6 100644 --- a/src/server/rest/v1/service/ConnectionService.ts +++ b/src/server/rest/v1/service/ConnectionService.ts @@ -104,7 +104,7 @@ export default class ConnectionService { if (!Utils.isNullOrUndefined(integrationConnector)) { // Create const connection: Connection = await integrationConnector.createConnection(filteredRequest.userId, filteredRequest.data); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateConnection', message: `Connection to '${connection.connectorId}' has been created successfully`, @@ -141,7 +141,7 @@ export default class ConnectionService { // Delete await ConnectionStorage.deleteConnectionById(req.tenant, connection.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: connection.userId, diff --git a/src/server/rest/v1/service/OCPIEndpointService.ts b/src/server/rest/v1/service/OCPIEndpointService.ts index e1b9f77b0d..4ac50d04c3 100644 --- a/src/server/rest/v1/service/OCPIEndpointService.ts +++ b/src/server/rest/v1/service/OCPIEndpointService.ts @@ -34,7 +34,7 @@ export default class OCPIEndpointService { const ocpiEndpoint = await UtilsService.checkAndGetOCPIEndpointAuthorization(req.tenant, req.user, filteredRequest.ID, Action.DELETE, action); // Delete await OCPIEndpointStorage.deleteOcpiEndpoint(req.tenant, ocpiEndpoint.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' has been deleted successfully`, @@ -108,7 +108,7 @@ export default class OCPIEndpointService { status: OCPIRegistrationStatus.NEW } as OCPIEndpoint; const endpointID = await OCPIEndpointStorage.saveOcpiEndpoint(req.tenant, ocpiEndpoint); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateOcpiEndpoint', message: `Ocpi Endpoint '${filteredRequest.name}' has been created successfully`, @@ -132,7 +132,7 @@ export default class OCPIEndpointService { ocpiEndpoint.lastChangedOn = new Date(); // Update OcpiEndpoint await OCPIEndpointStorage.saveOcpiEndpoint(req.tenant, { ...ocpiEndpoint, ...filteredRequest }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' has been updated successfully`, @@ -157,7 +157,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.ping(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handlePingOcpiEndpoint', message: `Ocpi Endpoint '${filteredRequest.name}' can be reached successfully`, @@ -543,7 +543,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.updateCredentials(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateCredentialsOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' can be reached successfully`, @@ -585,7 +585,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.unregister(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUnregisterOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' can be reached successfully`, @@ -627,7 +627,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.register(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleRegisterOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' can be reached successfully`, @@ -663,7 +663,7 @@ export default class OCPIEndpointService { await AuthorizationService.checkAndGetOCPIEndpointsAuthorizations(req.tenant, req.user, Action.GENERATE_LOCAL_TOKEN); // Generate endpoint const localToken = OCPIUtils.generateLocalToken(req.tenant.subdomain); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleGenerateLocalTokenOcpiEndpoint', message: 'Local Token for Ocpi Endpoint has been generated successfully', diff --git a/src/server/rest/v1/service/OICPEndpointService.ts b/src/server/rest/v1/service/OICPEndpointService.ts index 7934c640a0..887b2c7d9b 100644 --- a/src/server/rest/v1/service/OICPEndpointService.ts +++ b/src/server/rest/v1/service/OICPEndpointService.ts @@ -44,7 +44,7 @@ export default class OICPEndpointService { // Delete await OICPEndpointStorage.deleteOicpEndpoint(req.tenant, oicpEndpoint.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' has been deleted successfully`, @@ -91,7 +91,7 @@ export default class OICPEndpointService { } as OICPEndpoint; const endpointID = await OICPEndpointStorage.saveOicpEndpoint(req.tenant, oicpEndpoint); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateOicpEndpoint', message: `Oicp Endpoint '${filteredRequest.name}' has been created successfully`, @@ -128,7 +128,7 @@ export default class OICPEndpointService { // Update OicpEndpoint await OICPEndpointStorage.saveOicpEndpoint(req.tenant, { ...oicpEndpoint, ...filteredRequest }); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' has been updated successfully`, @@ -293,7 +293,7 @@ export default class OICPEndpointService { // Check ping result if (pingResult.statusCode === OICPStatusCode.Code000) { // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handlePingOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' can be reached successfully`, @@ -303,7 +303,7 @@ export default class OICPEndpointService { res.json(Object.assign(pingResult, Constants.REST_RESPONSE_SUCCESS)); } else { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handlePingOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' cannot be reached`, @@ -341,7 +341,7 @@ export default class OICPEndpointService { // Check ping result if (result.statusCode === StatusCodes.OK) { // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUnregisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' can be reached successfully`, @@ -351,7 +351,7 @@ export default class OICPEndpointService { res.json(Object.assign(result, Constants.REST_RESPONSE_SUCCESS)); } else { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUnregisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' cannot be reached`, @@ -389,7 +389,7 @@ export default class OICPEndpointService { // Check ping result if (result.statusCode === StatusCodes.OK) { // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleRegisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' can be reached successfully`, @@ -399,7 +399,7 @@ export default class OICPEndpointService { res.json(Object.assign(result, Constants.REST_RESPONSE_SUCCESS)); } else { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleRegisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' cannot be reached`, diff --git a/src/server/rest/v1/service/PricingService.ts b/src/server/rest/v1/service/PricingService.ts index f4ca032361..e8567210e0 100644 --- a/src/server/rest/v1/service/PricingService.ts +++ b/src/server/rest/v1/service/PricingService.ts @@ -130,7 +130,7 @@ export default class PricingService { // Save newPricingDefinition.id = await PricingStorage.savePricingDefinition(req.tenant, newPricingDefinition); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreatePricingDefinition', message: `Pricing model '${newPricingDefinition.id}' has been created successfully`, @@ -172,7 +172,7 @@ export default class PricingService { // Update Pricing await PricingStorage.savePricingDefinition(req.tenant, pricingDefinition); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdatePricingDefinition', message: `Pricing model '${pricingDefinition.id}' has been updated successfully`, @@ -201,7 +201,7 @@ export default class PricingService { // Delete await PricingStorage.deletePricingDefinition(req.tenant, pricingDefinition.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeletePricingDefinition', message: `Pricing model '${pricingDefinitionID}' has been deleted successfully`, @@ -249,7 +249,7 @@ export default class PricingService { } catch (error) { canCreate = false; if (!(error instanceof AppAuthError)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'alterCanCreate', message: 'Unexpected error while checking site access permissions', diff --git a/src/server/rest/v1/service/RegistrationTokenService.ts b/src/server/rest/v1/service/RegistrationTokenService.ts index 6a28ef380b..94c4de4ce8 100644 --- a/src/server/rest/v1/service/RegistrationTokenService.ts +++ b/src/server/rest/v1/service/RegistrationTokenService.ts @@ -41,7 +41,7 @@ export default class RegistrationTokenService { }; // Save registrationToken.id = await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateRegistrationToken', @@ -72,7 +72,7 @@ export default class RegistrationTokenService { registrationToken.revocationDate = null; // Save await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateRegistrationToken', @@ -91,7 +91,7 @@ export default class RegistrationTokenService { req.tenant, req.user, registrationTokenID, Action.DELETE, action); // Delete await RegistrationTokenStorage.deleteRegistrationToken(req.tenant, registrationToken.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, @@ -126,7 +126,7 @@ export default class RegistrationTokenService { registrationToken.lastChangedOn = now; // Save await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, diff --git a/src/server/rest/v1/service/SettingService.ts b/src/server/rest/v1/service/SettingService.ts index d585d7fb8a..25f86d9f3c 100644 --- a/src/server/rest/v1/service/SettingService.ts +++ b/src/server/rest/v1/service/SettingService.ts @@ -28,7 +28,7 @@ export default class SettingService { // Delete await SettingStorage.deleteSetting(req.tenant, settingID); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSetting', message: `Setting '${setting.identifier}' has been deleted successfully`, @@ -110,7 +110,7 @@ export default class SettingService { // Save Setting filteredRequest.id = await SettingStorage.saveSettings(req.tenant, filteredRequest); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateSetting', message: `Setting '${filteredRequest.identifier}' has been created successfully`, @@ -223,7 +223,7 @@ export default class SettingService { } } // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateSetting', message: `Setting '${filteredRequest.id}' has been updated successfully`, diff --git a/src/server/rest/v1/service/SiteAreaService.ts b/src/server/rest/v1/service/SiteAreaService.ts index 170ded47c4..363736f3ee 100644 --- a/src/server/rest/v1/service/SiteAreaService.ts +++ b/src/server/rest/v1/service/SiteAreaService.ts @@ -50,7 +50,7 @@ export default class SiteAreaService { await SiteAreaStorage.removeAssetsFromSiteArea( req.tenant, filteredRequest.siteAreaID, assets.map((asset) => asset.id)); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, @@ -104,7 +104,7 @@ export default class SiteAreaService { req.tenant, filteredRequest.siteAreaID, chargingStations.map((chargingStation) => chargingStation.id)); } // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, @@ -130,7 +130,7 @@ export default class SiteAreaService { // Update children await SiteAreaStorage.attachSiteAreaChildrenToNewParent(req.tenant, siteArea.id, siteArea.parentSiteAreaID); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSiteArea', @@ -329,7 +329,7 @@ export default class SiteAreaService { req.tenant, rootSiteArea, siteArea, parentSiteArea, subSiteAreasActions); // Save siteArea.id = await SiteAreaStorage.saveSiteArea(req.tenant, siteArea, Utils.objectHasProperty(filteredRequest, 'image')); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateSiteArea', @@ -410,7 +410,7 @@ export default class SiteAreaService { } // Retrigger Smart Charging void SiteAreaService.triggerSmartCharging(req.tenant, action, siteArea); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateSiteArea', @@ -488,7 +488,7 @@ export default class SiteAreaService { await smartCharging.computeAndApplyChargingProfiles(siteArea); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: tenant.id, action, module: MODULE_NAME, method: 'triggerSmartCharging', diff --git a/src/server/rest/v1/service/SiteService.ts b/src/server/rest/v1/service/SiteService.ts index 8268b91e57..3c75f35dd0 100644 --- a/src/server/rest/v1/service/SiteService.ts +++ b/src/server/rest/v1/service/SiteService.ts @@ -44,7 +44,7 @@ export default class SiteService { const user = await UtilsService.checkAndGetUserAuthorization(req.tenant, req.user, filteredRequest.userID, Action.READ, action); // Update await SiteStorage.updateSiteUserAdmin(req.tenant, filteredRequest.siteID, filteredRequest.userID, filteredRequest.siteAdmin); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, actionOnUser: user, @@ -70,7 +70,7 @@ export default class SiteService { req.tenant, req.user, filteredRequest.userID, Action.READ, action); // Update await SiteStorage.updateSiteOwner(req.tenant, filteredRequest.siteID, filteredRequest.userID, filteredRequest.siteOwner); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, actionOnUser: user, @@ -111,7 +111,7 @@ export default class SiteService { } else { await SiteStorage.removeUsersFromSite(req.tenant, site.id, users.map((user) => user.id)); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, @@ -169,7 +169,7 @@ export default class SiteService { req.tenant, req.user, siteID, Action.DELETE, action); // Delete await SiteStorage.deleteSite(req.tenant, site.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSite', @@ -314,7 +314,7 @@ export default class SiteService { } // Save site.id = await SiteStorage.saveSite(req.tenant, site, Utils.objectHasProperty(filteredRequest, 'image')); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateSite', @@ -393,7 +393,7 @@ export default class SiteService { await SiteStorage.saveSite(req.tenant, site, Utils.objectHasProperty(filteredRequest, 'image')); // Update all refs void SiteStorage.updateEntitiesWithOrganizationIDs(req.tenant, site.companyID, filteredRequest.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateSite', diff --git a/src/server/rest/v1/service/TagService.ts b/src/server/rest/v1/service/TagService.ts index 88cbca338d..1b81da2de9 100644 --- a/src/server/rest/v1/service/TagService.ts +++ b/src/server/rest/v1/service/TagService.ts @@ -188,7 +188,7 @@ export default class TagService { await TagStorage.saveTag(req.tenant, newTag); // OCPI void TagService.updateTagRoaming(action, req.tenant, req.user, newTag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(newTag), tenantID: req.tenant.id, action: action, @@ -264,7 +264,7 @@ export default class TagService { await TagStorage.saveTag(req.tenant, tag); // OCPI void TagService.updateTagRoaming(action, req.tenant, req.user, tag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(tag), tenantID: req.tenant.id, action: action, @@ -306,7 +306,7 @@ export default class TagService { // Save await TagStorage.saveTag(req.tenant, tag); void TagService.updateTagRoaming(action, req.tenant, req.user, tag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(tag), tenantID: req.tenant.id, action: action, @@ -382,7 +382,7 @@ export default class TagService { } // OCPI void TagService.updateTagRoaming(action, req.tenant, req.user, tag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(tag), tenantID: req.tenant.id, action: action, @@ -490,7 +490,7 @@ export default class TagService { }, async (error: CSVError) => { // Release the lock await LockingManager.release(importTagsLock); - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportTags', action: action, @@ -562,7 +562,7 @@ export default class TagService { parser.on('error', async (error) => { // Release the lock await LockingManager.release(importTagsLock); - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportTags', action: action, @@ -580,7 +580,7 @@ export default class TagService { } else { // Release the lock await LockingManager.release(importTagsLock); - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportTags', action: action, @@ -629,7 +629,7 @@ export default class TagService { // Handle dup keys result.inSuccess += error.result.nInserted; result.inError += error.writeErrors.length; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'insertTags', action: action, @@ -663,7 +663,7 @@ export default class TagService { } } catch (error) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'deleteTags', action: ServerAction.TAG_DELETE, @@ -708,7 +708,7 @@ export default class TagService { } } catch (error) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'unassignTags', action: ServerAction.TAG_DELETE, @@ -833,7 +833,7 @@ export default class TagService { UserValidatorRest.getInstance().validateUserImportCreateReq(newImportedUser); tagToImport = { ...tagToImport, ...newImportedUser as ImportedTag }; } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'processTag', action: action, @@ -846,7 +846,7 @@ export default class TagService { tagsToBeImported.push(tagToImport); return true; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'importTag', action: action, @@ -875,7 +875,7 @@ export default class TagService { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndDeleteTagOCPI', action: ServerAction.TAG_DELETE, @@ -898,7 +898,7 @@ export default class TagService { ); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: action, module: MODULE_NAME, method: 'updateTagOCPI', diff --git a/src/server/rest/v1/service/TenantService.ts b/src/server/rest/v1/service/TenantService.ts index d3fe1b9ab9..523e2e43a8 100644 --- a/src/server/rest/v1/service/TenantService.ts +++ b/src/server/rest/v1/service/TenantService.ts @@ -65,7 +65,7 @@ export default class TenantService { // Remove collection await TenantStorage.deleteTenantDB(tenant.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteTenant', message: `Tenant '${tenant.name}' has been deleted successfully`, @@ -342,7 +342,7 @@ export default class TenantService { } ); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateTenant', message: `Tenant '${filteredRequest.name}' has been created successfully`, @@ -416,7 +416,7 @@ export default class TenantService { // Update with components await TenantService.updateSettingsWithComponents(filteredRequest, req); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateTenant', message: `Tenant '${filteredRequest.name}' has been updated successfully`, @@ -455,7 +455,7 @@ export default class TenantService { // Update Tenant await TenantStorage.saveTenant(tenant, Utils.objectHasProperty(filteredRequest, 'logo') ? true : false); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateTenantData', message: `Tenant '${filteredRequest.name}' data has been updated successfully`, diff --git a/src/server/rest/v1/service/TransactionService.ts b/src/server/rest/v1/service/TransactionService.ts index 7c975da756..82488f1429 100644 --- a/src/server/rest/v1/service/TransactionService.ts +++ b/src/server/rest/v1/service/TransactionService.ts @@ -196,7 +196,7 @@ export default class TransactionService { } // Save await TransactionStorage.saveTransactionOcpiData(req.tenant, transaction.id, transaction.ocpiData); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, action, module: MODULE_NAME, method: 'handlePushTransactionCdr', @@ -231,7 +231,7 @@ export default class TransactionService { } // Save await TransactionStorage.saveTransactionOicpData(req.tenant, transaction.id, transaction.oicpData); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, user: req.user, actionOnUser: (transaction.user ?? null), @@ -685,7 +685,7 @@ export default class TransactionService { // Transaction refunded if (refundConnector && !refundConnector.canBeDeleted(transaction)) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: loggedUser.tenantID, user: loggedUser, @@ -698,7 +698,7 @@ export default class TransactionService { // Transaction billed if (billingImpl && transaction.billingData?.stop?.status === BillingStatus.BILLED) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: loggedUser.tenantID, user: loggedUser, @@ -811,7 +811,7 @@ export default class TransactionService { OCPPUtils.clearChargingStationConnectorRuntimeData(chargingStation, transaction.connectorId); await ChargingStationStorage.saveChargingStationConnectors(req.tenant, chargingStation.id, chargingStation.connectors); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, user: req.user, actionOnUser: transaction.userID, @@ -833,7 +833,7 @@ export default class TransactionService { try { await new OCPPService(Configuration.getChargingStationConfig()).softStopTransaction( req.tenant, transaction, chargingStation, chargingStation.siteArea); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, user: req.user, actionOnUser: transaction.userID, diff --git a/src/server/rest/v1/service/UserService.ts b/src/server/rest/v1/service/UserService.ts index 298e332633..392ecf88f0 100644 --- a/src/server/rest/v1/service/UserService.ts +++ b/src/server/rest/v1/service/UserService.ts @@ -210,7 +210,7 @@ export default class UserService { } else { await UserStorage.removeSitesFromUser(req.tenant, filteredRequest.userID, sites.map((site) => site.id)); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, @@ -230,7 +230,7 @@ export default class UserService { if (!user.issuer) { // Delete User await UserStorage.deleteUser(req.tenant, user.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: user, module: MODULE_NAME, method: 'handleDeleteUser', @@ -250,7 +250,7 @@ export default class UserService { // Delete User await UserStorage.deleteUser(req.tenant, user.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: user, module: MODULE_NAME, method: 'handleDeleteUser', @@ -315,7 +315,7 @@ export default class UserService { // Update Billing await UserService.syncUserAndUpdateBillingData(ServerAction.USER_UPDATE, req.tenant, req.user, user); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: user, module: MODULE_NAME, method: 'handleUpdateUser', @@ -353,7 +353,7 @@ export default class UserService { mobileVersion: filteredRequest.mobileVersion, mobileLastChangedOn: new Date() }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: user, module: MODULE_NAME, method: 'handleUpdateUserMobileData', @@ -573,7 +573,7 @@ export default class UserService { // Release the lock await LockingManager.release(importUsersLock); // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportUsers', action: action, @@ -648,7 +648,7 @@ export default class UserService { // Release the lock await LockingManager.release(importUsersLock); // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportUsers', action: action, @@ -667,7 +667,7 @@ export default class UserService { // Release the lock await LockingManager.release(importUsersLock); // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportUsers', action: action, @@ -735,7 +735,7 @@ export default class UserService { // Update Billing await UserService.syncUserAndUpdateBillingData(ServerAction.USER_CREATE, req.tenant, req.user, newUser); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: req.user, module: MODULE_NAME, method: 'handleCreateUser', @@ -754,7 +754,7 @@ export default class UserService { // Handle dup keys result.inSuccess += error.result.nInserted; result.inError += error.writeErrors.length; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'insertUsers', action: action, @@ -871,7 +871,7 @@ export default class UserService { usersToBeImported.push(newImportedUser); return true; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'importUser', action: action, @@ -892,7 +892,7 @@ export default class UserService { ...await billingImpl.precheckStartTransactionPrerequisites(user)); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'checkBillingErrorCodes', @@ -959,7 +959,7 @@ export default class UserService { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndDeleteUserOCPI', @@ -1000,7 +1000,7 @@ export default class UserService { // For performance reasons, the creation of a customer in the billing system should be done in a LAZY mode await billingImpl.synchronizeUser(user); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action, module: MODULE_NAME, method: 'syncUserAndUpdateBillingData', user: loggedUser, actionOnUser: user, diff --git a/src/server/rest/v1/service/UtilsService.ts b/src/server/rest/v1/service/UtilsService.ts index de6fcbbf88..e1ea01c8a3 100644 --- a/src/server/rest/v1/service/UtilsService.ts +++ b/src/server/rest/v1/service/UtilsService.ts @@ -104,7 +104,7 @@ export default class UtilsService { message: `The Captcha score is too low, got ${response.data.score as string} but expected ${centralSystemRestConfig.captchaScore}`, }); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant?.id, module: MODULE_NAME, action, method, message: `The Captcha score is ${response.data.score as string} (score limit is ${centralSystemRestConfig.captchaScore})`, diff --git a/src/start.ts b/src/start.ts index a1c386e56c..69251ac8f9 100644 --- a/src/start.ts +++ b/src/start.ts @@ -105,7 +105,7 @@ export default class Bootstrap { } else { const message = `Monitoring Server implementation does not exist '${this.monitoringConfig.implementation}'`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.STARTUP, module: MODULE_NAME, method: 'startServers', message @@ -142,7 +142,6 @@ export default class Bootstrap { } - // ------------------------------------------------------------------------- // Start all the Servers // ------------------------------------------------------------------------- @@ -188,7 +187,7 @@ export default class Bootstrap { await this.logDuration(startTimeGlobalMillis, `${serverStarted.join(', ')} server has been started successfully`, ServerAction.BOOTSTRAP_STARTUP); } catch (error) { Logging.logConsoleError(error); - global.database && await Logging.logError({ + global.database && Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.BOOTSTRAP_STARTUP, module: MODULE_NAME, method: 'start', @@ -202,7 +201,7 @@ export default class Bootstrap { const timeStartMillis = Date.now(); Logging.logConsoleDebug(logMessage); if (global.database) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.STARTUP, module: MODULE_NAME, method: 'start', @@ -217,7 +216,7 @@ export default class Bootstrap { logMessage = `${logMessage} in ${timeDurationSecs} secs`; Logging.logConsoleDebug(logMessage); if (global.database) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action, module: MODULE_NAME, method: 'start', @@ -303,7 +302,7 @@ export default class Bootstrap { } } catch (error) { Logging.logConsoleError(error.stack); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.STARTUP, module: MODULE_NAME, method: 'startServers', diff --git a/src/storage/mongodb/MongoDBStorage.ts b/src/storage/mongodb/MongoDBStorage.ts index 3d48f3c559..6b6c46011e 100644 --- a/src/storage/mongodb/MongoDBStorage.ts +++ b/src/storage/mongodb/MongoDBStorage.ts @@ -71,7 +71,7 @@ export default class MongoDBStorage { const changeStream = dbCollection.watch([], { fullDocument: 'updateLookup' }); const message = `Database collection '${tenant.id}.${collectionName}' is being watched`; Utils.isDevelopmentEnv() && Logging.logConsoleDebug(message); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.MONGO_DB, message, module: MODULE_NAME, method: 'watchDatabaseCollection' @@ -96,7 +96,7 @@ export default class MongoDBStorage { action: ServerAction.MONGO_DB }); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenantID, action: ServerAction.MONGO_DB, message: 'Check of MongoDB database...', @@ -195,7 +195,7 @@ export default class MongoDBStorage { { fields: { deleted: 1, issuer: 1 } }, { fields: { 'connectors.status': 1 } }, ]); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenantID, action: ServerAction.MONGO_DB, message: 'Check of MongoDB database done', @@ -319,7 +319,7 @@ export default class MongoDBStorage { this.dbPingFailed++; const message = `${this.dbPingFailed} database ping(s) failed: ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'ping', @@ -393,7 +393,7 @@ export default class MongoDBStorage { } catch (error) { const message = 'Error while checking Database in tenant \'default\''; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -423,7 +423,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error while checking Database in tenant '${tenantId}'`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -458,7 +458,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error in creating collection '${tenantID}.${tenantCollectionName}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -491,7 +491,7 @@ export default class MongoDBStorage { if (Utils.isDevelopmentEnv()) { const message = `Drop index '${databaseIndex.name as string}' in collection ${tenantCollectionName}`; Utils.isDevelopmentEnv() && Logging.logConsoleDebug(message); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -503,7 +503,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error in dropping index '${databaseIndex.name as string}' in '${tenantCollectionName}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -522,7 +522,7 @@ export default class MongoDBStorage { if (Utils.isDevelopmentEnv()) { const message = `Create index ${JSON.stringify(index)} in collection ${tenantCollectionName}`; Utils.isDevelopmentEnv() && Logging.logConsoleDebug(message); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -534,7 +534,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error in creating index '${JSON.stringify(index.fields)}' with options '${JSON.stringify(index.options)}' in '${tenantCollectionName}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -547,7 +547,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Unexpected error in handling Collection '${tenantID}.${name}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', diff --git a/src/storage/mongodb/SiteAreaStorage.ts b/src/storage/mongodb/SiteAreaStorage.ts index 930e156ec6..809b339f46 100644 --- a/src/storage/mongodb/SiteAreaStorage.ts +++ b/src/storage/mongodb/SiteAreaStorage.ts @@ -131,7 +131,7 @@ export default class SiteAreaStorage { }, Constants.DB_PARAMS_SINGLE_RECORD, projectFields); // No unique key on OCPI Location (avoid create several Site Area with the same location ID) if (siteAreaMDB.count > 1) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.UNKNOWN_ACTION, module: MODULE_NAME, method: 'getSiteAreaByOcpiLocationUid', diff --git a/src/storage/mongodb/TagStorage.ts b/src/storage/mongodb/TagStorage.ts index 9c456c41f6..33cae324a0 100644 --- a/src/storage/mongodb/TagStorage.ts +++ b/src/storage/mongodb/TagStorage.ts @@ -24,7 +24,7 @@ export default class TagStorage { const id = Utils.generateTagID(); existingTag = await TagStorage.getTag(tenant, id); if (existingTag) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'findAvailableID', action: ServerAction.TAG_CREATE, diff --git a/src/storage/mongodb/TransactionStorage.ts b/src/storage/mongodb/TransactionStorage.ts index 22d222f2e0..5b9ffdb10f 100644 --- a/src/storage/mongodb/TransactionStorage.ts +++ b/src/storage/mongodb/TransactionStorage.ts @@ -1223,7 +1223,7 @@ export default class TransactionStorage { const id = Utils.getRandomIntSafe(); existingTransaction = await TransactionStorage.getTransaction(tenant, id); if (existingTransaction) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'findAvailableID', action: ServerAction.TRANSACTION_STARTED, diff --git a/src/utils/Logging.ts b/src/utils/Logging.ts index 68749efea3..e2cd6e2375 100644 --- a/src/utils/Logging.ts +++ b/src/utils/Logging.ts @@ -87,6 +87,14 @@ export default class Logging { if (Logging.isLevelEnabled(expectedLogLevel)) { return new LightLogger(expectedLogLevel); } + // ------------------------------------------------------------------------------ + // ACHTUNG - returns null when the level is disabled + // ------------------------------------------------------------------------------ + // The purpose here is to avoid evaluating the log parameters and thus + // avoid triggering unnecessary garbage collection of log messages + // Make sure to use optional chaining operator (?.) when calling the log method + // ------------------------------------------------------------------------------ + return null; } public static getConfiguration(): LogConfiguration { diff --git a/test/api/SecurityTest.ts b/test/api/SecurityTest.ts index 70bd70403e..37c4e8b4f5 100644 --- a/test/api/SecurityTest.ts +++ b/test/api/SecurityTest.ts @@ -108,7 +108,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing "=") is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -124,7 +124,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing ":") is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -140,7 +140,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing ",") is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -156,7 +156,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing ";") is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -172,7 +172,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and =) is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -188,7 +188,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and :) is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -204,7 +204,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and ,) is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -220,7 +220,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and ;) is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -236,7 +236,7 @@ describe('Security', () => { it( 'Check that sensitive data string matching a ws url with registration token is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -250,7 +250,7 @@ describe('Security', () => { } ); it('Check that sensitive data query string is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -263,7 +263,7 @@ describe('Security', () => { checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages)); }); it('Check that client_id field is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -276,7 +276,7 @@ describe('Security', () => { checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages)); }); it('Check that client_secret field is anonymized', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -291,7 +291,7 @@ describe('Security', () => { it( 'Check that client_id and client_secret are anonymized in object', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -310,7 +310,7 @@ describe('Security', () => { it( 'Check that sensitive data is anonymized in object with string fields', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -344,7 +344,7 @@ describe('Security', () => { it( 'Check that sensitive data is anonymized in object with query string fields', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -365,7 +365,7 @@ describe('Security', () => { it( 'Check that sensitive data is anonymized in array with strings', async () => { - const logId: string = await Logging.logDebug({ + const logId: string = Logging.beDebug()?.log({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', From 57f1f10dc3ba38d5cfa215d7ccdc32b7c58c612f Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Thu, 22 Dec 2022 10:09:47 +0100 Subject: [PATCH 03/11] logger - perf improvements --- src/async-task/AsyncTaskBuilder.ts | 2 +- src/async-task/AsyncTaskManager.ts | 14 ++-- src/async-task/TenantAsyncTask.ts | 16 ++--- src/async-task/tasks/ImportHelper.ts | 2 +- src/async-task/tasks/TagsImportAsyncTask.ts | 6 +- src/async-task/tasks/UsersImportAsyncTask.ts | 6 +- src/authorization/Authorizations.ts | 2 +- src/bootstrap/LocalCarCatalogBootstrap.ts | 6 +- src/client/ocpi/CpoOCPIClient.ts | 32 ++++----- src/client/ocpi/EmspOCPIClient.ts | 10 +-- src/client/ocpi/OCPIClient.ts | 10 +-- src/client/ocpi/OCPIClientFactory.ts | 8 +-- .../json/JsonRestChargingStationClient.ts | 12 ++-- .../ocpp/soap/SoapChargingStationClient.ts | 16 ++--- src/client/oicp/CpoOICPClient.ts | 42 ++++++------ src/client/oicp/OICPClientFactory.ts | 4 +- src/integration/asset/AssetFactory.ts | 2 +- .../greencom/GreencomAssetIntegration.ts | 2 +- .../asset/iothink/IothinkAssetIntegration.ts | 2 +- .../asset/lacroix/LacroixAssetIntegration.ts | 2 +- .../schneider/SchneiderAssetIntegration.ts | 2 +- .../asset/wit/WitAssetIntegration.ts | 2 +- .../MercedesCarConnectorIntegration.ts | 8 +-- .../TargaTelematicsConnector.ts | 2 +- .../TronityCarConnectorIntegration.ts | 4 +- src/integration/car/CarIntegration.ts | 6 +- .../ev-database/EVDatabaseCarIntegration.ts | 6 +- .../ChargingStationVendorIntegration.ts | 30 ++++----- src/integration/pricing/PricingEngine.ts | 8 +-- .../BuiltInPricingIntegration.ts | 8 +-- src/integration/refund/RefundFactory.ts | 2 +- .../sap-concur/SapConcurRefundIntegration.ts | 20 +++--- .../SmartChargingIntegration.ts | 6 +- .../SapSmartChargingIntegration.ts | 20 +++--- src/locking/LockingManager.ts | 14 ++-- src/migration/MigrationHandler.ts | 12 ++-- src/migration/TenantMigrationTask.ts | 6 +- .../AddCompanyIDToChargingStationsTask.ts | 2 +- .../tasks/AddCompanyIDToTransactionsTask.ts | 2 +- ...elTemplateToChargingStationTemplateTask.ts | 4 +- src/migration/tasks/AddUserIDToCarsTask.ts | 2 +- .../AlignEntitiesWithOrganizationIDsTask.ts | 4 +- src/migration/tasks/MigrateSimplePricing.ts | 2 +- .../tasks/RemoveDuplicateTagVisualIDsTask.ts | 2 +- .../tasks/RepairInvoiceInconsistencies.ts | 10 +-- .../tasks/RepairTransactionBillingData.ts | 10 +-- .../RepairTransactionPricedAtZeroTask.ts | 6 +- .../RestoreDataIntegrityInSiteUsersTask.ts | 2 +- .../tasks/UpdateEmailsToLowercaseTask.ts | 2 +- src/notification/NotificationHandler.ts | 44 ++++++------- .../email/EMailNotificationTask.ts | 12 ++-- .../RemotePushNotificationTask.ts | 2 +- src/scheduler/SchedulerManager.ts | 8 +-- src/scheduler/SchedulerTask.ts | 6 +- src/scheduler/TenantSchedulerTask.ts | 16 ++--- .../tasks/BillPendingTransactionTask.ts | 14 ++-- .../tasks/CheckAndComputeSmartChargingTask.ts | 6 +- .../tasks/CheckChargingStationTemplateTask.ts | 6 +- .../tasks/CheckOfflineChargingStationsTask.ts | 2 +- .../tasks/CloseTransactionsInProgressTask.ts | 4 +- .../tasks/LoggingDatabaseTableCleanupTask.ts | 8 +-- .../SynchronizeRefundTransactionsTask.ts | 10 +-- src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts | 8 +-- .../tasks/ocpi/OCPICheckLocationsTask.ts | 8 +-- .../tasks/ocpi/OCPICheckSessionsTask.ts | 8 +-- src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts | 8 +-- .../tasks/ocpi/OCPIPullLocationsTask.ts | 8 +-- .../tasks/ocpi/OCPIPullSessionsTask.ts | 8 +-- .../tasks/ocpi/OCPIPullTokensTask.ts | 8 +-- src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts | 14 ++-- .../tasks/ocpi/OCPIPushEVSEStatusesTask.ts | 8 +-- .../tasks/ocpi/OCPIPushTokensTask.ts | 8 +-- .../tasks/oicp/OICPPushEvseDataTask.ts | 8 +-- .../tasks/oicp/OICPPushEvseStatusTask.ts | 8 +-- src/server/ServerUtils.ts | 2 +- src/server/ocpi/OCPIFacade.ts | 4 +- src/server/ocpi/OCPIUtils.ts | 6 +- src/server/ocpi/service/OCPIUtilsService.ts | 6 +- .../v2.1.1/CPOEMSPCredentialsService.ts | 16 ++--- .../service/cpo/v2.1.1/CPOCommandsService.ts | 32 ++++----- .../emsp/v2.1.1/EMSPCommandsService.ts | 4 +- src/server/ocpp/json/JsonOCPPServer.ts | 64 +++++++++--------- .../ocpp/json/web-socket/WSConnection.ts | 2 +- src/server/ocpp/services/OCPPService.ts | 66 +++++++++---------- src/server/ocpp/soap/SoapOCPPServer.ts | 4 +- src/server/ocpp/utils/OCPPCommon.ts | 12 ++-- src/server/ocpp/utils/OCPPUtils.ts | 62 ++++++++--------- src/server/ocpp/validator/OCPPValidator.ts | 6 +- src/server/odata/ODataRestAdapter.ts | 2 +- src/server/odata/odata-schema/ODataSchema.ts | 2 +- src/server/oicp/AbstractOICPService.ts | 8 +-- src/server/oicp/OICPFacade.ts | 4 +- .../CPORemoteAuthorizationsEndpoint.ts | 22 +++---- src/server/rest/RestServerService.ts | 4 +- src/server/rest/v1/service/AssetService.ts | 8 +-- src/server/rest/v1/service/AuthService.ts | 14 ++-- src/server/rest/v1/service/BillingService.ts | 8 +-- src/server/rest/v1/service/CarService.ts | 6 +- .../rest/v1/service/ChargingStationService.ts | 20 +++--- .../service/ChargingStationTemplateService.ts | 6 +- src/server/rest/v1/service/CompanyService.ts | 6 +- .../rest/v1/service/ConnectionService.ts | 4 +- .../rest/v1/service/OCPIEndpointService.ts | 16 ++--- .../rest/v1/service/OICPEndpointService.ts | 18 ++--- src/server/rest/v1/service/PricingService.ts | 8 +-- .../v1/service/RegistrationTokenService.ts | 8 +-- src/server/rest/v1/service/SettingService.ts | 6 +- src/server/rest/v1/service/SiteAreaService.ts | 12 ++-- src/server/rest/v1/service/SiteService.ts | 12 ++-- src/server/rest/v1/service/TagService.ts | 28 ++++---- src/server/rest/v1/service/TenantService.ts | 8 +-- .../rest/v1/service/TransactionService.ts | 12 ++-- src/server/rest/v1/service/UserService.ts | 28 ++++---- src/server/rest/v1/service/UtilsService.ts | 2 +- src/start.ts | 11 ++-- src/storage/mongodb/MongoDBStorage.ts | 24 +++---- src/storage/mongodb/SiteAreaStorage.ts | 2 +- src/storage/mongodb/TagStorage.ts | 2 +- src/storage/mongodb/TransactionStorage.ts | 2 +- src/utils/Logging.ts | 8 +++ 120 files changed, 627 insertions(+), 620 deletions(-) diff --git a/src/async-task/AsyncTaskBuilder.ts b/src/async-task/AsyncTaskBuilder.ts index c8adac2703..d81d1854a0 100644 --- a/src/async-task/AsyncTaskBuilder.ts +++ b/src/async-task/AsyncTaskBuilder.ts @@ -25,7 +25,7 @@ export default class AsyncTaskBuilder { // Save await AsyncTaskStorage.saveAsyncTask(asyncTask as AsyncTask); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'createAndSaveAsyncTasks', diff --git a/src/async-task/AsyncTaskManager.ts b/src/async-task/AsyncTaskManager.ts index b67835e7a9..5d9dba6d0c 100644 --- a/src/async-task/AsyncTaskManager.ts +++ b/src/async-task/AsyncTaskManager.ts @@ -54,7 +54,7 @@ export default class AsyncTaskManager { public static async handleAsyncTasks(): Promise { let failedToAcquireLock = false; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -75,7 +75,7 @@ export default class AsyncTaskManager { { status: AsyncTaskStatus.PENDING }, Constants.DB_PARAMS_MAX_LIMIT); // Process them if (!Utils.isEmptyArray(asyncTasks.result)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -98,7 +98,7 @@ export default class AsyncTaskManager { asyncTask.lastChangedOn = asyncTask.execTimestamp; await AsyncTaskStorage.saveAsyncTask(asyncTask); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -115,7 +115,7 @@ export default class AsyncTaskManager { await AsyncTaskStorage.saveAsyncTask(asyncTask); processedTask.inSuccess++; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -130,7 +130,7 @@ export default class AsyncTaskManager { asyncTask.lastChangedOn = new Date(); await AsyncTaskStorage.saveAsyncTask(asyncTask); // Log error - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'handleAsyncTasks', action: ServerAction.ASYNC_TASK, @@ -162,7 +162,7 @@ export default class AsyncTaskManager { void AsyncTaskManager.handleAsyncTasks(); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', @@ -201,7 +201,7 @@ export default class AsyncTaskManager { case AsyncTasks.OCPI_PUSH_EVSE_STATUSES: return new OCPIPushEVSEStatusesAsyncTask(asyncTask, correlationID); default: - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'handleAsyncTasks', diff --git a/src/async-task/TenantAsyncTask.ts b/src/async-task/TenantAsyncTask.ts index 913d6a30dd..86c219155a 100644 --- a/src/async-task/TenantAsyncTask.ts +++ b/src/async-task/TenantAsyncTask.ts @@ -23,7 +23,7 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { (taskSettings.task.disableAllTasks || !Utils.isEmptyArray(taskSettings.task.disableTasksInEnv) && taskSettings.task.disableTasksInEnv.includes(currentTaskEnv))) { // Tasks are disabled for this environment isTaskExecutionDisabled = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -43,7 +43,7 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { } // Check if tenant task needs to run on a specific env if (tenant.taskExecutionEnv && tenant.taskExecutionEnv !== currentTaskEnv) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -54,13 +54,13 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { } const tenantCorrelationID = Utils.generateShortNonUniqueID(); const startTimeInTenant = moment(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', message: `The Task '${this.getAsyncTask().name}~${this.getCorrelationID()}~${tenantCorrelationID}' is running for Tenant ${Utils.buildTenantName(tenant)}...` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -74,14 +74,14 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { // Hook await this.afterExecuteTenantAsyncTask(tenant); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', message: `Error while running the Task '${this.getAsyncTask().name}~${this.getCorrelationID()}~${tenantCorrelationID}' for Tenant ${Utils.buildTenantName(tenant)}: ${error.message as string}`, detailedMessages: { error: error.stack } }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', @@ -91,13 +91,13 @@ export default abstract class TenantAsyncTask extends AbstractAsyncTask { } // Log Total Processing Time in Tenant const totalTimeSecsInTenant = moment.duration(moment().diff(startTimeInTenant)).asSeconds(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', message: `The Task '${this.getAsyncTask().name}~${this.getCorrelationID()}~${tenantCorrelationID}' has been run successfully in ${totalTimeSecsInTenant} secs for Tenant ${Utils.buildTenantName(tenant)}` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.ASYNC_TASK, module: MODULE_NAME, method: 'executeAsyncTask', diff --git a/src/async-task/tasks/ImportHelper.ts b/src/async-task/tasks/ImportHelper.ts index e0883efc8f..661d039772 100644 --- a/src/async-task/tasks/ImportHelper.ts +++ b/src/async-task/tasks/ImportHelper.ts @@ -140,7 +140,7 @@ export default class ImportHelper { await UserStorage.addSiteToUser(tenant, user.id, importedSiteID); } else { // Site does not exist - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'executeAsyncTask', diff --git a/src/async-task/tasks/TagsImportAsyncTask.ts b/src/async-task/tasks/TagsImportAsyncTask.ts index 550912d519..d4f41cfcb2 100644 --- a/src/async-task/tasks/TagsImportAsyncTask.ts +++ b/src/async-task/tasks/TagsImportAsyncTask.ts @@ -43,7 +43,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { // Get total number of Tags to import const totalTagsToImport = await TagStorage.getImportedTagsCount(tenant); if (totalTagsToImport > 0) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.TAGS_IMPORT, module: MODULE_NAME, method: 'processTenant', @@ -66,7 +66,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { importedTag.errorDescription = error.message; result.inError++; await TagStorage.saveImportedTag(tenant, importedTag); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.TAGS_IMPORT, module: MODULE_NAME, method: 'processTenant', @@ -77,7 +77,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { } if (!Utils.isEmptyArray(importedTags.result) && (result.inError + result.inSuccess) > 0) { const intermediateDurationSecs = Math.round((new Date().getTime() - startTime) / 1000); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.TAGS_IMPORT, module: MODULE_NAME, method: 'processTenant', diff --git a/src/async-task/tasks/UsersImportAsyncTask.ts b/src/async-task/tasks/UsersImportAsyncTask.ts index 400351c935..000411d703 100644 --- a/src/async-task/tasks/UsersImportAsyncTask.ts +++ b/src/async-task/tasks/UsersImportAsyncTask.ts @@ -42,7 +42,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { // Get total number of Users to import const totalUsersToImport = await UserStorage.getImportedUsersCount(tenant); if (totalUsersToImport > 0) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'processTenant', @@ -66,7 +66,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { result.inError++; // Update it await UserStorage.saveImportedUser(tenant, importedUser); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'executeAsyncTask', @@ -77,7 +77,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { } if (importedUsers.result.length > 0 && (result.inError + result.inSuccess) > 0) { const intermediateDurationSecs = Math.round((new Date().getTime() - startTime) / 1000); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.USERS_IMPORT, module: MODULE_NAME, method: 'processTenant', diff --git a/src/authorization/Authorizations.ts b/src/authorization/Authorizations.ts index 76b5a03f2d..c80c39492b 100644 --- a/src/authorization/Authorizations.ts +++ b/src/authorization/Authorizations.ts @@ -946,7 +946,7 @@ export default class Authorizations { if (remoteAuthorization && OCPIUtils.isAuthorizationValid(remoteAuthorization.timestamp)) { // Check Tag ID if (remoteAuthorization.tagId === tag.ocpiToken?.uid) { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, message: `${Utils.buildConnectorInfo(connector.connectorId, transaction?.id)} Valid Remote Authorization found for Tag ID '${tag.ocpiToken.uid}'`, diff --git a/src/bootstrap/LocalCarCatalogBootstrap.ts b/src/bootstrap/LocalCarCatalogBootstrap.ts index ff4c2f1d77..87daede0d1 100644 --- a/src/bootstrap/LocalCarCatalogBootstrap.ts +++ b/src/bootstrap/LocalCarCatalogBootstrap.ts @@ -54,7 +54,7 @@ export default class LocalCarCatalogBootstrap { created++; } catch (error) { const message = `Error while importing the local Car ID '${carCatalog.id}': ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile', @@ -66,7 +66,7 @@ export default class LocalCarCatalogBootstrap { } } catch (error) { const message = `Error while importing the local Cars: ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile', @@ -77,7 +77,7 @@ export default class LocalCarCatalogBootstrap { // Log in the default tenant if (created > 0) { const message = `${created} local Car(s) catalog created in the default tenant`; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.UPDATE_LOCAL_CAR_CATALOGS, message, module: MODULE_NAME, method: 'uploadLocalCarCatalogsFromFile', diff --git a/src/client/ocpi/CpoOCPIClient.ts b/src/client/ocpi/CpoOCPIClient.ts index 13fa38b693..b71cf35e72 100644 --- a/src/client/ocpi/CpoOCPIClient.ts +++ b/src/client/ocpi/CpoOCPIClient.ts @@ -117,7 +117,7 @@ export default class CpoOCPIClient extends OCPIClient { } const numberOfTags = response.data.data.length as number; totalNumberOfTags += numberOfTags; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_GET_TOKENS, message: `${numberOfTags.toString()} Tokens retrieved from ${tokensUrl}`, @@ -162,7 +162,7 @@ export default class CpoOCPIClient extends OCPIClient { } const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_GET_TOKENS, message: `${numberOfTags.toString()} token(s) processed in ${executionDurationLoopSecs}s - Total of ${totalNumberOfTags} token(s) processed in ${executionDurationTotalLoopSecs}s`, @@ -239,7 +239,7 @@ export default class CpoOCPIClient extends OCPIClient { detailedMessages: { locationReference, authorizationInfo } }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_AUTHORIZE_TOKEN, @@ -284,7 +284,7 @@ export default class CpoOCPIClient extends OCPIClient { transaction.ocpiData = { session: ocpiSession }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_START_SESSION, @@ -330,7 +330,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_PUSH_SESSIONS, @@ -375,7 +375,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_STOP_SESSION, @@ -441,7 +441,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, @@ -451,7 +451,7 @@ export default class CpoOCPIClient extends OCPIClient { }); return true; } - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, @@ -758,7 +758,7 @@ export default class CpoOCPIClient extends OCPIClient { { concurrency: Constants.OCPI_MAX_PARALLEL_REQUESTS }); const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_UPDATE_STATUS, message: `${evses.length} EVSE Status(es) processed in ${executionDurationLoopSecs}s in Location '${location.name}' - Total of ${totalNumberOfEvses} EVSE(s) processed in ${executionDurationTotalLoopSecs}s`, @@ -862,7 +862,7 @@ export default class CpoOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation as ChargingStation), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_UPDATE_STATUS, @@ -896,7 +896,7 @@ export default class CpoOCPIClient extends OCPIClient { }); // Create if it does not exit if (response.data.status_code === 3001) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -918,7 +918,7 @@ export default class CpoOCPIClient extends OCPIClient { const cdr = response.data.data as OCPICdr; if (cdr) { // CDR checked - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -929,7 +929,7 @@ export default class CpoOCPIClient extends OCPIClient { return true; } } - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -964,7 +964,7 @@ export default class CpoOCPIClient extends OCPIClient { if (OCPIUtilsService.isSuccessResponse(response.data)) { const session = response.data.data as OCPISession; if (session) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -975,7 +975,7 @@ export default class CpoOCPIClient extends OCPIClient { return true; } } - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -1020,7 +1020,7 @@ export default class CpoOCPIClient extends OCPIClient { detailedMessages: { location, ocpiLocation } }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_CHECK_LOCATIONS, message: `Location '${location.name}' with ID '${location.id}' checked successfully`, diff --git a/src/client/ocpi/EmspOCPIClient.ts b/src/client/ocpi/EmspOCPIClient.ts index 78f9e02cd8..b93a19490f 100644 --- a/src/client/ocpi/EmspOCPIClient.ts +++ b/src/client/ocpi/EmspOCPIClient.ts @@ -99,7 +99,7 @@ export default class EmspOCPIClient extends OCPIClient { currentSkip += Constants.DB_RECORD_COUNT_DEFAULT; const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, message: `${tokens.count.toString()} token(s) pushed in ${executionDurationLoopSecs}s - Total of ${totalNumberOfTokens} token(s) pushed in ${executionDurationTotalLoopSecs}s`, @@ -188,7 +188,7 @@ export default class EmspOCPIClient extends OCPIClient { } const numberOfLocations = response.data.data.length as number; totalNumberOfLocations += numberOfLocations; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CPO_GET_TOKENS, message: `${numberOfLocations.toString()} Tokens retrieved from ${locationsUrl}`, @@ -237,7 +237,7 @@ export default class EmspOCPIClient extends OCPIClient { } const executionDurationLoopSecs = (new Date().getTime() - startTimeLoop) / 1000; const executionDurationTotalLoopSecs = (new Date().getTime() - startTime) / 1000; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, message: `${numberOfLocations.toString()} location(s) processed in ${executionDurationLoopSecs}s - Total of ${totalNumberOfLocations} location(s) processed in ${executionDurationTotalLoopSecs}s`, @@ -471,7 +471,7 @@ export default class EmspOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, ...LoggingHelper.getChargingStationProperties(chargingStation), action: ServerAction.OCPI_EMSP_START_SESSION, @@ -527,7 +527,7 @@ export default class EmspOCPIClient extends OCPIClient { 'Content-Type': 'application/json' }, }); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OCPI_EMSP_STOP_SESSION, diff --git a/src/client/ocpi/OCPIClient.ts b/src/client/ocpi/OCPIClient.ts index 72eb7387f2..5e36abb9c2 100644 --- a/src/client/ocpi/OCPIClient.ts +++ b/src/client/ocpi/OCPIClient.ts @@ -169,7 +169,7 @@ export default abstract class OCPIClient { } public async getVersions(): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_GET_VERSIONS, message: `Get OCPI Versions at ${this.ocpiEndpoint.baseUrl}`, @@ -188,7 +188,7 @@ export default abstract class OCPIClient { } public async getEndpointVersions(): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_GET_ENDPOINT_VERSIONS, message: `Get OCPI Services at ${this.ocpiEndpoint.versionUrl}`, @@ -267,7 +267,7 @@ export default abstract class OCPIClient { private async deleteCredentials(): Promise { // Get credentials url const credentialsUrl = this.getEndpointUrl('credentials', ServerAction.OCPI_CREATE_CREDENTIALS); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CREATE_CREDENTIALS, message: `Delete Credentials at ${credentialsUrl}`, @@ -288,7 +288,7 @@ export default abstract class OCPIClient { // Get credentials url const credentialsUrl = this.getEndpointUrl('credentials', ServerAction.OCPI_CREATE_CREDENTIALS); const credentials = await OCPIUtils.buildOcpiCredentialObject(this.tenant, this.ocpiEndpoint.localToken, this.ocpiEndpoint.role); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_CREATE_CREDENTIALS, message: `Post Credentials at ${credentialsUrl}`, @@ -310,7 +310,7 @@ export default abstract class OCPIClient { // Get credentials url const credentialsUrl = this.getEndpointUrl('credentials', ServerAction.OCPI_UPDATE_CREDENTIALS); const credentials = await OCPIUtils.buildOcpiCredentialObject(this.tenant, this.ocpiEndpoint.localToken, this.ocpiEndpoint.role); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OCPI_UPDATE_CREDENTIALS, message: `Put Credentials at ${credentialsUrl}`, diff --git a/src/client/ocpi/OCPIClientFactory.ts b/src/client/ocpi/OCPIClientFactory.ts index 37084e7fc4..f2fabab363 100644 --- a/src/client/ocpi/OCPIClientFactory.ts +++ b/src/client/ocpi/OCPIClientFactory.ts @@ -22,7 +22,7 @@ export default class OCPIClientFactory { if (Utils.isTenantComponentActive(tenant, TenantComponents.OCPI)) { const ocpiSettings = await SettingStorage.getOCPISettings(tenant); if (!ocpiSettings && ocpiSettings.ocpi) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_SETTINGS, module: MODULE_NAME, method: 'getOcpiClient', @@ -37,7 +37,7 @@ export default class OCPIClientFactory { return new EmspOCPIClient(tenant, ocpiSettings.ocpi, ocpiEndpoint); } } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_SETTINGS, module: MODULE_NAME, method: 'getOcpiClient', @@ -52,7 +52,7 @@ export default class OCPIClientFactory { const client = await OCPIClientFactory.getOcpiClient(tenant, ocpiEndpoint); return client as CpoOCPIClient; } - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CLIENT_INITIALIZATION, module: MODULE_NAME, method: 'getCpoOcpiClient', @@ -65,7 +65,7 @@ export default class OCPIClientFactory { const client = await OCPIClientFactory.getOcpiClient(tenant, ocpiEndpoint); return client as EmspOCPIClient; } - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CLIENT_INITIALIZATION, module: MODULE_NAME, method: 'getEmspOcpiClient', diff --git a/src/client/ocpp/json/JsonRestChargingStationClient.ts b/src/client/ocpp/json/JsonRestChargingStationClient.ts index 8e7cc9728b..58fcce968b 100644 --- a/src/client/ocpp/json/JsonRestChargingStationClient.ts +++ b/src/client/ocpp/json/JsonRestChargingStationClient.ts @@ -119,7 +119,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Extract Current Command const triggeringCommand: Command = request[2]; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -145,7 +145,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Opened // eslint-disable-next-line @typescript-eslint/no-misused-promises this.wsConnection.onopen = async () => { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -161,7 +161,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Closed // eslint-disable-next-line @typescript-eslint/no-misused-promises this.wsConnection.onclose = async (code: number) => { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -176,7 +176,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Handle Error Message // eslint-disable-next-line @typescript-eslint/no-misused-promises this.wsConnection.onerror = async (error: Error) => { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -202,7 +202,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Check message type if (messageType === OCPPMessageType.CALL_ERROR_MESSAGE) { // Error message - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, @@ -224,7 +224,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient this.closeConnection(); } else { // Error message - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, diff --git a/src/client/ocpp/soap/SoapChargingStationClient.ts b/src/client/ocpp/soap/SoapChargingStationClient.ts index 73610caff9..d6437c9c2a 100644 --- a/src/client/ocpp/soap/SoapChargingStationClient.ts +++ b/src/client/ocpp/soap/SoapChargingStationClient.ts @@ -56,7 +56,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { // Create SOAP client soap.createClient(chargingStationWdsl, options, async (error, client) => { if (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: scsc.tenant.id, action: ServerAction.CHARGING_STATION_CLIENT_INITIALIZATION, siteID: scsc.chargingStation.siteID, @@ -96,7 +96,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { 'remoteStopTransactionRequest': params }); if (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_REMOTE_STOP_TRANSACTION, siteID: this.chargingStation.siteID, @@ -135,7 +135,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { const { error, result, envelope } = await this.client.RemoteStartTransaction(params); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_REMOTE_START_TRANSACTION, siteID: this.chargingStation.siteID, @@ -175,7 +175,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_UNLOCK_CONNECTOR, siteID: this.chargingStation.siteID, @@ -215,7 +215,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_RESET, siteID: this.chargingStation.siteID, @@ -253,7 +253,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { const { error, result, envelope } = await this.client.ClearCache({ clearCacheRequest: {} }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_CLEAR_CACHE, siteID: this.chargingStation.siteID, @@ -300,7 +300,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { const { error, result, envelope } = await this.client.GetConfiguration(request); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.CHARGING_STATION_GET_CONFIGURATION, siteID: this.chargingStation.siteID, @@ -344,7 +344,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { }); if (error) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, siteID: this.chargingStation.siteID, siteAreaID: this.chargingStation.siteAreaID, diff --git a/src/client/oicp/CpoOICPClient.ts b/src/client/oicp/CpoOICPClient.ts index 3a66039025..3c3c4b75e6 100644 --- a/src/client/oicp/CpoOICPClient.ts +++ b/src/client/oicp/CpoOICPClient.ts @@ -80,7 +80,7 @@ export default class CpoOICPClient extends OICPClient { transaction.oicpData = { session: oicpSession }; - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_SESSIONS, @@ -159,7 +159,7 @@ export default class CpoOICPClient extends OICPClient { // Stop if (transaction.tagID !== OICPDefaultTagId.RemoteIdentification) { const response = await this.authorizeStop(transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_SESSIONS, @@ -529,7 +529,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_DATA, message: `${evses.length} EVSEs have been pushed successfully`, @@ -571,7 +571,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!pushEvseStatusResponse?.Result || pushEvseStatusResponse?.Result !== true) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_STATUSES, message: this.buildOICPChargingNotificationErrorMessage(pushEvseStatusResponse, requestError), @@ -583,7 +583,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_STATUSES, message: `${evseStatuses.length} EVSE Statuses have been pushed successfully`, @@ -628,7 +628,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (requestError) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_AUTHORIZE_START, message: this.buildOICPChargingNotificationErrorMessage(authorizeResponse, requestError), @@ -641,7 +641,7 @@ export default class CpoOICPClient extends OICPClient { }); } if (authorizeResponse?.AuthorizationStatus !== OICPAuthorizationStatus.Authorized) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_AUTHORIZE_START, module: MODULE_NAME, method: 'authorizeStart', @@ -649,7 +649,7 @@ export default class CpoOICPClient extends OICPClient { detailedMessages: { authorize: payload, response: authorizeResponse } }); } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_AUTHORIZE_START, message: `OICP Tag ID '${tagID}' has been authorized`, @@ -694,7 +694,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (requestError) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: user, @@ -709,7 +709,7 @@ export default class CpoOICPClient extends OICPClient { }); } if (authorizeResponse?.AuthorizationStatus !== OICPAuthorizationStatus.Authorized) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: user, @@ -719,7 +719,7 @@ export default class CpoOICPClient extends OICPClient { detailedMessages: { authorize: payload, response: authorizeResponse } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, user: user, @@ -800,7 +800,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!pushCdrResponse?.Result || pushCdrResponse?.Result !== true) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_CDRS, @@ -813,7 +813,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_CDRS, @@ -871,7 +871,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!notificationStartResponse?.Result || notificationStartResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_START, @@ -884,7 +884,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_START, @@ -946,7 +946,7 @@ export default class CpoOICPClient extends OICPClient { } transaction.oicpData.session.last_progress_notification = new Date(); if (!notificationProgressResponse?.Result || notificationProgressResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_PROGRESS, @@ -959,7 +959,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_PROGRESS, @@ -1034,7 +1034,7 @@ export default class CpoOICPClient extends OICPClient { requestError = error; } if (!notificationEndResponse?.Result || notificationEndResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_END, @@ -1047,7 +1047,7 @@ export default class CpoOICPClient extends OICPClient { } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_END, @@ -1102,7 +1102,7 @@ export default class CpoOICPClient extends OICPClient { requestError = err; } if (!notificationErrorResponse?.Result || notificationErrorResponse?.Result !== true) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, action: ServerAction.OICP_SEND_CHARGING_NOTIFICATION_ERROR, @@ -1142,7 +1142,7 @@ export default class CpoOICPClient extends OICPClient { } private async pingEvseEndpoint(): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: this.tenant.id, action: ServerAction.OICP_PUSH_EVSE_DATA, message: `Ping Hubject at ${this.getEndpointUrl('evses',ServerAction.OICP_PUSH_EVSE_DATA)}`, diff --git a/src/client/oicp/OICPClientFactory.ts b/src/client/oicp/OICPClientFactory.ts index 7854998070..25a41c2432 100644 --- a/src/client/oicp/OICPClientFactory.ts +++ b/src/client/oicp/OICPClientFactory.ts @@ -20,7 +20,7 @@ export default class OICPClientFactory { if (Utils.isTenantComponentActive(tenant, TenantComponents.OICP)) { const oicpSettings = await SettingStorage.getOICPSettings(tenant); if (!oicpSettings && oicpSettings.oicp) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_SETTINGS, module: MODULE_NAME, method: 'getOicpClient', @@ -41,7 +41,7 @@ export default class OICPClientFactory { const client = await OICPClientFactory.getOicpClient(tenant, oicpEndpoint); return client as CpoOICPClient; } - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_SETTINGS, module: MODULE_NAME, method: 'getCpoOicpClient', diff --git a/src/integration/asset/AssetFactory.ts b/src/integration/asset/AssetFactory.ts index e6c5dbf02b..0b55e7871f 100644 --- a/src/integration/asset/AssetFactory.ts +++ b/src/integration/asset/AssetFactory.ts @@ -45,7 +45,7 @@ export default class AssetFactory { return assetIntegrationImpl; } } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.ASSET, module: MODULE_NAME, method: 'getAssetImpl', diff --git a/src/integration/asset/greencom/GreencomAssetIntegration.ts b/src/integration/asset/greencom/GreencomAssetIntegration.ts index f1cb4c0aa6..1b3966081d 100644 --- a/src/integration/asset/greencom/GreencomAssetIntegration.ts +++ b/src/integration/asset/greencom/GreencomAssetIntegration.ts @@ -46,7 +46,7 @@ export default class GreencomAssetIntegration extends AssetIntegration GreenCom web service has been called successfully`, diff --git a/src/integration/asset/iothink/IothinkAssetIntegration.ts b/src/integration/asset/iothink/IothinkAssetIntegration.ts index 82ae80a4c8..0ea28ea43f 100644 --- a/src/integration/asset/iothink/IothinkAssetIntegration.ts +++ b/src/integration/asset/iothink/IothinkAssetIntegration.ts @@ -48,7 +48,7 @@ export default class IothinkAssetIntegration extends AssetIntegration Iothink web service has been called successfully`, diff --git a/src/integration/asset/lacroix/LacroixAssetIntegration.ts b/src/integration/asset/lacroix/LacroixAssetIntegration.ts index eebcfdd767..4c78cf4021 100644 --- a/src/integration/asset/lacroix/LacroixAssetIntegration.ts +++ b/src/integration/asset/lacroix/LacroixAssetIntegration.ts @@ -64,7 +64,7 @@ export default class LacroixAssetIntegration extends AssetIntegration Lacroix web service has been called successfully`, diff --git a/src/integration/asset/schneider/SchneiderAssetIntegration.ts b/src/integration/asset/schneider/SchneiderAssetIntegration.ts index 1530b5f03b..9cf7328075 100644 --- a/src/integration/asset/schneider/SchneiderAssetIntegration.ts +++ b/src/integration/asset/schneider/SchneiderAssetIntegration.ts @@ -43,7 +43,7 @@ export default class SchneiderAssetIntegration extends AssetIntegration Schneider web service has been called successfully`, diff --git a/src/integration/asset/wit/WitAssetIntegration.ts b/src/integration/asset/wit/WitAssetIntegration.ts index dab98f9fbb..105a5aa7ca 100644 --- a/src/integration/asset/wit/WitAssetIntegration.ts +++ b/src/integration/asset/wit/WitAssetIntegration.ts @@ -48,7 +48,7 @@ export default class WitAssetIntegration extends AssetIntegration headers: this.buildAuthHeader(token) } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.RETRIEVE_ASSET_CONSUMPTION, message: `${asset.name} > WIT web service has been called successfully`, diff --git a/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts b/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts index 370f167a55..a4a228ee03 100644 --- a/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts +++ b/src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts @@ -76,7 +76,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra public async createConnection(userID: string, data: any): Promise { try { - await Logging.logDebug({ + Logging.beDebug()?.log({ user: userID, tenantID: this.tenant.id, module: MODULE_NAME, method: 'createConnection', @@ -95,7 +95,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra 'Authorization': `Basic ${Buffer.from(this.connection.mercedesConnection.clientId + ':' + await Cypher.decrypt(this.tenant, this.connection.mercedesConnection.clientSecret)).toString('base64')}` }, }); - await Logging.logDebug({ + Logging.beDebug()?.log({ user: userID, tenantID: this.tenant.id, module: MODULE_NAME, method: 'createConnection', @@ -144,7 +144,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra headers: { 'Authorization': 'Bearer ' + connection.data.access_token } } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.CAR_CONNECTOR, message: `${car.vin} > Mercedes web service has been called successfully`, @@ -201,7 +201,7 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra 'Authorization': `Basic ${Buffer.from(this.connection.mercedesConnection.clientId + ':' + await Cypher.decrypt(this.tenant, this.connection.mercedesConnection.clientSecret)).toString('base64')}` } }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, user: userID, action: ServerAction.CAR_CONNECTOR, diff --git a/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts b/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts index aa1e59a1b1..a8aeee9cf1 100644 --- a/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts +++ b/src/integration/car-connector/targa-telematics-connector/TargaTelematicsConnector.ts @@ -46,7 +46,7 @@ export default class TargaTelematicsCarConnectorIntegration extends CarConnector headers: { 'Authorization': 'Bearer ' + connectionToken } } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.CAR_CONNECTOR, message: `${car.vin} > Targa Telematics web service has been called successfully`, diff --git a/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts b/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts index 177a07821a..6f71336e13 100644 --- a/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts +++ b/src/integration/car-connector/tronity-connector/TronityCarConnectorIntegration.ts @@ -38,7 +38,7 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat public async getCurrentSoC(car: Car): Promise { if (Utils.isNullOrUndefined(car.carConnectorData.carConnectorMeterID)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenant.id, module: MODULE_NAME, method: 'getCurrentSoC', @@ -57,7 +57,7 @@ export default class TronityCarConnectorIntegration extends CarConnectorIntegrat headers: { 'Authorization': 'Bearer ' + connectionToken } } ); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.CAR_CONNECTOR, message: `${car.vin} > Tronity web service has been called successfully`, diff --git a/src/integration/car/CarIntegration.ts b/src/integration/car/CarIntegration.ts index f046b8fa0e..d6b4295c75 100644 --- a/src/integration/car/CarIntegration.ts +++ b/src/integration/car/CarIntegration.ts @@ -41,7 +41,7 @@ export default abstract class CarIntegration { externalCar.id = await CarStorage.saveCarCatalog(externalCar); actionsDone.inSuccess++; // Log - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'synchronizeCarCatalogs', @@ -75,7 +75,7 @@ export default abstract class CarIntegration { await CarStorage.saveCarCatalog(externalCar); actionsDone.inSuccess++; // Log - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'synchronizeCarCatalogs', @@ -84,7 +84,7 @@ export default abstract class CarIntegration { } } catch (error) { actionsDone.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'synchronizeCarCatalogs', diff --git a/src/integration/car/ev-database/EVDatabaseCarIntegration.ts b/src/integration/car/ev-database/EVDatabaseCarIntegration.ts index 6eb573d6ea..7c7917fc98 100644 --- a/src/integration/car/ev-database/EVDatabaseCarIntegration.ts +++ b/src/integration/car/ev-database/EVDatabaseCarIntegration.ts @@ -22,7 +22,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration { public async getCarCatalogs(): Promise { const evDatabaseConfig = Configuration.getEVDatabaseConfig(); if (!evDatabaseConfig) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, message: 'No configuration is provided to access the EVDatabase system, skipping', module: MODULE_NAME, method: 'getCarCatalogs', @@ -95,7 +95,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration { const base64Image = Buffer.from(response.data).toString('base64'); image = 'data:' + response.headers['content-type'] + ';base64,' + base64Image; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'getCarCatalogThumb', @@ -114,7 +114,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration { const encodedImage = await response.getBase64Async(imageMIME); return encodedImage; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SYNCHRONIZE_CAR_CATALOGS, module: MODULE_NAME, method: 'getCarCatalogImage', diff --git a/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts b/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts index 6fb3eae206..ba6c46f984 100644 --- a/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts +++ b/src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts @@ -37,7 +37,7 @@ export default abstract class ChargingStationVendorIntegration { const numberOfPhases = Utils.getNumberOfConnectedPhases(chargingStation, chargePoint); const numberOfConnectors = chargePoint ? chargePoint.connectorIDs.length : chargingStation.connectors.length; if (chargePoint.excludeFromPowerLimitation) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_LIMIT_POWER, @@ -48,7 +48,7 @@ export default abstract class ChargingStationVendorIntegration { return { status: OCPPConfigurationStatus.NOT_SUPPORTED }; } if (!chargePoint.ocppParamForPowerLimitation) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_LIMIT_POWER, @@ -88,7 +88,7 @@ export default abstract class ChargingStationVendorIntegration { const ocppLimitAmpValue = this.convertLimitAmpPerPhase(chargingStation, chargePoint, 0, maxAmps * ocppParamValueMultiplier); let result: OCPPChangeConfigurationResponse; try { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_LIMIT_POWER, @@ -133,7 +133,7 @@ export default abstract class ChargingStationVendorIntegration { const connector = Utils.getConnectorFromID(chargingStation, connectorID); if (connector) { connector.amperageLimit = this.convertLimitAmpToAllPhases(chargingStation, chargePoint, connectorID, Utils.convertToInt(ocppParamValue) / ocppParamValueDivider); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_PARAM_UPDATE, @@ -187,7 +187,7 @@ export default abstract class ChargingStationVendorIntegration { }); // Call each connector? if (result.status !== OCPPChargingProfileStatus.ACCEPTED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_UPDATE, @@ -214,7 +214,7 @@ export default abstract class ChargingStationVendorIntegration { }); return result; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_UPDATE, @@ -261,7 +261,7 @@ export default abstract class ChargingStationVendorIntegration { }); // Call each connector? if (result.status !== OCPPClearChargingProfileStatus.ACCEPTED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -288,7 +288,7 @@ export default abstract class ChargingStationVendorIntegration { }); return result; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -340,7 +340,7 @@ export default abstract class ChargingStationVendorIntegration { result.chargingSchedule = this.convertFromVendorChargingSchedule(chargingStation, chargePoint, result.connectorId, result.chargingSchedule); return result; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_GET_COMPOSITE_SCHEDULE, @@ -433,7 +433,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, connectorLimitAmps), limitSource: ConnectorCurrentLimitSource.STATIC_LIMITATION, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -445,7 +445,7 @@ export default abstract class ChargingStationVendorIntegration { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -460,7 +460,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: limitDefaultMaxPower, limitSource: ConnectorCurrentLimitSource.CONNECTOR }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -609,7 +609,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, Utils.convertToInt(schedulePeriod.limit)), limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -627,7 +627,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, Utils.convertToInt(lastButOneSchedule.limit)), limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, @@ -646,7 +646,7 @@ export default abstract class ChargingStationVendorIntegration { limitWatts: Utils.convertAmpToWatt(chargingStation, chargePoint, connectorID, Utils.convertToInt(lastButOneSchedule.limit)), limitSource: ConnectorCurrentLimitSource.CHARGING_PROFILE, }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.GET_CONNECTOR_CURRENT_LIMIT, diff --git a/src/integration/pricing/PricingEngine.ts b/src/integration/pricing/PricingEngine.ts index 61913d75dc..a71b329e50 100644 --- a/src/integration/pricing/PricingEngine.ts +++ b/src/integration/pricing/PricingEngine.ts @@ -25,7 +25,7 @@ export default class PricingEngine { // pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, pricingContext, PricingEntity.COMPANY, transaction.companyID)); pricingDefinitions.push(...await PricingEngine.getPricingDefinitions4Entity(tenant, pricingContext, PricingEntity.TENANT, tenant.id)); if (!pricingContext.timezone) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, @@ -43,7 +43,7 @@ export default class PricingEngine { }, pricingDefinitions }; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, @@ -75,7 +75,7 @@ export default class PricingEngine { private static async getPricingDefinitions4Entity(tenant: Tenant, pricingContext: PricingContext, entityType: PricingEntity, entityID: string): Promise { if (!entityID) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, @@ -94,7 +94,7 @@ export default class PricingEngine { ).map((pricingDefinition) => PricingEngine.shrinkPricingDefinition(pricingDefinition) ); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: tenant.id, module: MODULE_NAME, diff --git a/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts b/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts index a986caf383..3ba45ba0a8 100644 --- a/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts +++ b/src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts @@ -23,7 +23,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, module: MODULE_NAME, @@ -41,7 +41,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, module: MODULE_NAME, @@ -55,7 +55,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: this.tenant.id, module: MODULE_NAME, @@ -69,7 +69,7 @@ export default class BuiltInPricingIntegration extends PricingIntegration { if (!PricingHelper.checkContextConsistency(pricingContext)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getPricingContextProperties(pricingContext), tenantID: this.tenant.id, module: MODULE_NAME, diff --git a/src/integration/refund/RefundFactory.ts b/src/integration/refund/RefundFactory.ts index 4877679987..37997af5a0 100644 --- a/src/integration/refund/RefundFactory.ts +++ b/src/integration/refund/RefundFactory.ts @@ -25,7 +25,7 @@ export default class RefundFactory { } return refundIntegrationImpl; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.REFUND, module: MODULE_NAME, diff --git a/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts b/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts index 14d357fcda..42459ddfab 100644 --- a/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts +++ b/src/integration/refund/sap-concur/SapConcurRefundIntegration.ts @@ -106,7 +106,7 @@ export default class SapConcurRefundIntegration extends RefundIntegration { try { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, module: MODULE_NAME, method: 'createConnection', action: ServerAction.REFUND, message: `Request Concur access token for User ID '${userID}'` @@ -125,7 +125,7 @@ export default class SapConcurRefundIntegration extends RefundIntegration chargingStation.siteAreaID === siteArea.id); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > No charging station used, so no need to call the Smart Charging service`, @@ -116,7 +116,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio const url = await this.buildOptimizerUrl(sourceSiteArea); // Check at least one car if (request.state.cars.length === 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > No car connected so no need to call the SAP Smart Charging service`, @@ -125,7 +125,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio }); return; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > Call the SAP Smart Charging service...`, @@ -138,7 +138,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio Accept: 'application/json', } }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > SAP Smart Charging service has been called successfully`, @@ -148,7 +148,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio // Build charging profiles from result const chargingProfiles = await this.buildChargingProfilesFromOptimizerResponse( sourceSiteArea, siteAreas.result, response.data); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${sourceSiteArea.name} > Charging Profiles have been built successfully`, @@ -338,7 +338,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio // Transaction in progress? if (!connector.currentTransactionID) { // Should not happen - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, @@ -352,7 +352,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio const currentTransaction = transactions.find((transaction) => transaction.id === connector.currentTransactionID); if (!currentTransaction) { // Should not happen - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, @@ -370,7 +370,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio // Get Asset consumption const assetConsumptionInWatts = await this.getAssetConsumptionInWatts(siteArea); if (siteArea.maximumPower !== siteArea.maximumPower - assetConsumptionInWatts) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${siteArea.name} > limit of ${siteArea.maximumPower} W has been adjusted to ${Math.round(siteArea.maximumPower - assetConsumptionInWatts)} W due Asset Consumption`, @@ -482,7 +482,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio } // Found unsupported chargers if (siteMaxAmps !== rootFuse.fusePhase1 + rootFuse.fusePhase2 + rootFuse.fusePhase3) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${siteArea.name} > limit of ${siteMaxAmps} Amps has been lowered to ${Math.round(rootFuse.fusePhase1 + rootFuse.fusePhase2 + rootFuse.fusePhase3)} Amps due to unsupported charging stations currently being used`, @@ -935,7 +935,7 @@ export default class SapSmartChargingIntegration extends SmartChargingIntegratio } } if (removedChargingProfiles > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: this.tenant.id, action: ServerAction.SMART_CHARGING, message: `${siteArea.name} > ${removedChargingProfiles} Charging Profiles have been already applied and will be removed from charging profile schedule`, diff --git a/src/locking/LockingManager.ts b/src/locking/LockingManager.ts index 6101cdb430..fbea696984 100644 --- a/src/locking/LockingManager.ts +++ b/src/locking/LockingManager.ts @@ -16,7 +16,7 @@ export default class LockingManager { public static async acquire(lock: Lock, timeoutSecs = 0, retry = true): Promise { try { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -36,7 +36,7 @@ export default class LockingManager { detailedMessages: { lock, timeoutSecs, retry } }); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -50,7 +50,7 @@ export default class LockingManager { if (retry && await LockingManager.checkAndReleaseExpiredLock(lock)) { return LockingManager.acquire(lock, timeoutSecs, false); } - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -66,7 +66,7 @@ export default class LockingManager { // Delete const result = await LockingStorage.deleteLock(lock.id); if (!result) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'release', action: ServerAction.LOCKING, @@ -75,7 +75,7 @@ export default class LockingManager { }); return false; } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'release', action: ServerAction.LOCKING, @@ -156,7 +156,7 @@ export default class LockingManager { try { // Remove the lock await LockingManager.release(lockInDB); - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, @@ -166,7 +166,7 @@ export default class LockingManager { Utils.isDevelopmentEnv() && Logging.logConsoleWarning(`The lock '${lock.entity}' ('${lock.key}') of type '${lock.type}' in Tenant ID ${lock.tenantID} has expired and was released successfully`); return true; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: lock.tenantID, module: MODULE_NAME, method: 'acquire', action: ServerAction.LOCKING, diff --git a/src/migration/MigrationHandler.ts b/src/migration/MigrationHandler.ts index 5bf4955c55..4eb4b2290b 100644 --- a/src/migration/MigrationHandler.ts +++ b/src/migration/MigrationHandler.ts @@ -18,7 +18,7 @@ export default class MigrationHandler { if (await LockingManager.acquire(migrationLock)) { try { const startTime = moment(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -49,14 +49,14 @@ export default class MigrationHandler { } // Log Total Processing Time const totalTimeSecs = moment.duration(moment().diff(startTime)).asSeconds(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', message: `The ${processAsyncTasksOnly ? 'asynchronous' : 'synchronous'} migration has been run in ${totalTimeSecs} secs` }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -80,7 +80,7 @@ export default class MigrationHandler { try { // Log Start Task let logMsg = `${currentMigrationTask.isAsynchronous() ? 'Asynchronous' : 'Synchronous'} Migration Task '${currentMigrationTask.getName()}' Version '${currentMigrationTask.getVersion()}' is running...`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'executeTask', @@ -104,7 +104,7 @@ export default class MigrationHandler { durationSecs: totalTaskTimeSecs }); logMsg = `${currentMigrationTask.isAsynchronous() ? 'Asynchronous' : 'Synchronous'} Migration Task '${currentMigrationTask.getName()}' Version '${currentMigrationTask.getVersion()}' has run with success in ${totalTaskTimeSecs} secs`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'executeTask', @@ -114,7 +114,7 @@ export default class MigrationHandler { Utils.isDevelopmentEnv() && Logging.logConsoleDebug(logMsg); } catch (error) { const logMsg = `${currentMigrationTask.isAsynchronous() ? 'Asynchronous' : 'Synchronous'} Migration Task '${currentMigrationTask.getName()}' Version '${currentMigrationTask.getVersion()}' has failed with error: ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'executeTask', diff --git a/src/migration/TenantMigrationTask.ts b/src/migration/TenantMigrationTask.ts index 578f5628d6..22c5b74e72 100644 --- a/src/migration/TenantMigrationTask.ts +++ b/src/migration/TenantMigrationTask.ts @@ -15,7 +15,7 @@ export default abstract class TenantMigrationTask extends MigrationTask { for (const tenant of tenants.result) { const tenantCorrelationID = Utils.generateShortNonUniqueID(); const startTimeInTenant = moment(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -25,7 +25,7 @@ export default abstract class TenantMigrationTask extends MigrationTask { // Migrate await this.migrateTenant(tenant); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', @@ -35,7 +35,7 @@ export default abstract class TenantMigrationTask extends MigrationTask { } // Log Total Processing Time const totalTimeSecsInTenant = moment.duration(moment().diff(startTimeInTenant)).asSeconds(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrate', diff --git a/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts b/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts index 7ccaf443ec..fe310260c2 100644 --- a/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts +++ b/src/migration/tasks/AddCompanyIDToChargingStationsTask.ts @@ -49,7 +49,7 @@ export default class AddCompanyIDToChargingStationsTask extends TenantMigrationT } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AddCompanyIDToTransactionsTask.ts b/src/migration/tasks/AddCompanyIDToTransactionsTask.ts index 0b3bed5724..f29df87978 100644 --- a/src/migration/tasks/AddCompanyIDToTransactionsTask.ts +++ b/src/migration/tasks/AddCompanyIDToTransactionsTask.ts @@ -49,7 +49,7 @@ export default class AddCompanyIDToTransactionsTask extends TenantMigrationTask } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts b/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts index 8885317dd9..d4bb559f08 100644 --- a/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts +++ b/src/migration/tasks/AddLevelTemplateToChargingStationTemplateTask.ts @@ -17,7 +17,7 @@ export default class AddLevelTemplateToChargingStationTemplateTask extends Migra for (const template of templates) { if (template.template) { // skip this one as it has already ran - continue + continue; } // Put _id in id const and get template without id const { @@ -47,7 +47,7 @@ export default class AddLevelTemplateToChargingStationTemplateTask extends Migra }, ); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrate', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AddUserIDToCarsTask.ts b/src/migration/tasks/AddUserIDToCarsTask.ts index 11af90b226..562f07de48 100644 --- a/src/migration/tasks/AddUserIDToCarsTask.ts +++ b/src/migration/tasks/AddUserIDToCarsTask.ts @@ -35,7 +35,7 @@ export default class AddUserIDToCarsTask extends TenantMigrationTask { } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts b/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts index 55b33f3823..7ebafa767b 100644 --- a/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts +++ b/src/migration/tasks/AlignEntitiesWithOrganizationIDsTask.ts @@ -30,7 +30,7 @@ export default class AlignEntitiesWithOrganizationIDsTask extends TenantMigratio updated += await SiteAreaStorage.updateEntitiesWithOrganizationIDs( tenant, foundSite.companyID.toString(), siteArea.siteID.toString(), siteArea._id.toString()); } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, @@ -41,7 +41,7 @@ export default class AlignEntitiesWithOrganizationIDsTask extends TenantMigratio } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/MigrateSimplePricing.ts b/src/migration/tasks/MigrateSimplePricing.ts index 254ad75eac..4b3aca90d3 100644 --- a/src/migration/tasks/MigrateSimplePricing.ts +++ b/src/migration/tasks/MigrateSimplePricing.ts @@ -17,7 +17,7 @@ export default class SimplePricingMigrationTask extends TenantMigrationTask { const pricingSetting = await SettingStorage.getSettingByIdentifier(tenant, TenantComponents.PRICING); if (pricingSetting?.content?.type === PricingSettingsType.SIMPLE) { await this.createDefaultPricingDefinition(tenant, pricingSetting.content.simple); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts b/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts index b30e494b9d..df35d90735 100644 --- a/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts +++ b/src/migration/tasks/RemoveDuplicateTagVisualIDsTask.ts @@ -49,7 +49,7 @@ export default class RemoveDuplicateTagVisualIDsTask extends TenantMigrationTask } // Log in the default tenant if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/RepairInvoiceInconsistencies.ts b/src/migration/tasks/RepairInvoiceInconsistencies.ts index 3dbef59364..2534ba41e2 100644 --- a/src/migration/tasks/RepairInvoiceInconsistencies.ts +++ b/src/migration/tasks/RepairInvoiceInconsistencies.ts @@ -18,7 +18,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { const billingImpl = await BillingFactory.getBillingImpl(tenant); if (billingImpl && billingImpl instanceof StripeBillingIntegration) { await this.repairInvoices(tenant, billingImpl); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, @@ -26,7 +26,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, module: MODULE_NAME, method: 'repairInvoices', @@ -68,7 +68,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { try { // Skip invoices that are already PAID or not relevant for the current billing process if (!billingInvoice.sessions) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -76,7 +76,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { message: `Attempt to repair invoice: '${billingInvoice.id}' - '${billingInvoice.number}' ` }); await billingImpl.repairInvoice(billingInvoice); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -85,7 +85,7 @@ export default class RepairInvoiceInconsistencies extends TenantMigrationTask { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, diff --git a/src/migration/tasks/RepairTransactionBillingData.ts b/src/migration/tasks/RepairTransactionBillingData.ts index d9855e3589..ad608bf579 100644 --- a/src/migration/tasks/RepairTransactionBillingData.ts +++ b/src/migration/tasks/RepairTransactionBillingData.ts @@ -18,7 +18,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { const billingImpl = await BillingFactory.getBillingImpl(tenant); if (billingImpl && billingImpl instanceof StripeBillingIntegration) { await this.repairTransactionsBillingData(tenant, billingImpl); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, @@ -26,7 +26,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, module: MODULE_NAME, method: 'repairInvoices', @@ -66,7 +66,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { skip += limit; for (const billingInvoice of invoices.result) { try { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -74,7 +74,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { message: `Attempt to repair transaction's billing data for invoice: '${billingInvoice.id}' - '${billingInvoice.number}' ` }); await billingImpl.repairTransactionsBillingData(billingInvoice); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, @@ -82,7 +82,7 @@ export default class RepairTransactionBillingData extends TenantMigrationTask { message: `Transaction's billing data has been repaired for invoice: '${billingInvoice.id}' - '${billingInvoice.number}' ` }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_PERFORM_OPERATIONS, actionOnUser: billingInvoice.user, diff --git a/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts b/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts index 39ead9fc19..428a5b31d7 100644 --- a/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts +++ b/src/migration/tasks/RepairTransactionPricedAtZeroTask.ts @@ -46,7 +46,7 @@ export default class RepairTransactionPricedAtZero extends TenantMigrationTask { await this.loadSimplePricingSettings(tenant); if (transactionsMDB.length > 0 && this.pricingSettings?.simple?.price > 0) { let message = `${transactionsMDB.length} Transaction(s) are going to be repaired in Tenant ${Utils.buildTenantName(tenant)}...`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrateTenant', @@ -57,7 +57,7 @@ export default class RepairTransactionPricedAtZero extends TenantMigrationTask { const numberOfProcessedTransactions = transactionsUpdated.inError + transactionsUpdated.inSuccess; if (numberOfProcessedTransactions > 0 && (numberOfProcessedTransactions % 100) === 0) { message = `> ${transactionsUpdated.inError + transactionsUpdated.inSuccess}/${transactionsMDB.length} - Transaction consumptions recomputed in Tenant ${Utils.buildTenantName(tenant)}`; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrateTenant', @@ -78,7 +78,7 @@ export default class RepairTransactionPricedAtZero extends TenantMigrationTask { transactionsUpdated.inSuccess++; } catch (error) { transactionsUpdated.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MIGRATION, module: MODULE_NAME, method: 'migrateTenant', diff --git a/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts b/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts index 246bf41044..e1b88a9c48 100644 --- a/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts +++ b/src/migration/tasks/RestoreDataIntegrityInSiteUsersTask.ts @@ -47,7 +47,7 @@ export default class RestoreDataIntegrityInSiteUsersTask extends TenantMigration } // Log in the default tenant if (deleted > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/migration/tasks/UpdateEmailsToLowercaseTask.ts b/src/migration/tasks/UpdateEmailsToLowercaseTask.ts index 86889ca148..4cd636e746 100644 --- a/src/migration/tasks/UpdateEmailsToLowercaseTask.ts +++ b/src/migration/tasks/UpdateEmailsToLowercaseTask.ts @@ -22,7 +22,7 @@ export default class UpdateEmailsToLowercaseTask extends TenantMigrationTask { ) as UpdateResult; if (updateResult.modifiedCount > 0) { // Log in the default tenant - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'migrateTenant', action: ServerAction.MIGRATION, diff --git a/src/notification/NotificationHandler.ts b/src/notification/NotificationHandler.ts index f0eb1006ce..a9cb7e43b6 100644 --- a/src/notification/NotificationHandler.ts +++ b/src/notification/NotificationHandler.ts @@ -119,7 +119,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendEndOfCharge(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendEndOfCharge', @@ -164,7 +164,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendOptimalChargeReached(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendOptimalChargeReached', @@ -209,7 +209,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendEndOfSession(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendEndOfSession', @@ -254,7 +254,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendEndOfSignedSession(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendEndOfSignedSession', @@ -417,7 +417,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendVerificationEmail( sourceData, user, tenant, NotificationSeverity.INFO); } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendVerificationEmail', action: ServerAction.VERIFY_EMAIL, @@ -490,7 +490,7 @@ export default class NotificationHandler { sourceData, adminUser, tenant, NotificationSeverity.ERROR); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendChargingStationStatusError', @@ -593,7 +593,7 @@ export default class NotificationHandler { sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendSessionStarted', @@ -643,7 +643,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOCPIPatchChargingStationsStatusesError', action: ServerAction.PATCH_EVSE_STATUS_ERROR, @@ -687,7 +687,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOICPPatchChargingStationsStatusesError', action: ServerAction.PATCH_EVSE_STATUS_ERROR, @@ -731,7 +731,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOICPPatchChargingStationsError', action: ServerAction.PATCH_EVSE_ERROR, @@ -766,7 +766,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendUserAccountInactivity( sourceData, user, tenant, NotificationSeverity.INFO); } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendUserAccountInactivity', action: ServerAction.USER_ACCOUNT_INACTIVITY, @@ -810,7 +810,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendPreparingSessionNotStarted(sourceData, user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendPreparingSessionNotStarted', @@ -855,7 +855,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendOfflineChargingStations', action: ServerAction.OFFLINE_CHARGING_STATIONS, @@ -898,7 +898,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingSynchronizationFailed', action: ServerAction.BILLING_USER_SYNCHRONIZATION_FAILED, @@ -941,7 +941,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingInvoicesSynchronizationFailed', action: ServerAction.BILLING_INVOICE_SYNCHRONIZATION_FAILED, @@ -984,7 +984,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingPeriodicOperationFailed', action: ServerAction.BILLING_PERFORM_OPERATIONS, @@ -1027,7 +1027,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_OBJECT.id, module: MODULE_NAME, method: 'sendCarsSynchronizationFailed', action: ServerAction.CAR_CATALOG_SYNCHRONIZATION_FAILED, @@ -1071,7 +1071,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendComputeAndApplyChargingProfilesFailed', @@ -1146,7 +1146,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendSessionNotStarted(sourceData, sourceData.user, tenant, NotificationSeverity.INFO); } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'sendSessionNotStarted', @@ -1185,7 +1185,7 @@ export default class NotificationHandler { } } } else { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendBillingNewInvoiceNotification', action: ServerAction.BILLING_NEW_INVOICE, @@ -1260,7 +1260,7 @@ export default class NotificationHandler { // Success if (extraParams.user) { // User - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, siteID: extraParams.chargingStation?.siteID, siteAreaID: extraParams.chargingStation?.siteAreaID, @@ -1273,7 +1273,7 @@ export default class NotificationHandler { }); } else { // Admin - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, siteID: extraParams.chargingStation?.siteID, siteAreaID: extraParams.chargingStation?.siteAreaID, diff --git a/src/notification/email/EMailNotificationTask.ts b/src/notification/email/EMailNotificationTask.ts index d32bf0eb06..8fba4c1125 100644 --- a/src/notification/email/EMailNotificationTask.ts +++ b/src/notification/email/EMailNotificationTask.ts @@ -243,7 +243,7 @@ export default class EMailNotificationTask implements NotificationTask { // Email configuration sanity checks if (!this.smtpMainClientInstance) { // No suitable main SMTP server configuration found to send the email - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -258,7 +258,7 @@ export default class EMailNotificationTask implements NotificationTask { } if (useSmtpClientBackup && !this.smtpBackupClientInstance) { // No suitable backup SMTP server configuration found or activated to send the email - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -285,7 +285,7 @@ export default class EMailNotificationTask implements NotificationTask { }); if (Utils.isDevelopmentEnv()) { // Do not send mail in Dev mode - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id ? tenant.id : Constants.DEFAULT_TENANT_ID, action: ServerAction.EMAIL_NOTIFICATION, module: MODULE_NAME, method: 'sendEmail', @@ -306,7 +306,7 @@ export default class EMailNotificationTask implements NotificationTask { // Send the message const messageSent: Message = await smtpClient.sendAsync(messageToSend); // Email sent successfully - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id ? tenant.id : Constants.DEFAULT_TENANT_ID, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -323,7 +323,7 @@ export default class EMailNotificationTask implements NotificationTask { } }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id ? tenant.id : Constants.DEFAULT_TENANT_ID, siteID: data?.siteID, siteAreaID: data?.siteAreaID, @@ -425,7 +425,7 @@ export default class EMailNotificationTask implements NotificationTask { html: emailContent.html, }; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, ...LoggingHelper.getSourceDataProperties(sourceData), action: ServerAction.EMAIL_NOTIFICATION, diff --git a/src/notification/remote-push-notification/RemotePushNotificationTask.ts b/src/notification/remote-push-notification/RemotePushNotificationTask.ts index 91c7968a59..d6d84c456b 100644 --- a/src/notification/remote-push-notification/RemotePushNotificationTask.ts +++ b/src/notification/remote-push-notification/RemotePushNotificationTask.ts @@ -469,7 +469,7 @@ export default class RemotePushNotificationTask implements NotificationTask { return Promise.resolve(); } if (!user?.mobileData?.mobileToken) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, siteID: data?.siteID, siteAreaID: data?.siteAreaID, diff --git a/src/scheduler/SchedulerManager.ts b/src/scheduler/SchedulerManager.ts index bb8f7e3d0c..ae78cf3248 100644 --- a/src/scheduler/SchedulerManager.ts +++ b/src/scheduler/SchedulerManager.ts @@ -43,7 +43,7 @@ export default class SchedulerManager { // Keep the conf SchedulerManager.schedulerConfig = schedulerConfig; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'init', @@ -53,7 +53,7 @@ export default class SchedulerManager { for (const task of SchedulerManager.schedulerConfig.tasks) { // Active? if (!task.active) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'init', @@ -65,7 +65,7 @@ export default class SchedulerManager { if (schedulerTask) { // Register task to cron engine cron.schedule(task.periodicity, () => SchedulerManager.runTask(schedulerTask, task)); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'init', @@ -146,7 +146,7 @@ export default class SchedulerManager { case 'DispatchCollectedFundsTask': return new DispatchCollectedFundsTask(); default: - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'createTask', diff --git a/src/scheduler/SchedulerTask.ts b/src/scheduler/SchedulerTask.ts index 8410143fd6..6ff7e3db8b 100644 --- a/src/scheduler/SchedulerTask.ts +++ b/src/scheduler/SchedulerTask.ts @@ -21,7 +21,7 @@ export default abstract class SchedulerTask { if (scheduledTaskLock) { try { const startTime = moment(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'run', @@ -35,7 +35,7 @@ export default abstract class SchedulerTask { // Hook await this.afterTaskRun(config); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'run', @@ -45,7 +45,7 @@ export default abstract class SchedulerTask { } // Log Total Processing Time const totalTimeSecs = moment.duration(moment().diff(startTime)).asSeconds(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'run', diff --git a/src/scheduler/TenantSchedulerTask.ts b/src/scheduler/TenantSchedulerTask.ts index ffee0dbd70..1a1f2014a8 100644 --- a/src/scheduler/TenantSchedulerTask.ts +++ b/src/scheduler/TenantSchedulerTask.ts @@ -23,7 +23,7 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { (taskSettings.task.disableAllTasks || !Utils.isEmptyArray(taskSettings.task.disableTasksInEnv) && taskSettings.task.disableTasksInEnv.includes(currentTaskEnv))) { // Tasks are disabled for this environment isTaskExecutionDisabled = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -43,7 +43,7 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { } // Check if tenant task needs to run on a specific environment if (tenant.taskExecutionEnv && tenant.taskExecutionEnv !== currentTaskEnv) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -54,13 +54,13 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { } const tenantCorrelationID = Utils.generateShortNonUniqueID(); const startTimeInTenant = moment(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', message: `The Task '${this.getName()}~${this.getCorrelationID()}~${tenantCorrelationID}' is running for Tenant ${Utils.buildTenantName(tenant)}...` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -74,14 +74,14 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { // Hook await this.afterProcessTenant(tenant, config); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', message: `Error while running the Task '${this.getName()}~${this.getCorrelationID()}~${tenantCorrelationID}' for Tenant ${Utils.buildTenantName(tenant)}: ${error.message as string}`, detailedMessages: { error: error.stack } }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', @@ -91,13 +91,13 @@ export default abstract class TenantSchedulerTask extends SchedulerTask { } // Log Total Processing Time in Tenant const totalTimeSecsInTenant = moment.duration(moment().diff(startTimeInTenant)).asSeconds(); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', message: `The Task '${this.getName()}~${this.getCorrelationID()}~${tenantCorrelationID}' has been run successfully in ${totalTimeSecsInTenant} secs for Tenant ${Utils.buildTenantName(tenant)}` }); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SCHEDULER, module: MODULE_NAME, method: 'processTask', diff --git a/src/scheduler/tasks/BillPendingTransactionTask.ts b/src/scheduler/tasks/BillPendingTransactionTask.ts index dad30128c8..e98b0cec69 100644 --- a/src/scheduler/tasks/BillPendingTransactionTask.ts +++ b/src/scheduler/tasks/BillPendingTransactionTask.ts @@ -43,7 +43,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } ]).toArray(); if (!Utils.isEmptyArray(transactionsMDB)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -56,7 +56,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { // Get Transaction const transaction = await TransactionStorage.getTransaction(tenant, transactionMDB._id, { withUser: true, withChargingStation: true }); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -67,7 +67,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { // Get Charging Station const chargingStation = transaction.chargeBox; if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -87,7 +87,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } // Check for the billing status if (transaction.billingData?.stop?.status !== BillingStatus.PENDING) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -97,7 +97,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } // Avoid billing again! if (transaction.billingData?.stop?.invoiceID) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', @@ -112,7 +112,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { await BillingFacade.processEndTransaction(tenant, transaction, transaction.user); // Save await TransactionStorage.saveTransaction(tenant, transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, actionOnUser: transaction.user, @@ -120,7 +120,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { message: `The billing process has been started for transaction '${transaction.id}'`, }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.BILLING_BILL_PENDING_TRANSACTION, module: MODULE_NAME, method: 'processTenant', diff --git a/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts b/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts index 8b7d4e92b9..37bfccf9d1 100644 --- a/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts +++ b/src/scheduler/tasks/CheckAndComputeSmartChargingTask.ts @@ -29,7 +29,7 @@ export default class CheckAndComputeSmartChargingTask extends TenantSchedulerTas const smartCharging = await SmartChargingFactory.getSmartChargingImpl(tenant); if (!smartCharging) { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processTenant', action: ServerAction.CHECK_AND_APPLY_SMART_CHARGING, @@ -40,7 +40,7 @@ export default class CheckAndComputeSmartChargingTask extends TenantSchedulerTas await smartCharging.computeAndApplyChargingProfiles(siteArea); } catch (error) { // Log error - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processTenant', action: ServerAction.CHECK_AND_APPLY_SMART_CHARGING, @@ -53,7 +53,7 @@ export default class CheckAndComputeSmartChargingTask extends TenantSchedulerTas } } } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'processTenant', action: ServerAction.CHECK_AND_APPLY_SMART_CHARGING, diff --git a/src/scheduler/tasks/CheckChargingStationTemplateTask.ts b/src/scheduler/tasks/CheckChargingStationTemplateTask.ts index 61d4650bc7..ae7c68c04d 100644 --- a/src/scheduler/tasks/CheckChargingStationTemplateTask.ts +++ b/src/scheduler/tasks/CheckChargingStationTemplateTask.ts @@ -34,7 +34,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas let updated = 0; // Bypass perf tenant if (tenant.subdomain === 'testperf') { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'applyTemplateToChargingStations', @@ -57,7 +57,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas updated++; } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -68,7 +68,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas } } if (updated > 0) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, module: MODULE_NAME, method: 'applyTemplateToChargingStations', diff --git a/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts b/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts index 4c93124e1d..8067f870a4 100644 --- a/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts +++ b/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts @@ -45,7 +45,7 @@ export default class CheckOfflineChargingStationsTask extends TenantSchedulerTas } // Charging Station is still connected: ignore it if (ocppHeartbeatConfiguration) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OFFLINE_CHARGING_STATION, diff --git a/src/scheduler/tasks/CloseTransactionsInProgressTask.ts b/src/scheduler/tasks/CloseTransactionsInProgressTask.ts index a5d8983545..e80c721435 100644 --- a/src/scheduler/tasks/CloseTransactionsInProgressTask.ts +++ b/src/scheduler/tasks/CloseTransactionsInProgressTask.ts @@ -34,7 +34,7 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask // Soft stop transaction await ocppService.softStopTransaction(tenant, transaction, transaction.chargeBox, transaction.siteArea); result.inSuccess++; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, @@ -45,7 +45,7 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask }); } catch (error) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.TRANSACTION_SOFT_STOP, diff --git a/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts b/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts index b4e5bd2022..c88e9b0803 100644 --- a/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts +++ b/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts @@ -47,14 +47,14 @@ export default class LoggingDatabaseTableCleanupTask extends TenantSchedulerTask // Delete const result = await LogStorage.deleteLogs(tenant, deleteUpToDate); if (result.acknowledged) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.LOGS_CLEANUP, module: MODULE_NAME, method: 'deleteLogs', message: `${result.deletedCount} Log(s) have been deleted before '${moment(deleteUpToDate).format('DD/MM/YYYY h:mm A')}'` }); } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.LOGS_CLEANUP, module: MODULE_NAME, method: 'deleteLogs', @@ -90,14 +90,14 @@ export default class LoggingDatabaseTableCleanupTask extends TenantSchedulerTask // Delete Logs const result = await PerformanceStorage.deletePerformanceRecords({ deleteUpToDate }); if (result.acknowledged) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.PERFORMANCES_CLEANUP, module: MODULE_NAME, method: 'deletePerformanceRecords', message: `${result.deletedCount} Performance Record(s) have been deleted before '${moment(deleteUpToDate).format('DD/MM/YYYY h:mm A')}'` }); } else { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.PERFORMANCES_CLEANUP, module: MODULE_NAME, method: 'deletePerformanceRecords', diff --git a/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts b/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts index 98e49ed8ab..bc5d113526 100644 --- a/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts +++ b/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts @@ -17,7 +17,7 @@ const MODULE_NAME = 'SynchronizeRefundTransactionsTask'; export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTask { public async processTenant(tenant: Tenant, config: TaskConfig): Promise { if (!Utils.isTenantComponentActive(tenant, TenantComponents.REFUND)) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'run', @@ -28,7 +28,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa // Get Concur Settings const refundConnector = await RefundFactory.getRefundImpl(tenant); if (!refundConnector) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'run', @@ -46,7 +46,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa { ...Constants.DB_PARAMS_MAX_LIMIT, sort: { 'userID': 1, 'refundData.reportId': 1 } }); if (!Utils.isEmptyArray(transactions.result)) { // Process them - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'processTenant', @@ -78,7 +78,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa } } // Log result - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'processTenant', @@ -86,7 +86,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa }); } else { // Process them - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.SYNCHRONIZE_REFUND, module: MODULE_NAME, method: 'processTenant', diff --git a/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts index 76027bc2eb..c97a997b86 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts @@ -40,7 +40,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -49,7 +49,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -57,7 +57,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, @@ -67,7 +67,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Check CDRs const result = await ocpiClient.checkCdrs(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_CDRS, diff --git a/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts index f9f97eb453..36c4703434 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts @@ -40,7 +40,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -49,7 +49,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -57,7 +57,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -67,7 +67,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Check Locations const result = await ocpiClient.checkLocations(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, diff --git a/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts index 1cc32f4389..f5a76dd3a4 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts @@ -40,7 +40,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -49,7 +49,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -57,7 +57,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, @@ -67,7 +67,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Check Sessions const result = await ocpiClient.checkSessions(); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_CHECK_SESSIONS, diff --git a/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts index 26aafb2278..e0d03d77e7 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts @@ -41,7 +41,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -50,7 +50,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -58,7 +58,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpointatch', @@ -68,7 +68,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Pull CDRs const result = await ocpiClient.pullCdrs(true); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_CDRS, module: MODULE_NAME, method: 'processOCPIEndpoint', diff --git a/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts index fad3084a51..92a29b972f 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts @@ -40,7 +40,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -49,7 +49,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -57,7 +57,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -67,7 +67,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Pull Locations const result = await ocpiClient.pullLocations(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_GET_LOCATIONS, module: MODULE_NAME, method: 'processOCPIEndpoint', diff --git a/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts index d0e1ddfaa9..85e93a6de6 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts @@ -40,7 +40,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, @@ -49,7 +49,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, @@ -57,7 +57,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, @@ -67,7 +67,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Pull Sessions const result = await ocpiClient.pullSessions(true); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_EMSP_GET_SESSION, diff --git a/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts b/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts index a453172eee..6716a17dde 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts @@ -40,7 +40,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, @@ -49,7 +49,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, @@ -57,7 +57,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, @@ -67,7 +67,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Pull Tokens const result = await ocpiClient.pullTokens(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_GET_TOKENS, diff --git a/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts index 7c2906f901..185fb89962 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts @@ -41,7 +41,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { } ]).toArray(); if (!Utils.isEmptyArray(transactionsMDB)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -55,7 +55,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { // Get Transaction const transaction = await TransactionStorage.getTransaction(tenant, transactionMDB._id, { withUser: true }); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -64,7 +64,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { continue; } if (transaction.ocpiData?.cdr) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -75,7 +75,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { // Get Charging Station const chargingStation = await ChargingStationStorage.getChargingStation(tenant, transaction.chargeBoxID, { withSiteArea: true }); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -86,7 +86,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { // Get Tag const tag = await TagStorage.getTag(tenant, transaction.tagID); if (!tag) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', @@ -98,7 +98,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { await OCPIFacade.processEndTransaction(tenant, transaction, chargingStation, chargingStation.siteArea, transaction.user, ServerAction.OCPI_CPO_PUSH_CDRS); // Save await TransactionStorage.saveTransactionOcpiData(tenant, transaction.id, transaction.ocpiData); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, actionOnUser: (transaction.user ? transaction.user : null), @@ -107,7 +107,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { detailedMessages: { cdr: transaction.ocpiData.cdr } }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_CPO_PUSH_CDRS, module: MODULE_NAME, method: 'processTenant', diff --git a/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts b/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts index 6e8fb59dc3..b6dac32dbc 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts @@ -40,7 +40,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, @@ -49,7 +49,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, @@ -57,7 +57,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, @@ -67,7 +67,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getCpoOcpiClient(tenant, ocpiEndpoint); // Push EVSE statuses const sendResult = await ocpiClient.pushChargingStationStatuses(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOCPIEndpoint', action: ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, diff --git a/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts b/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts index 54a864ebaa..6829291f10 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts @@ -40,7 +40,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { try { // Check if OCPI endpoint is registered if (ocpiEndpoint.status !== OCPIRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -49,7 +49,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { return; } if (!ocpiEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -57,7 +57,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', @@ -67,7 +67,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { const ocpiClient = await OCPIClientFactory.getEmspOcpiClient(tenant, ocpiEndpoint); // Push Tokens const result = await ocpiClient.pushTokens(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: ServerAction.OCPI_EMSP_UPDATE_TOKENS, module: MODULE_NAME, method: 'processOCPIEndpoint', diff --git a/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts b/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts index 0ebec59080..8e21967d32 100644 --- a/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts +++ b/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts @@ -40,7 +40,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { try { // Check if OICP endpoint is registered if (oicpEndpoint.status !== OICPRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, @@ -49,7 +49,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { return; } if (!oicpEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, @@ -57,7 +57,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, @@ -67,7 +67,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { const oicpClient = await OICPClientFactory.getCpoOicpClient(tenant, oicpEndpoint); // Send EVSEs const sendEVSEDataResult = await oicpClient.sendEVSEs(!Utils.isUndefined(config.partial) ? config.partial : false); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_DATA, diff --git a/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts b/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts index b118cad2a4..c840c3283c 100644 --- a/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts +++ b/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts @@ -40,7 +40,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { try { // Check if OICP endpoint is registered if (oicpEndpoint.status !== OICPRegistrationStatus.REGISTERED) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, @@ -49,7 +49,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { return; } if (!oicpEndpoint.backgroundPatchJob) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, @@ -57,7 +57,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { }); return; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, @@ -67,7 +67,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { const oicpClient = await OICPClientFactory.getCpoOicpClient(tenant, oicpEndpoint); // Send EVSE statuses const sendEVSEStatusResult = await oicpClient.sendEVSEStatuses(config.partial); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'processOICPEndpoint', action: ServerAction.OICP_PUSH_EVSE_STATUSES, diff --git a/src/server/ServerUtils.ts b/src/server/ServerUtils.ts index 62b246a69b..c4191c1d37 100644 --- a/src/server/ServerUtils.ts +++ b/src/server/ServerUtils.ts @@ -12,7 +12,7 @@ export class ServerUtils { protocol: ServerProtocol, hostname: string, port: number): Promise { const logMsg = `${serverType} Server listening on '${protocol}://${hostname}:${port}'`; // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: serverModuleName, method: methodName, action: ServerAction.STARTUP, diff --git a/src/server/ocpi/OCPIFacade.ts b/src/server/ocpi/OCPIFacade.ts index 17a958eddd..ce229de5bb 100644 --- a/src/server/ocpi/OCPIFacade.ts +++ b/src/server/ocpi/OCPIFacade.ts @@ -52,7 +52,7 @@ export default class OCPIFacade { // Update OCPI Session await ocpiClient.updateSession(transaction); } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processUpdateTransaction', @@ -120,7 +120,7 @@ export default class OCPIFacade { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'updateConnectorStatus', diff --git a/src/server/ocpi/OCPIUtils.ts b/src/server/ocpi/OCPIUtils.ts index 12387bf34b..296818addf 100644 --- a/src/server/ocpi/OCPIUtils.ts +++ b/src/server/ocpi/OCPIUtils.ts @@ -239,7 +239,7 @@ export default class OCPIUtils { try { await OCPIUtils.updateCreateChargingStationWithEmspLocation(tenant, location, site, siteArea, evse, action); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action, module: MODULE_NAME, method: 'processEMSPLocationChargingStations', message: `Error while processing the EVSE UID '${evse.uid}' (ID '${evse.evse_id}') in Location '${location.name}'`, @@ -265,7 +265,7 @@ export default class OCPIUtils { // Delete Charging Station if (currentChargingStation && evse.status === OCPIEvseStatus.REMOVED) { await ChargingStationStorage.deleteChargingStation(tenant, currentChargingStation.id); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(currentChargingStation), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processEMSPLocationChargingStation', @@ -278,7 +278,7 @@ export default class OCPIUtils { currentChargingStation, evse, location, site, siteArea, action); await ChargingStationStorage.saveChargingStation(tenant, chargingStation); await ChargingStationStorage.saveChargingStationOcpiData(tenant, chargingStation.id, chargingStation.ocpiData); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processEMSPLocationChargingStation', diff --git a/src/server/ocpi/service/OCPIUtilsService.ts b/src/server/ocpi/service/OCPIUtilsService.ts index b25fe7c97d..6119dd29c4 100644 --- a/src/server/ocpi/service/OCPIUtilsService.ts +++ b/src/server/ocpi/service/OCPIUtilsService.ts @@ -321,7 +321,7 @@ export default class OCPIUtilsService { } // Check the CDR if (transaction?.ocpiData?.cdr?.id) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, @@ -333,7 +333,7 @@ export default class OCPIUtilsService { } // Check the Session Status if (transaction?.ocpiData?.session?.status === OCPISessionStatus.COMPLETED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, @@ -445,7 +445,7 @@ export default class OCPIUtilsService { } // Session in the past if (moment(session.last_updated).isBefore(transaction.lastConsumption.timestamp)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, actionOnUser: transaction.userID, diff --git a/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts b/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts index 7de3403615..43e7c1bc55 100644 --- a/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts +++ b/src/server/ocpi/service/common/v2.1.1/CPOEMSPCredentialsService.ts @@ -25,7 +25,7 @@ export default class CPOEMSPCredentialsService { token = req.headers.authorization.split(' ')[1]; } // Log body - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleDeleteCredentials', action, message: 'Received OCPI unregister endpoint', @@ -52,7 +52,7 @@ export default class CPOEMSPCredentialsService { const { tenant, ocpiEndpoint } = req; // Get payload const credential = req.body as OCPICredential; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Received credential object', @@ -73,7 +73,7 @@ export default class CPOEMSPCredentialsService { token = req.headers.authorization.split(' ')[1]; } // Log body - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Received token', @@ -86,7 +86,7 @@ export default class CPOEMSPCredentialsService { ocpiEndpoint.partyId = credential.party_id; ocpiEndpoint.businessDetails = credential.business_details; // Log updated ocpi endpoint - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'OCPI Server found and updated with credential object', @@ -102,7 +102,7 @@ export default class CPOEMSPCredentialsService { }, }); // Log available OCPI Versions - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Available OCPI Versions', @@ -125,7 +125,7 @@ export default class CPOEMSPCredentialsService { ocpiEndpoint.version = version.version; ocpiEndpoint.versionUrl = version.url; // Log correct OCPI service found - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Correct OCPI version found', @@ -149,7 +149,7 @@ export default class CPOEMSPCredentialsService { } }); // Log available OCPI services - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Available OCPI services', @@ -184,7 +184,7 @@ export default class CPOEMSPCredentialsService { // Build credential object const respCredential = await OCPIUtils.buildOcpiCredentialObject(tenant, ocpiEndpoint.localToken, ocpiEndpoint.role, versionUrl); // Log available OCPI Versions - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'handleUpdateCreateCredentials', action, message: 'Response with credential object', diff --git a/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts b/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts index 35e3a31544..ff911b51ea 100644 --- a/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts +++ b/src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts @@ -92,7 +92,7 @@ export default class CPOCommandsService { localToken = await OCPIUtilsService.updateCreateTagWithEmspToken(tenant, startSession.token, localToken, emspUser, action); } if (!localToken?.active || !localToken.ocpiToken?.valid) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, message: `Token ID '${startSession.token.uid}' is either not active or invalid`, @@ -101,7 +101,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (Utils.isNullOrUndefined(localToken.user) || localToken.user?.issuer) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, message: `Invalid user associated to Token ID '${startSession.token.uid}'`, @@ -113,7 +113,7 @@ export default class CPOCommandsService { const chargingStation = await ChargingStationStorage.getChargingStationByOcpiLocationEvseUid( tenant, startSession.location_id, startSession.evse_uid); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, message: `Charging Station with EVSE ID '${startSession.evse_uid}' and Location ID '${startSession.location_id}' does not exist`, @@ -125,7 +125,7 @@ export default class CPOCommandsService { const connectorID = Utils.convertToInt(OCPIUtils.getConnectorIDFromEvseID(startSession.evse_uid)); const connector = Utils.getConnectorFromID(chargingStation, connectorID); if (!connector) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -135,7 +135,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (!chargingStation.issuer || !chargingStation.public) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -146,7 +146,7 @@ export default class CPOCommandsService { } if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.PREPARING) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -162,7 +162,7 @@ export default class CPOCommandsService { (authorization) => authorization.connectorId === connector.connectorId); if (existingAuthorization) { if (OCPIUtils.isAuthorizationValid(existingAuthorization.timestamp)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartSession', action, @@ -203,7 +203,7 @@ export default class CPOCommandsService { } const transaction = await TransactionStorage.getOCPITransactionBySessionID(tenant, stopSession.session_id); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, message: `Transaction with Session ID '${stopSession.session_id}' does not exists`, @@ -212,7 +212,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (!transaction.issuer) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, @@ -222,7 +222,7 @@ export default class CPOCommandsService { return CPOCommandsService.buildOCPIResponse(OCPICommandResponseType.REJECTED); } if (transaction.stop) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, @@ -233,7 +233,7 @@ export default class CPOCommandsService { } const chargingStation = await ChargingStationStorage.getChargingStation(tenant, transaction.chargeBoxID); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopSession', action, @@ -278,7 +278,7 @@ export default class CPOCommandsService { try { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartTransaction', action, @@ -296,7 +296,7 @@ export default class CPOCommandsService { await CPOCommandsService.sendCommandResponse(tenant, action, startSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStartTransaction', action, @@ -311,7 +311,7 @@ export default class CPOCommandsService { try { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopTransaction', action, @@ -328,7 +328,7 @@ export default class CPOCommandsService { await CPOCommandsService.sendCommandResponse(tenant, action, stopSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'remoteStopTransaction', action, @@ -343,7 +343,7 @@ export default class CPOCommandsService { const payload: OCPICommandResponse = { result: responseType }; - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'sendCommandResponse', action, message: `Post command response at ${responseUrl}`, diff --git a/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts b/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts index 6f70ce7f35..4e9002357d 100644 --- a/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts +++ b/src/server/ocpi/service/emsp/v2.1.1/EMSPCommandsService.ts @@ -39,7 +39,7 @@ export default class EMSPCommandsService { case OCPICommandType.RESERVE_NOW: case OCPICommandType.UNLOCK_CONNECTOR: if (req.body?.result !== OCPICommandResponseType.ACCEPTED) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: EMSPCommandsService.getAction(command), message: `OCPI Callback '${req.body?.result as string}' received for Command '${command}' with ID '${commandId}'`, @@ -47,7 +47,7 @@ export default class EMSPCommandsService { detailedMessages: { response: req.body } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, action: EMSPCommandsService.getAction(command), message: `OCPI Callback '${req.body?.result as string}' received for Command '${command}' with ID '${commandId}'`, diff --git a/src/server/ocpp/json/JsonOCPPServer.ts b/src/server/ocpp/json/JsonOCPPServer.ts index a91fc6aeaa..c343f20d32 100644 --- a/src/server/ocpp/json/JsonOCPPServer.ts +++ b/src/server/ocpp/json/JsonOCPPServer.ts @@ -136,13 +136,13 @@ export default class JsonOCPPServer extends OCPPServer { const jsonWebSocket = this.jsonWSConnections.get(`${tenant.id}~${chargingStation.id}`); if (!jsonWebSocket) { const message = 'No opened Web Socket connection found'; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'getChargingStationClient', action: ServerAction.WS_SERVER_CONNECTION, message }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: chargingStation.id, module: MODULE_NAME, method: 'getChargingStationClient', @@ -169,7 +169,7 @@ export default class JsonOCPPServer extends OCPPServer { // INFO: Cannot use Logging in this method as uWebSocket will fail in using req/res objects :S // Check URI (/OCPP16/// or /REST///) if (!url.startsWith('/OCPP16') && !url.startsWith('/REST')) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'onUpgrade', action: ServerAction.WS_SERVER_CONNECTION, @@ -181,7 +181,7 @@ export default class JsonOCPPServer extends OCPPServer { // Check Protocol (ocpp1.6 / rest) const protocol = req.getHeader('sec-websocket-protocol'); if (url.startsWith('/OCPP16') && (protocol !== WSServerProtocol.OCPP16)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'onUpgrade', action: ServerAction.WS_SERVER_CONNECTION, @@ -192,7 +192,7 @@ export default class JsonOCPPServer extends OCPPServer { return; } if (url.startsWith('/REST') && (protocol !== WSServerProtocol.REST)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'onUpgrade', action: ServerAction.WS_SERVER_CONNECTION, @@ -214,7 +214,7 @@ export default class JsonOCPPServer extends OCPPServer { res.writeStatus('500'); res.end(message); this.isDebug() && Logging.logConsoleDebug(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.WS_SERVER_CONNECTION, module: MODULE_NAME, method: 'onUpgrade', @@ -269,7 +269,7 @@ export default class JsonOCPPServer extends OCPPServer { if (protocol === WSServerProtocol.REST) { wsConnection = new JsonRestWSConnection(wsWrapper); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.WS_SERVER_CONNECTION_OPEN, module: MODULE_NAME, method: 'checkAndStoreWSOpenedConnection', message: `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' is being checked ('${wsWrapper.url}')`, @@ -290,13 +290,13 @@ export default class JsonOCPPServer extends OCPPServer { // Check already existing WS Connection await this.checkAndCloseIdenticalOpenedWSConnection(wsWrapper, wsConnection); const message = `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' has been accepted in ${Utils.computeTimeDurationSecs(timeStart)} secs`; - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION_OPEN, module: MODULE_NAME, method: 'checkAndStoreWSOpenedConnection', message, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } }); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getWSWrapperProperties(wsWrapper), action: ServerAction.WS_SERVER_CONNECTION_OPEN, module: MODULE_NAME, method: 'checkAndStoreWSOpenedConnection', message, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } @@ -322,7 +322,7 @@ export default class JsonOCPPServer extends OCPPServer { const result = await this.pingWebSocket(existingWSWrapper); if (result.ok) { // Close the old WS and keep the new incoming one - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION, module: MODULE_NAME, method: 'checkAndCloseIdenticalOpenedWSConnection', @@ -385,14 +385,14 @@ export default class JsonOCPPServer extends OCPPServer { } } catch (error) { const logMessage = `${WebSocketAction.MESSAGE} > WS Connection ID '${wsWrapper.guid}' got error while processing WS Message: ${error.message as string}`; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getWSWrapperProperties(wsWrapper), action: ServerAction.WS_SERVER_MESSAGE, module: MODULE_NAME, method: 'onMessage', message: logMessage, detailedMessages: { message, isBinary, wsWrapper: this.getWSWrapperData(wsWrapper), error: error.stack } }); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -410,7 +410,7 @@ export default class JsonOCPPServer extends OCPPServer { const wsExistingConnection = this.getWSConnectionFromProtocolAndID(wsWrapper.protocol, wsWrapper.key); if (!wsExistingConnection) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -425,7 +425,7 @@ export default class JsonOCPPServer extends OCPPServer { // Should have the same GUID const wsExistingWrapper = wsExistingConnection.getWS(); if (wsExistingWrapper.guid !== wsWrapper.guid) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -436,7 +436,7 @@ export default class JsonOCPPServer extends OCPPServer { // Ping const result = await this.pingWebSocket(wsExistingWrapper); if (result.ok) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -448,7 +448,7 @@ export default class JsonOCPPServer extends OCPPServer { await this.closeWebSocket(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsExistingWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.MESSAGE} > Existing WS Connection ID '${wsExistingWrapper.guid}' has been closed successfully by server (duplicate WS Connection)`); } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_MESSAGE, @@ -465,13 +465,13 @@ export default class JsonOCPPServer extends OCPPServer { private async logWSConnectionClosed(wsWrapper: WSWrapper, action: ServerAction, code: number, message: string): Promise { this.isDebug() && Logging.logConsoleDebug(message); if (wsWrapper.tenantID) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getWSWrapperProperties(wsWrapper), action, module: MODULE_NAME, method: 'logWSConnectionClosed', message: message, detailedMessages: { code, message, wsWrapper: this.getWSWrapperData(wsWrapper) } }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'logWSConnectionClosed', @@ -485,7 +485,7 @@ export default class JsonOCPPServer extends OCPPServer { const maxNumberOfTrials = 10; let numberOfTrials = 0; const timeStart = Date.now(); - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'waitForWSLockToRelease', @@ -500,7 +500,7 @@ export default class JsonOCPPServer extends OCPPServer { numberOfTrials++; // Message has been processed if (!this.runningWSRequestsMessages[wsWrapper.url]) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'waitForWSLockToRelease', @@ -514,7 +514,7 @@ export default class JsonOCPPServer extends OCPPServer { // Handle remaining trial if (numberOfTrials >= maxNumberOfTrials) { // Abnormal situation: The lock should not be taken for so long! - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'waitForWSLockToRelease', @@ -543,7 +543,7 @@ export default class JsonOCPPServer extends OCPPServer { wsWrapper.nbrPingFailed++; // Close WS if (wsWrapper.nbrPingFailed >= Constants.WS_MAX_NBR_OF_FAILED_PINGS) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION_PING, module: MODULE_NAME, method: 'pingWebSocket', @@ -553,7 +553,7 @@ export default class JsonOCPPServer extends OCPPServer { await this.closeWebSocket(WebSocketAction.PING, ServerAction.WS_SERVER_CONNECTION_PING, wsWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.PING} > WS Connection ID '${wsWrapper.guid}' has been closed by server after ${wsWrapper.nbrPingFailed} failed ping`); } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action: ServerAction.WS_SERVER_CONNECTION_PING, module: MODULE_NAME, method: 'pingWebSocket', @@ -577,7 +577,7 @@ export default class JsonOCPPServer extends OCPPServer { await this.logWSConnectionClosed(wsWrapper, action, code, message); } catch (error) { // Just log and ignore issue - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'closeWebSocket', @@ -594,7 +594,7 @@ export default class JsonOCPPServer extends OCPPServer { // Reference a Json WebSocket connection object if (wsWrapper.protocol === WSServerProtocol.OCPP16) { this.jsonWSConnections.set(wsConnection.getID(), wsConnection as JsonWSConnection); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'setWSConnection', @@ -604,7 +604,7 @@ export default class JsonOCPPServer extends OCPPServer { } if (wsWrapper.protocol === WSServerProtocol.REST) { this.jsonRestWSConnections.set(wsConnection.getID(), wsConnection as JsonRestWSConnection); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'setWSConnection', @@ -645,7 +645,7 @@ export default class JsonOCPPServer extends OCPPServer { if (existingWsWrapper.guid === wsWrapper.guid) { // Remove from WS Cache wsConnections.delete(wsConnection.getID()); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'setWSConnection', @@ -654,7 +654,7 @@ export default class JsonOCPPServer extends OCPPServer { }); } else { // WS Connection not identical - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'removeWSConnection', @@ -664,7 +664,7 @@ export default class JsonOCPPServer extends OCPPServer { } } else { // WS Connection not found - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, chargingStationID: wsWrapper.chargingStationID, action, module: MODULE_NAME, method: 'removeWSConnection', @@ -691,7 +691,7 @@ export default class JsonOCPPServer extends OCPPServer { numberOfCurrentRequests += Object.keys(currentOcppRequests).length; } // Log Stats on number of WS Connections - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.WS_SERVER_CONNECTION, module: MODULE_NAME, method: 'monitorWSConnections', message: `${this.jsonWSConnections.size} WS connections, ${this.jsonRestWSConnections.size} REST connections, ${this.runningWSMessages} Messages, ${Object.keys(this.runningWSRequestsMessages).length} Requests, ${this.waitingWSMessages} queued WS Message(s)`, @@ -755,14 +755,14 @@ export default class JsonOCPPServer extends OCPPServer { const message = `Total of ${wsConnectionKeys.length} ${type} WS connection(s) pinged in ${Utils.computeTimeDurationSecs(timeStart)} secs: ${validConnections.length} valid, ${invalidConnections.length} invalid`; this.isDebug() && Logging.logConsoleDebug(message); if (invalidConnections.length) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'checkAndCleanupWebSockets', action: ServerAction.WS_SERVER_CONNECTION_PING, message, detailedMessages: { invalidConnections, /* validConnections */ } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'checkAndCleanupWebSockets', action: ServerAction.WS_SERVER_CONNECTION_PING, diff --git a/src/server/ocpp/json/web-socket/WSConnection.ts b/src/server/ocpp/json/web-socket/WSConnection.ts index 90102d624d..1771993344 100644 --- a/src/server/ocpp/json/web-socket/WSConnection.ts +++ b/src/server/ocpp/json/web-socket/WSConnection.ts @@ -234,7 +234,7 @@ export default abstract class WSConnection { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.siteID, siteAreaID: this.siteAreaID, diff --git a/src/server/ocpp/services/OCPPService.ts b/src/server/ocpp/services/OCPPService.ts index 84439ff8c9..9f0ce8a694 100644 --- a/src/server/ocpp/services/OCPPService.ts +++ b/src/server/ocpp/services/OCPPService.ts @@ -86,7 +86,7 @@ export default class OCPPService { setTimeout(async () => { await OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation); }, Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_BOOT_NOTIFICATION, @@ -126,7 +126,7 @@ export default class OCPPService { heartbeat.timezone = Utils.getTimezone(chargingStation.coordinates); // Save Heart Beat await OCPPStorage.saveHeartbeat(tenant, heartbeat); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleHeartbeat', @@ -156,7 +156,7 @@ export default class OCPPService { this.enrichOCPPRequest(chargingStation, statusNotification, false); // Skip connectorId = 0 case if (statusNotification.connectorId <= 0) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STATUS_NOTIFICATION, @@ -186,7 +186,7 @@ export default class OCPPService { // Handle Charging Station's specificities this.filterMeterValuesOnSpecificChargingStations(tenant, chargingStation, normalizedMeterValues); if (Utils.isEmptyArray(normalizedMeterValues.values)) { - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleMeterValues', @@ -242,7 +242,7 @@ export default class OCPPService { // Yes: Trigger Smart Charging await this.triggerSmartCharging(tenant, chargingStation.siteArea); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_METER_VALUES, @@ -272,7 +272,7 @@ export default class OCPPService { this.enrichAuthorize(user, chargingStation, headers, authorize); // Save await OCPPStorage.saveAuthorize(tenant, authorize); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleAuthorize', @@ -309,7 +309,7 @@ export default class OCPPService { this.enrichOCPPRequest(chargingStation, diagnosticsStatusNotification); // Save it await OCPPStorage.saveDiagnosticsStatusNotification(tenant, diagnosticsStatusNotification); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_DIAGNOSTICS_STATUS_NOTIFICATION, @@ -338,7 +338,7 @@ export default class OCPPService { await ChargingStationStorage.saveChargingStationFirmwareStatus(tenant, chargingStation.id, firmwareStatusNotification.status); // Save it await OCPPStorage.saveFirmwareStatusNotification(tenant, firmwareStatusNotification); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleFirmwareStatusNotification', @@ -395,7 +395,7 @@ export default class OCPPService { await ChargingStationStorage.saveChargingStation(tenant, chargingStation); // Notify NotificationHelper.notifyStartTransaction(tenant, newTransaction, chargingStation, user); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleStartTransaction', @@ -433,7 +433,7 @@ export default class OCPPService { this.enrichOCPPRequest(chargingStation, dataTransfer); // Save it await OCPPStorage.saveDataTransfer(tenant, dataTransfer); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleDataTransfer', @@ -502,7 +502,7 @@ export default class OCPPService { NotificationHelper.notifyStopTransaction(tenant, chargingStation, transaction, user, alternateUser); // Recompute the Smart Charging Plan await this.triggerSmartChargingStopTransaction(tenant, chargingStation, transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'handleStopTransaction', @@ -668,7 +668,7 @@ export default class OCPPService { // Trigger Smart Charging await this.triggerSmartCharging(tenant, chargingStation.siteArea); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'triggerSmartChargingStopTransaction', @@ -692,7 +692,7 @@ export default class OCPPService { for (const chargingProfile of chargingProfiles.result) { try { await OCPPUtils.clearAndDeleteChargingProfile(tenant, chargingProfile); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -701,7 +701,7 @@ export default class OCPPService { detailedMessages: { chargingProfile } }); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -744,7 +744,7 @@ export default class OCPPService { await ChargingStationStorage.saveChargingStation(tenant, chargingStation); // Process Smart Charging await this.processSmartChargingFromStatusNotification(tenant, chargingStation, connector, previousStatus); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'processConnectorStatusNotification', @@ -766,7 +766,7 @@ export default class OCPPService { // Trigger Smart Charging await this.triggerSmartCharging(tenant, chargingStation.siteArea); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'processSmartChargingStatusNotification', @@ -810,7 +810,7 @@ export default class OCPPService { // Same Status Notification? } else if (Utils.objectAllPropertiesAreEqual(statusNotification, connector, ['status', 'info', 'errorCode', 'vendorErrorCode'])) { ignoreStatusNotification = true; - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STATUS_NOTIFICATION, @@ -850,7 +850,7 @@ export default class OCPPService { await TransactionStorage.saveTransaction(tenant, lastTransaction); } } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndUpdateLastCompletedTransactionFromStatusNotification', @@ -862,7 +862,7 @@ export default class OCPPService { // Clear Connector Runtime Data OCPPUtils.clearChargingStationConnectorRuntimeData(chargingStation, lastTransaction.connectorId); } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(lastTransaction), tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndUpdateLastCompletedTransactionFromStatusNotification', @@ -897,7 +897,7 @@ export default class OCPPService { Utils.createDecimal(currentStatusNotifTimestamp.getTime()).minus(transactionStopTimestamp.getTime()).div(1000).floor().toNumber(); // Negative inactivity if (transaction.stop.extraInactivitySecs < 0) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndComputeTransactionExtraInactivityFromStatusNotification', @@ -915,7 +915,7 @@ export default class OCPPService { ); // Build extra inactivity consumption await OCPPUtils.buildAndPriceExtraConsumptionInactivity(tenant, user, chargingStation, transaction); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, user: transaction.userID, @@ -927,7 +927,7 @@ export default class OCPPService { } } else { // No extra inactivity - connector status is not set to FINISHING - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, user: transaction.userID, @@ -961,7 +961,7 @@ export default class OCPPService { if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.FINISHING && // TODO: To remove after fix of ABB bug having Finishing status with an Error Code to avoid spamming Admins connector.errorCode !== ChargePointErrorCode.NO_ERROR) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STATUS_NOTIFICATION, @@ -1192,7 +1192,7 @@ export default class OCPPService { meterValues.values = meterValues.values.filter(async (meterValue) => { // Remove Sample Clock if (meterValue.attribute && meterValue.attribute.context === OCPPReadingContext.SAMPLE_CLOCK) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'filterMeterValuesOnSpecificChargingStations', @@ -1297,7 +1297,7 @@ export default class OCPPService { // Has consumption? if (activeTransaction.currentTotalConsumptionWh <= 0) { // No consumption: delete - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'stopOrDeleteActiveTransactions', @@ -1325,7 +1325,7 @@ export default class OCPPService { }, false, true); if (result.idTagInfo.status === OCPPAuthorizationStatus.INVALID) { // Cannot stop it - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'stopOrDeleteActiveTransactions', @@ -1336,7 +1336,7 @@ export default class OCPPService { }); } else { // Stopped - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'stopOrDeleteActiveTransactions', @@ -1713,7 +1713,7 @@ export default class OCPPService { stopTransaction: OCPPStopTransactionRequestExtended): Promise { // Ignore it (DELTA bug)? if (stopTransaction.transactionId === 0) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'bypassStopTransaction', @@ -1767,7 +1767,7 @@ export default class OCPPService { } // Received Meter Values after the Transaction End Meter Value if (transaction.transactionEndReceived) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'getTransactionFromMeterValues', @@ -1783,7 +1783,7 @@ export default class OCPPService { // Get the OCPP Client const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'abortOngoingTransactionInMeterValues', @@ -1797,7 +1797,7 @@ export default class OCPPService { transactionId: meterValues.transactionId }); if (result.status === OCPPRemoteStartStopStatus.ACCEPTED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'abortOngoingTransactionInMeterValues', @@ -1806,7 +1806,7 @@ export default class OCPPService { detailedMessages: { meterValues } }); } else { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'abortOngoingTransactionInMeterValues', @@ -1867,7 +1867,7 @@ export default class OCPPService { } else if (transaction.lastConsumption) { // The consumption should be the same if (transaction.lastConsumption.value !== stopTransaction.meterStop) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OCPP_STOP_TRANSACTION, diff --git a/src/server/ocpp/soap/SoapOCPPServer.ts b/src/server/ocpp/soap/SoapOCPPServer.ts index 997ecbce44..76ce42f3b6 100644 --- a/src/server/ocpp/soap/SoapOCPPServer.ts +++ b/src/server/ocpp/soap/SoapOCPPServer.ts @@ -72,7 +72,7 @@ export default class SoapOCPPServer extends OCPPServer { } private async handleSoapServerMessage(ocppVersion: OCPPVersion, request: any, methodName: string) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'handleSoapServerMessage', action: ServerAction.EXPRESS_SERVER, @@ -84,7 +84,7 @@ export default class SoapOCPPServer extends OCPPServer { private async handleSoapServerLog(ocppVersion: OCPPVersion, type: string, data: any) { // Do not log 'Info' if (type === 'replied') { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'handleSoapServerLog', action: ServerAction.EXPRESS_SERVER, diff --git a/src/server/ocpp/utils/OCPPCommon.ts b/src/server/ocpp/utils/OCPPCommon.ts index bad25b8252..e26fa1bab5 100644 --- a/src/server/ocpp/utils/OCPPCommon.ts +++ b/src/server/ocpp/utils/OCPPCommon.ts @@ -35,7 +35,7 @@ export default class OCPPCommon { await OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation); } if (triggerConditionalReset && result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -52,7 +52,7 @@ export default class OCPPCommon { try { // Get the OCPP Configuration const ocppConfiguration = await OCPPCommon.requestChargingStationOcppParameters(tenant, chargingStation, {}); - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -90,7 +90,7 @@ export default class OCPPCommon { } // Save configuration await ChargingStationStorage.saveOcppParameters(tenant, chargingStationOcppParameters); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -118,7 +118,7 @@ export default class OCPPCommon { } let resetResult = await chargingStationClient.reset({ type: resetType }); if (resetResult.status === OCPPResetStatus.REJECTED) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_RESET, @@ -126,7 +126,7 @@ export default class OCPPCommon { message: `Error at ${resetType} Rebooting charging station`, }); if (hardResetFallback && resetType !== OCPPResetType.HARD) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_RESET, @@ -135,7 +135,7 @@ export default class OCPPCommon { }); resetResult = await chargingStationClient.reset({ type: OCPPResetType.HARD }); if (resetResult.status === OCPPResetStatus.REJECTED) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_RESET, diff --git a/src/server/ocpp/utils/OCPPUtils.ts b/src/server/ocpp/utils/OCPPUtils.ts index 3be8399e03..82d3f9c022 100644 --- a/src/server/ocpp/utils/OCPPUtils.ts +++ b/src/server/ocpp/utils/OCPPUtils.ts @@ -482,7 +482,7 @@ export default class OCPPUtils { // Meter Value is in the past if (transaction.lastConsumption?.timestamp && meterValue.timestamp && moment(meterValue?.timestamp).isBefore(moment(transaction?.lastConsumption?.timestamp))) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'createConsumptionsFromMeterValues', @@ -795,7 +795,7 @@ export default class OCPPUtils { // Add unknown Connector ID chargingStation.chargePoints[0].connectorIDs.push(connector.connectorId); } - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -821,7 +821,7 @@ export default class OCPPUtils { } // Not found but not master/salve if (!foundTemplateConnector) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -874,7 +874,7 @@ export default class OCPPUtils { await OCPPUtils.setConnectorPhaseAssignment(tenant, chargingStation, connector, numberOfPhases); } // Success - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -885,7 +885,7 @@ export default class OCPPUtils { return true; } // No Connector in Template - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -896,7 +896,7 @@ export default class OCPPUtils { return false; } // No Template - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -920,7 +920,7 @@ export default class OCPPUtils { } public static async applyTemplateOcppParametersToChargingStation(tenant: Tenant, chargingStation: ChargingStation): Promise { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -932,7 +932,7 @@ export default class OCPPUtils { Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS, OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation), `Time out error (${Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS} ms): Cannot update Charging Station with Template's OCPP Parameters`); if (result.status !== OCPPConfigurationStatus.ACCEPTED) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -945,7 +945,7 @@ export default class OCPPUtils { Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS, OCPPUtils.updateChargingStationOcppParametersWithTemplate(tenant, chargingStation), `Time out error (${Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS} ms): Cannot update Charging Station with Template's OCPP Parameters`); if (result.status === OCPPConfigurationStatus.ACCEPTED) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -953,7 +953,7 @@ export default class OCPPUtils { message: 'Charging Station has been successfully updated with Template\'s OCPP Parameters', }); } else { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -984,7 +984,7 @@ export default class OCPPUtils { await this.clearAndDeleteChargingProfile(tenant, chargingProfile); actionsResponse.inSuccess++; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, siteID: chargingProfile.chargingStation?.siteID, siteAreaID: chargingProfile.chargingStation?.siteAreaID, @@ -1039,7 +1039,7 @@ export default class OCPPUtils { try { await chargingStationVendor.clearChargingProfile(tenant, chargingStation, chargingProfile); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -1051,7 +1051,7 @@ export default class OCPPUtils { } // Delete from database await ChargingStationStorage.deleteChargingProfile(tenant, chargingProfile.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_DELETE, @@ -1136,7 +1136,7 @@ export default class OCPPUtils { } // Save const chargingProfileID = await ChargingStationStorage.saveChargingProfile(tenant, chargingProfile); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_PROFILE_UPDATE, @@ -1268,7 +1268,7 @@ export default class OCPPUtils { // Must have a valid connection Token token = await OCPPUtils.ensureChargingStationHasValidConnectionToken(action, tenant, chargingStationID, tokenID); // Ok, set it - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, module: MODULE_NAME, method: 'checkAndGetChargingStationData', @@ -1320,7 +1320,7 @@ export default class OCPPUtils { const currentOcppParameters = (await ChargingStationStorage.getOcppParameters(tenant, chargingStation.id)).result; if (Utils.isEmptyArray(chargingStation.ocppStandardParameters) && Utils.isEmptyArray(chargingStation.ocppVendorParameters)) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1340,7 +1340,7 @@ export default class OCPPUtils { // Check Value if (currentOcppParam && currentOcppParam.value === ocppParameter.value) { // Ok: Already the good value - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1356,7 +1356,7 @@ export default class OCPPUtils { }, false); if (result.status === OCPPConfigurationStatus.ACCEPTED) { updatedOcppParameters.inSuccess++; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1366,7 +1366,7 @@ export default class OCPPUtils { } else if (result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { updatedOcppParameters.inSuccess++; rebootRequired = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1375,7 +1375,7 @@ export default class OCPPUtils { }); } else { updatedOcppParameters.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1385,7 +1385,7 @@ export default class OCPPUtils { } } catch (error) { updatedOcppParameters.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, @@ -1433,7 +1433,7 @@ export default class OCPPUtils { // Log const instantPower = Utils.truncTo(Utils.createDecimal(connector.currentInstantWatts).div(1000).toNumber(), 3); const totalConsumption = Utils.truncTo(Utils.createDecimal(connector.currentTotalConsumptionWh).div(1000).toNumber(), 3); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'updateChargingStationConnectorRuntimeDataWithTransaction', @@ -1512,7 +1512,7 @@ export default class OCPPUtils { }; // Do not apply template if manual configured if (chargingStation.manualConfiguration) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1527,7 +1527,7 @@ export default class OCPPUtils { if (chargingStationTemplate) { // Already updated? if (chargingStation.templateHash !== chargingStationTemplate.hash) { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1550,7 +1550,7 @@ export default class OCPPUtils { // Update chargingStation.templateHash = chargingStationTemplate.hash; templateUpdateResult.chargingStationUpdated = true; - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1559,7 +1559,7 @@ export default class OCPPUtils { detailedMessages: { templateUpdateResult, chargingStationTemplate, chargingStation } }); } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1575,7 +1575,7 @@ export default class OCPPUtils { } } } else { - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1633,7 +1633,7 @@ export default class OCPPUtils { if (matchFirmware && matchOcpp) { for (const parameter in ocppParameters.parameters) { if (OCPPUtils.isOcppParamForPowerLimitationKey(parameter, chargingStation)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1644,7 +1644,7 @@ export default class OCPPUtils { continue; } if (Constants.OCPP_HEARTBEAT_KEYS.includes(parameter)) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1663,7 +1663,7 @@ export default class OCPPUtils { } } // Not found - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, @@ -1710,7 +1710,7 @@ export default class OCPPUtils { } } // Not found - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, diff --git a/src/server/ocpp/validator/OCPPValidator.ts b/src/server/ocpp/validator/OCPPValidator.ts index d04285ee24..a9d05b93ee 100644 --- a/src/server/ocpp/validator/OCPPValidator.ts +++ b/src/server/ocpp/validator/OCPPValidator.ts @@ -112,7 +112,7 @@ export default class OCPPValidator extends SchemaValidator { // Check Connector ID if (meterValues.connectorId === 0) { // KEBA: Connector ID must be > 0 according to OCPP - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenantID, module: MODULE_NAME, method: 'validateMeterValues', @@ -125,7 +125,7 @@ export default class OCPPValidator extends SchemaValidator { // Check if the transaction ID matches with the one on the Connector const foundConnector = Utils.getConnectorFromID(chargingStation, meterValues.connectorId); if (!foundConnector) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenantID, module: MODULE_NAME, method: 'validateMeterValues', @@ -140,7 +140,7 @@ export default class OCPPValidator extends SchemaValidator { if (meterValues.transactionId === 0 && foundConnector.currentTransactionID > 0) { // Reuse Transaction ID from Connector meterValues.transactionId = foundConnector.currentTransactionID; - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenantID, module: MODULE_NAME, method: 'validateMeterValues', diff --git a/src/server/odata/ODataRestAdapter.ts b/src/server/odata/ODataRestAdapter.ts index 648f0d7378..078bd3633c 100644 --- a/src/server/odata/ODataRestAdapter.ts +++ b/src/server/odata/ODataRestAdapter.ts @@ -97,7 +97,7 @@ export default class ODataRestAdapter { } } catch (error) { // Add logging - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.user.tenantID, module: MODULE_NAME, method: 'query', action: ServerAction.ODATA_SERVER, diff --git a/src/server/odata/odata-schema/ODataSchema.ts b/src/server/odata/odata-schema/ODataSchema.ts index e41221636a..a00c038c71 100644 --- a/src/server/odata/odata-schema/ODataSchema.ts +++ b/src/server/odata/odata-schema/ODataSchema.ts @@ -42,7 +42,7 @@ export default class ODataSchema { } } catch (error) { // Add logging: login info - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'getSchema', action: ServerAction.ODATA_SERVER, diff --git a/src/server/oicp/AbstractOICPService.ts b/src/server/oicp/AbstractOICPService.ts index 246baa4acf..b6e25fa560 100644 --- a/src/server/oicp/AbstractOICPService.ts +++ b/src/server/oicp/AbstractOICPService.ts @@ -103,7 +103,7 @@ export default abstract class AbstractOICPService { // Handle request action (endpoint) const endpoint = registeredEndpoints.get(endpointName); if (endpoint) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: endpointName, message: `>> OICP Request ${req.method} ${req.originalUrl}`, @@ -112,7 +112,7 @@ export default abstract class AbstractOICPService { }); const response = await endpoint.process(req, res, next, tenant); if (response) { - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: endpointName, message: `<< OICP Response ${req.method} ${req.originalUrl}`, @@ -121,7 +121,7 @@ export default abstract class AbstractOICPService { }); res.json(response); } else { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: endpointName, message: `<< OICP Endpoint ${req.method} ${req.originalUrl} not implemented`, @@ -139,7 +139,7 @@ export default abstract class AbstractOICPService { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.user && req.user.tenantID ? req.user.tenantID : Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: endpointName, message: `<< OICP Response Error ${req.method} ${req.originalUrl}`, diff --git a/src/server/oicp/OICPFacade.ts b/src/server/oicp/OICPFacade.ts index 3204ac2d68..19f48244fc 100644 --- a/src/server/oicp/OICPFacade.ts +++ b/src/server/oicp/OICPFacade.ts @@ -58,7 +58,7 @@ export default class OICPFacade { // Update OICP Session await oicpClient.updateSession(transaction); } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action, module: MODULE_NAME, method: 'processUpdateTransaction', @@ -128,7 +128,7 @@ export default class OICPFacade { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, module: MODULE_NAME, method: 'updateConnectorStatus', diff --git a/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts b/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts index 876a6dc5a5..1a63f5fa9a 100644 --- a/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts +++ b/src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts @@ -61,7 +61,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { const connector = chargingStationConnector.connector; const chargingStation = chargingStationConnector.chargingStation; if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Charging Station ID '${authorizeRemoteStart.EvseID}' not found`, @@ -70,7 +70,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `EVSE for EvseID '${authorizeRemoteStart.EvseID}' not found`); } if (!connector) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Connector for Charging Station ID '${authorizeRemoteStart.EvseID}' not found`, @@ -79,7 +79,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `EVSE for EvseID '${authorizeRemoteStart.EvseID}' not found`); } if (!chargingStation.issuer || !chargingStation.public) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Charging Station ID '${authorizeRemoteStart.EvseID}' cannot be used with OICP`, @@ -88,7 +88,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `EVSE '${authorizeRemoteStart.EvseID}' cannot be used with OICP`); } if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.PREPARING) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, message: `Charging Station ID '${authorizeRemoteStart.EvseID}' is not available`, @@ -108,7 +108,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { // Check if authorization of different user is valid if (OICPUtils.isAuthorizationValid(existingAuthorization.timestamp)) { // Current remote authorization fails due to valid remote authorization of different user - await Logging.logDebug({ + Logging.beDebug()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, @@ -155,7 +155,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { session.providerID = authorizeRemoteStop.ProviderID; const transaction = await TransactionStorage.getOICPTransactionBySessionID(tenant, authorizeRemoteStop.SessionID); if (!transaction) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, message: `OICP Transaction ID '${authorizeRemoteStop.SessionID}' does not exists`, @@ -164,7 +164,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `Transaction with OICP Transaction ID '${authorizeRemoteStop.SessionID}' does not exists`); } if (!transaction.issuer) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, message: `OICP Transaction ID '${authorizeRemoteStop.SessionID}' has been issued locally`, @@ -173,7 +173,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { return OICPUtils.noSuccess(session, `Transaction with OICP Transaction ID '${authorizeRemoteStop.SessionID}' has been issued locally`); } if (transaction.stop) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, message: `OICP Transaction ID '${authorizeRemoteStop.SessionID}' is already stopped`, @@ -183,7 +183,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { } const chargingStation = await ChargingStationStorage.getChargingStation(tenant, transaction.chargeBoxID); if (!chargingStation) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, @@ -204,7 +204,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { connector: Connector, authorizeRemoteStart: OICPAuthorizeRemoteStartCpoReceive): Promise { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_START, @@ -222,7 +222,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint { private async remoteStopTransaction(tenant: Tenant, chargingStation: ChargingStation, transactionId: number): Promise { const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation); if (!chargingStationClient) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP, diff --git a/src/server/rest/RestServerService.ts b/src/server/rest/RestServerService.ts index 8c25795ee9..b373d1442d 100644 --- a/src/server/rest/RestServerService.ts +++ b/src/server/rest/RestServerService.ts @@ -253,7 +253,7 @@ export default class RestServerService { try { // Parse the action const action = req.params.action as ServerAction; - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, message: `REST Endpoint 'restServiceUtil' should not be used for action '${action}'`, action: ServerAction.DEPRECATED_REST_ENDPOINT, @@ -311,7 +311,7 @@ export default class RestServerService { // Parse the action const action = req.params.action as ServerAction; // Old endpoint: should not be used - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: req.tenant?.id, message: `REST Endpoint 'restServiceSecured' should not be used for action '${action}'`, action: ServerAction.DEPRECATED_REST_ENDPOINT, diff --git a/src/server/rest/v1/service/AssetService.ts b/src/server/rest/v1/service/AssetService.ts index 574f7a6f04..b5875c8ab9 100644 --- a/src/server/rest/v1/service/AssetService.ts +++ b/src/server/rest/v1/service/AssetService.ts @@ -166,7 +166,7 @@ export default class AssetService { res.json(Object.assign({ connectionIsValid: true }, Constants.REST_RESPONSE_SUCCESS)); } catch (error) { // KO - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCheckAssetConnection', @@ -292,7 +292,7 @@ export default class AssetService { // Delete await AssetStorage.deleteAsset(req.tenant, asset.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getAssetProperties(asset), tenantID: req.tenant.id, user: req.user, @@ -422,7 +422,7 @@ export default class AssetService { // Save newAsset.id = await AssetStorage.saveAsset(req.tenant, newAsset); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getAssetProperties(newAsset), tenantID: req.tenant.id, user: req.user, @@ -469,7 +469,7 @@ export default class AssetService { asset.lastChangedOn = new Date(); await AssetStorage.saveAsset(req.tenant, asset); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getAssetProperties(asset), tenantID: req.tenant.id, user: req.user, diff --git a/src/server/rest/v1/service/AuthService.ts b/src/server/rest/v1/service/AuthService.ts index 8a35a2fcd4..d41054d36c 100644 --- a/src/server/rest/v1/service/AuthService.ts +++ b/src/server/rest/v1/service/AuthService.ts @@ -77,7 +77,7 @@ export default class AuthService { // Yes: Check date to reset pass if (user.passwordBlockedUntil && moment(user.passwordBlockedUntil).isBefore(moment())) { // Time elapsed: activate the account again - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.user.tenantID, actionOnUser: user, module: MODULE_NAME, method: 'handleLogIn', action: action, @@ -199,7 +199,7 @@ export default class AuthService { }; await TagStorage.saveTag(req.tenant, tag); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: newUser, action: action, module: MODULE_NAME, @@ -249,7 +249,7 @@ export default class AuthService { const resetHash = Utils.generateUUID(); // Init Password info await UserStorage.saveUserPassword(tenant, user.id, { passwordResetHash: resetHash }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, user: user, action: action, module: MODULE_NAME, @@ -295,7 +295,7 @@ export default class AuthService { if (user.status === UserStatus.LOCKED) { await UserStorage.saveUserStatus(tenant, user.id, UserStatus.ACTIVE); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, user: user, action: action, module: MODULE_NAME, @@ -440,7 +440,7 @@ export default class AuthService { // Save User Verification Account await UserStorage.saveUserAccountVerification(req.tenant, user.id, { verificationToken: null, verifiedAt: new Date() }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: user, action: action, module: MODULE_NAME, method: 'handleVerifyEmail', @@ -517,7 +517,7 @@ export default class AuthService { // Get existing verificationToken verificationToken = user.verificationToken; } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: user, action: action, @@ -590,7 +590,7 @@ export default class AuthService { public static async userLoginSucceeded(action: ServerAction, tenant: Tenant, user: User, req: Request, res: Response, next: NextFunction): Promise { // Password / Login OK - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: tenant.id, user: user, module: MODULE_NAME, method: 'checkUserLogin', diff --git a/src/server/rest/v1/service/BillingService.ts b/src/server/rest/v1/service/BillingService.ts index 98eaad30be..799d5c7355 100644 --- a/src/server/rest/v1/service/BillingService.ts +++ b/src/server/rest/v1/service/BillingService.ts @@ -59,7 +59,7 @@ export default class BillingService { res.json(operationResult); } catch (error) { // Ko - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleClearBillingTestData', @@ -96,7 +96,7 @@ export default class BillingService { res.json(Object.assign({ connectionIsValid: true }, Constants.REST_RESPONSE_SUCCESS)); } catch (error) { // Ko - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCheckBillingConnection', @@ -296,7 +296,7 @@ export default class BillingService { const user: User = await UtilsService.checkAndGetUserAuthorization(req.tenant, req.user, filteredRequest.userID, Action.READ, action); // Invoke the billing implementation const paymentMethods: BillingPaymentMethod[] = await billingImpl.getPaymentMethods(user); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user, action: ServerAction.BILLING_PAYMENT_METHODS, @@ -339,7 +339,7 @@ export default class BillingService { // Invoke the billing implementation const operationResult: BillingOperationResult = await billingImpl.deletePaymentMethod(user, filteredRequest.paymentMethodId); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSite', message: `Payment Method '${filteredRequest.paymentMethodId}' has been deleted successfully`, diff --git a/src/server/rest/v1/service/CarService.ts b/src/server/rest/v1/service/CarService.ts index a589055a5d..b5d5d5d16b 100644 --- a/src/server/rest/v1/service/CarService.ts +++ b/src/server/rest/v1/service/CarService.ts @@ -242,7 +242,7 @@ export default class CarService { }; // Save newCar.id = await CarStorage.saveCar(req.tenant, newCar); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, ...LoggingHelper.getCarProperties(newCar), user: req.user, module: MODULE_NAME, method: 'handleCreateCar', @@ -323,7 +323,7 @@ export default class CarService { if (setDefaultCarToOldUserID) { await CarService.setDefaultCarForUser(req.tenant, setDefaultCarToOldUserID); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, ...LoggingHelper.getCarProperties(car), user: req.user, module: MODULE_NAME, method: 'handleUpdateCar', @@ -405,7 +405,7 @@ export default class CarService { if (car.default) { await CarService.setDefaultCarForUser(req.tenant, car.userID); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getCarProperties(car), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteCar', diff --git a/src/server/rest/v1/service/ChargingStationService.ts b/src/server/rest/v1/service/ChargingStationService.ts index 017d1c9869..d1b3c81494 100644 --- a/src/server/rest/v1/service/ChargingStationService.ts +++ b/src/server/rest/v1/service/ChargingStationService.ts @@ -87,7 +87,7 @@ export default class ChargingStationService { // Check and Apply Charging Station templates await ChargingStationService.checkAndApplyChargingStationTemplate( action, req.tenant, chargingStation, req.user, resetAndApplyTemplate); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, action, user: req.user, module: MODULE_NAME, method: 'handleUpdateChargingStationParams', @@ -164,7 +164,7 @@ export default class ChargingStationService { detailedMessages: { result }, }); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, action, user: req.user, @@ -397,7 +397,7 @@ export default class ChargingStationService { // Delete physically await ChargingStationStorage.deleteChargingStation(req.tenant, chargingStation.id); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteChargingStation', message: `Charging Station '${chargingStation.id}' has been deleted successfully`, @@ -864,7 +864,7 @@ export default class ChargingStationService { } // OCPP Command with status if (Utils.objectHasProperty(result, 'status') && ![OCPPStatus.ACCEPTED, OCPPUnlockStatus.UNLOCKED].includes(result.status)) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, user: req.user, @@ -874,7 +874,7 @@ export default class ChargingStationService { }); } else { // OCPP Command with no status - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, user: req.user, @@ -1321,7 +1321,7 @@ export default class ChargingStationService { result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { // Reboot? if (result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) { - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: req.tenant.id, action, user: req.user, @@ -1389,7 +1389,7 @@ export default class ChargingStationService { await ocpiClient.patchChargingStationStatus(chargingStation, status); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'updateChargingStationRoaming', action, @@ -1421,7 +1421,7 @@ export default class ChargingStationService { site, chargingStation.siteArea, chargingStation, options), actionType); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'updateChargingStationRoaming', action, @@ -1453,7 +1453,7 @@ export default class ChargingStationService { site, siteArea, chargingStation, options), OICPActionType.DELETE); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'deactivateChargingStationRoaming', action, @@ -1690,7 +1690,7 @@ export default class ChargingStationService { detailedMessages: { result: chargingProfiles[index] } }); } - await Logging.logWarning({ + Logging.beWarning()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, action, user, diff --git a/src/server/rest/v1/service/ChargingStationTemplateService.ts b/src/server/rest/v1/service/ChargingStationTemplateService.ts index e749391ed3..c464c7b424 100644 --- a/src/server/rest/v1/service/ChargingStationTemplateService.ts +++ b/src/server/rest/v1/service/ChargingStationTemplateService.ts @@ -34,7 +34,7 @@ export default class ChargingStationTemplateService { } }; newChargingStationTemplate.id = await ChargingStationTemplateStorage.saveChargingStationTemplate(newChargingStationTemplate); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateChargingStationTemplate', message: `ChargingStationTemplate '${newChargingStationTemplate.id}' has been created successfully`, @@ -99,7 +99,7 @@ export default class ChargingStationTemplateService { const chargingStationTemplate = await UtilsService.checkAndGetChargingStationTemplateAuthorization(req.tenant, req.user, chargingStationTemplateID, Action.DELETE, action); // Delete await ChargingStationTemplateStorage.deleteChargingStationTemplate(req.tenant, chargingStationTemplate.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteChargingStationTemplate', message: `Charging Station Template'${chargingStationTemplate.id}' has been deleted successfully`, @@ -129,7 +129,7 @@ export default class ChargingStationTemplateService { chargingStationTemplate.lastChangedOn = new Date(); // Save await ChargingStationTemplateStorage.saveChargingStationTemplate(chargingStationTemplate); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateChargingStationTemplate', message: `'${chargingStationTemplate.id}' has been updated successfully`, diff --git a/src/server/rest/v1/service/CompanyService.ts b/src/server/rest/v1/service/CompanyService.ts index daceb2b644..136f92a69d 100644 --- a/src/server/rest/v1/service/CompanyService.ts +++ b/src/server/rest/v1/service/CompanyService.ts @@ -30,7 +30,7 @@ export default class CompanyService { req.tenant, req.user, companyID, Action.DELETE, action); // Delete await CompanyStorage.deleteCompany(req.tenant, company.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteCompany', message: `Company '${company.name}' has been deleted successfully`, @@ -163,7 +163,7 @@ export default class CompanyService { } // Save newCompany.id = await CompanyStorage.saveCompany(req.tenant, newCompany); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateCompany', message: `Company '${newCompany.id}' has been created successfully`, @@ -203,7 +203,7 @@ export default class CompanyService { company.lastChangedOn = new Date(); // Update Company await CompanyStorage.saveCompany(req.tenant, company, Utils.objectHasProperty(filteredRequest, 'logo') ? true : false); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateCompany', message: `Company '${company.name}' has been updated successfully`, diff --git a/src/server/rest/v1/service/ConnectionService.ts b/src/server/rest/v1/service/ConnectionService.ts index 7f12d1f2fa..aff28cd8d6 100644 --- a/src/server/rest/v1/service/ConnectionService.ts +++ b/src/server/rest/v1/service/ConnectionService.ts @@ -104,7 +104,7 @@ export default class ConnectionService { if (!Utils.isNullOrUndefined(integrationConnector)) { // Create const connection: Connection = await integrationConnector.createConnection(filteredRequest.userId, filteredRequest.data); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateConnection', message: `Connection to '${connection.connectorId}' has been created successfully`, @@ -141,7 +141,7 @@ export default class ConnectionService { // Delete await ConnectionStorage.deleteConnectionById(req.tenant, connection.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: connection.userId, diff --git a/src/server/rest/v1/service/OCPIEndpointService.ts b/src/server/rest/v1/service/OCPIEndpointService.ts index e1b9f77b0d..4ac50d04c3 100644 --- a/src/server/rest/v1/service/OCPIEndpointService.ts +++ b/src/server/rest/v1/service/OCPIEndpointService.ts @@ -34,7 +34,7 @@ export default class OCPIEndpointService { const ocpiEndpoint = await UtilsService.checkAndGetOCPIEndpointAuthorization(req.tenant, req.user, filteredRequest.ID, Action.DELETE, action); // Delete await OCPIEndpointStorage.deleteOcpiEndpoint(req.tenant, ocpiEndpoint.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' has been deleted successfully`, @@ -108,7 +108,7 @@ export default class OCPIEndpointService { status: OCPIRegistrationStatus.NEW } as OCPIEndpoint; const endpointID = await OCPIEndpointStorage.saveOcpiEndpoint(req.tenant, ocpiEndpoint); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateOcpiEndpoint', message: `Ocpi Endpoint '${filteredRequest.name}' has been created successfully`, @@ -132,7 +132,7 @@ export default class OCPIEndpointService { ocpiEndpoint.lastChangedOn = new Date(); // Update OcpiEndpoint await OCPIEndpointStorage.saveOcpiEndpoint(req.tenant, { ...ocpiEndpoint, ...filteredRequest }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' has been updated successfully`, @@ -157,7 +157,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.ping(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handlePingOcpiEndpoint', message: `Ocpi Endpoint '${filteredRequest.name}' can be reached successfully`, @@ -543,7 +543,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.updateCredentials(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateCredentialsOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' can be reached successfully`, @@ -585,7 +585,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.unregister(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUnregisterOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' can be reached successfully`, @@ -627,7 +627,7 @@ export default class OCPIEndpointService { const result = await ocpiClient.register(); // Check ping result if (result.statusCode === StatusCodes.OK) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleRegisterOcpiEndpoint', message: `Ocpi Endpoint '${ocpiEndpoint.name}' can be reached successfully`, @@ -663,7 +663,7 @@ export default class OCPIEndpointService { await AuthorizationService.checkAndGetOCPIEndpointsAuthorizations(req.tenant, req.user, Action.GENERATE_LOCAL_TOKEN); // Generate endpoint const localToken = OCPIUtils.generateLocalToken(req.tenant.subdomain); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleGenerateLocalTokenOcpiEndpoint', message: 'Local Token for Ocpi Endpoint has been generated successfully', diff --git a/src/server/rest/v1/service/OICPEndpointService.ts b/src/server/rest/v1/service/OICPEndpointService.ts index 7934c640a0..887b2c7d9b 100644 --- a/src/server/rest/v1/service/OICPEndpointService.ts +++ b/src/server/rest/v1/service/OICPEndpointService.ts @@ -44,7 +44,7 @@ export default class OICPEndpointService { // Delete await OICPEndpointStorage.deleteOicpEndpoint(req.tenant, oicpEndpoint.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' has been deleted successfully`, @@ -91,7 +91,7 @@ export default class OICPEndpointService { } as OICPEndpoint; const endpointID = await OICPEndpointStorage.saveOicpEndpoint(req.tenant, oicpEndpoint); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateOicpEndpoint', message: `Oicp Endpoint '${filteredRequest.name}' has been created successfully`, @@ -128,7 +128,7 @@ export default class OICPEndpointService { // Update OicpEndpoint await OICPEndpointStorage.saveOicpEndpoint(req.tenant, { ...oicpEndpoint, ...filteredRequest }); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' has been updated successfully`, @@ -293,7 +293,7 @@ export default class OICPEndpointService { // Check ping result if (pingResult.statusCode === OICPStatusCode.Code000) { // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handlePingOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' can be reached successfully`, @@ -303,7 +303,7 @@ export default class OICPEndpointService { res.json(Object.assign(pingResult, Constants.REST_RESPONSE_SUCCESS)); } else { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handlePingOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' cannot be reached`, @@ -341,7 +341,7 @@ export default class OICPEndpointService { // Check ping result if (result.statusCode === StatusCodes.OK) { // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUnregisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' can be reached successfully`, @@ -351,7 +351,7 @@ export default class OICPEndpointService { res.json(Object.assign(result, Constants.REST_RESPONSE_SUCCESS)); } else { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUnregisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' cannot be reached`, @@ -389,7 +389,7 @@ export default class OICPEndpointService { // Check ping result if (result.statusCode === StatusCodes.OK) { // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleRegisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' can be reached successfully`, @@ -399,7 +399,7 @@ export default class OICPEndpointService { res.json(Object.assign(result, Constants.REST_RESPONSE_SUCCESS)); } else { // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleRegisterOicpEndpoint', message: `Oicp Endpoint '${oicpEndpoint.name}' cannot be reached`, diff --git a/src/server/rest/v1/service/PricingService.ts b/src/server/rest/v1/service/PricingService.ts index f4ca032361..e8567210e0 100644 --- a/src/server/rest/v1/service/PricingService.ts +++ b/src/server/rest/v1/service/PricingService.ts @@ -130,7 +130,7 @@ export default class PricingService { // Save newPricingDefinition.id = await PricingStorage.savePricingDefinition(req.tenant, newPricingDefinition); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreatePricingDefinition', message: `Pricing model '${newPricingDefinition.id}' has been created successfully`, @@ -172,7 +172,7 @@ export default class PricingService { // Update Pricing await PricingStorage.savePricingDefinition(req.tenant, pricingDefinition); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdatePricingDefinition', message: `Pricing model '${pricingDefinition.id}' has been updated successfully`, @@ -201,7 +201,7 @@ export default class PricingService { // Delete await PricingStorage.deletePricingDefinition(req.tenant, pricingDefinition.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeletePricingDefinition', message: `Pricing model '${pricingDefinitionID}' has been deleted successfully`, @@ -249,7 +249,7 @@ export default class PricingService { } catch (error) { canCreate = false; if (!(error instanceof AppAuthError)) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'alterCanCreate', message: 'Unexpected error while checking site access permissions', diff --git a/src/server/rest/v1/service/RegistrationTokenService.ts b/src/server/rest/v1/service/RegistrationTokenService.ts index 6a28ef380b..94c4de4ce8 100644 --- a/src/server/rest/v1/service/RegistrationTokenService.ts +++ b/src/server/rest/v1/service/RegistrationTokenService.ts @@ -41,7 +41,7 @@ export default class RegistrationTokenService { }; // Save registrationToken.id = await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateRegistrationToken', @@ -72,7 +72,7 @@ export default class RegistrationTokenService { registrationToken.revocationDate = null; // Save await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateRegistrationToken', @@ -91,7 +91,7 @@ export default class RegistrationTokenService { req.tenant, req.user, registrationTokenID, Action.DELETE, action); // Delete await RegistrationTokenStorage.deleteRegistrationToken(req.tenant, registrationToken.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, @@ -126,7 +126,7 @@ export default class RegistrationTokenService { registrationToken.lastChangedOn = now; // Save await RegistrationTokenStorage.saveRegistrationToken(req.tenant, registrationToken); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getRegistrationTokenProperties(registrationToken), tenantID: req.tenant.id, user: req.user, diff --git a/src/server/rest/v1/service/SettingService.ts b/src/server/rest/v1/service/SettingService.ts index d585d7fb8a..25f86d9f3c 100644 --- a/src/server/rest/v1/service/SettingService.ts +++ b/src/server/rest/v1/service/SettingService.ts @@ -28,7 +28,7 @@ export default class SettingService { // Delete await SettingStorage.deleteSetting(req.tenant, settingID); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSetting', message: `Setting '${setting.identifier}' has been deleted successfully`, @@ -110,7 +110,7 @@ export default class SettingService { // Save Setting filteredRequest.id = await SettingStorage.saveSettings(req.tenant, filteredRequest); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateSetting', message: `Setting '${filteredRequest.identifier}' has been created successfully`, @@ -223,7 +223,7 @@ export default class SettingService { } } // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateSetting', message: `Setting '${filteredRequest.id}' has been updated successfully`, diff --git a/src/server/rest/v1/service/SiteAreaService.ts b/src/server/rest/v1/service/SiteAreaService.ts index 170ded47c4..363736f3ee 100644 --- a/src/server/rest/v1/service/SiteAreaService.ts +++ b/src/server/rest/v1/service/SiteAreaService.ts @@ -50,7 +50,7 @@ export default class SiteAreaService { await SiteAreaStorage.removeAssetsFromSiteArea( req.tenant, filteredRequest.siteAreaID, assets.map((asset) => asset.id)); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, @@ -104,7 +104,7 @@ export default class SiteAreaService { req.tenant, filteredRequest.siteAreaID, chargingStations.map((chargingStation) => chargingStation.id)); } // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, @@ -130,7 +130,7 @@ export default class SiteAreaService { // Update children await SiteAreaStorage.attachSiteAreaChildrenToNewParent(req.tenant, siteArea.id, siteArea.parentSiteAreaID); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSiteArea', @@ -329,7 +329,7 @@ export default class SiteAreaService { req.tenant, rootSiteArea, siteArea, parentSiteArea, subSiteAreasActions); // Save siteArea.id = await SiteAreaStorage.saveSiteArea(req.tenant, siteArea, Utils.objectHasProperty(filteredRequest, 'image')); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateSiteArea', @@ -410,7 +410,7 @@ export default class SiteAreaService { } // Retrigger Smart Charging void SiteAreaService.triggerSmartCharging(req.tenant, action, siteArea); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateSiteArea', @@ -488,7 +488,7 @@ export default class SiteAreaService { await smartCharging.computeAndApplyChargingProfiles(siteArea); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getSiteAreaProperties(siteArea), tenantID: tenant.id, action, module: MODULE_NAME, method: 'triggerSmartCharging', diff --git a/src/server/rest/v1/service/SiteService.ts b/src/server/rest/v1/service/SiteService.ts index 8268b91e57..3c75f35dd0 100644 --- a/src/server/rest/v1/service/SiteService.ts +++ b/src/server/rest/v1/service/SiteService.ts @@ -44,7 +44,7 @@ export default class SiteService { const user = await UtilsService.checkAndGetUserAuthorization(req.tenant, req.user, filteredRequest.userID, Action.READ, action); // Update await SiteStorage.updateSiteUserAdmin(req.tenant, filteredRequest.siteID, filteredRequest.userID, filteredRequest.siteAdmin); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, actionOnUser: user, @@ -70,7 +70,7 @@ export default class SiteService { req.tenant, req.user, filteredRequest.userID, Action.READ, action); // Update await SiteStorage.updateSiteOwner(req.tenant, filteredRequest.siteID, filteredRequest.userID, filteredRequest.siteOwner); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, actionOnUser: user, @@ -111,7 +111,7 @@ export default class SiteService { } else { await SiteStorage.removeUsersFromSite(req.tenant, site.id, users.map((user) => user.id)); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, @@ -169,7 +169,7 @@ export default class SiteService { req.tenant, req.user, siteID, Action.DELETE, action); // Delete await SiteStorage.deleteSite(req.tenant, site.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteSite', @@ -314,7 +314,7 @@ export default class SiteService { } // Save site.id = await SiteStorage.saveSite(req.tenant, site, Utils.objectHasProperty(filteredRequest, 'image')); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateSite', @@ -393,7 +393,7 @@ export default class SiteService { await SiteStorage.saveSite(req.tenant, site, Utils.objectHasProperty(filteredRequest, 'image')); // Update all refs void SiteStorage.updateEntitiesWithOrganizationIDs(req.tenant, site.companyID, filteredRequest.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getSiteProperties(site), tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateSite', diff --git a/src/server/rest/v1/service/TagService.ts b/src/server/rest/v1/service/TagService.ts index 88cbca338d..1b81da2de9 100644 --- a/src/server/rest/v1/service/TagService.ts +++ b/src/server/rest/v1/service/TagService.ts @@ -188,7 +188,7 @@ export default class TagService { await TagStorage.saveTag(req.tenant, newTag); // OCPI void TagService.updateTagRoaming(action, req.tenant, req.user, newTag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(newTag), tenantID: req.tenant.id, action: action, @@ -264,7 +264,7 @@ export default class TagService { await TagStorage.saveTag(req.tenant, tag); // OCPI void TagService.updateTagRoaming(action, req.tenant, req.user, tag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(tag), tenantID: req.tenant.id, action: action, @@ -306,7 +306,7 @@ export default class TagService { // Save await TagStorage.saveTag(req.tenant, tag); void TagService.updateTagRoaming(action, req.tenant, req.user, tag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(tag), tenantID: req.tenant.id, action: action, @@ -382,7 +382,7 @@ export default class TagService { } // OCPI void TagService.updateTagRoaming(action, req.tenant, req.user, tag); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTagProperties(tag), tenantID: req.tenant.id, action: action, @@ -490,7 +490,7 @@ export default class TagService { }, async (error: CSVError) => { // Release the lock await LockingManager.release(importTagsLock); - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportTags', action: action, @@ -562,7 +562,7 @@ export default class TagService { parser.on('error', async (error) => { // Release the lock await LockingManager.release(importTagsLock); - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportTags', action: action, @@ -580,7 +580,7 @@ export default class TagService { } else { // Release the lock await LockingManager.release(importTagsLock); - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportTags', action: action, @@ -629,7 +629,7 @@ export default class TagService { // Handle dup keys result.inSuccess += error.result.nInserted; result.inError += error.writeErrors.length; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'insertTags', action: action, @@ -663,7 +663,7 @@ export default class TagService { } } catch (error) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'deleteTags', action: ServerAction.TAG_DELETE, @@ -708,7 +708,7 @@ export default class TagService { } } catch (error) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'unassignTags', action: ServerAction.TAG_DELETE, @@ -833,7 +833,7 @@ export default class TagService { UserValidatorRest.getInstance().validateUserImportCreateReq(newImportedUser); tagToImport = { ...tagToImport, ...newImportedUser as ImportedTag }; } catch (error) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'processTag', action: action, @@ -846,7 +846,7 @@ export default class TagService { tagsToBeImported.push(tagToImport); return true; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'importTag', action: action, @@ -875,7 +875,7 @@ export default class TagService { }); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndDeleteTagOCPI', action: ServerAction.TAG_DELETE, @@ -898,7 +898,7 @@ export default class TagService { ); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action: action, module: MODULE_NAME, method: 'updateTagOCPI', diff --git a/src/server/rest/v1/service/TenantService.ts b/src/server/rest/v1/service/TenantService.ts index d3fe1b9ab9..523e2e43a8 100644 --- a/src/server/rest/v1/service/TenantService.ts +++ b/src/server/rest/v1/service/TenantService.ts @@ -65,7 +65,7 @@ export default class TenantService { // Remove collection await TenantStorage.deleteTenantDB(tenant.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleDeleteTenant', message: `Tenant '${tenant.name}' has been deleted successfully`, @@ -342,7 +342,7 @@ export default class TenantService { } ); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleCreateTenant', message: `Tenant '${filteredRequest.name}' has been created successfully`, @@ -416,7 +416,7 @@ export default class TenantService { // Update with components await TenantService.updateSettingsWithComponents(filteredRequest, req); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateTenant', message: `Tenant '${filteredRequest.name}' has been updated successfully`, @@ -455,7 +455,7 @@ export default class TenantService { // Update Tenant await TenantStorage.saveTenant(tenant, Utils.objectHasProperty(filteredRequest, 'logo') ? true : false); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, method: 'handleUpdateTenantData', message: `Tenant '${filteredRequest.name}' data has been updated successfully`, diff --git a/src/server/rest/v1/service/TransactionService.ts b/src/server/rest/v1/service/TransactionService.ts index 7c975da756..82488f1429 100644 --- a/src/server/rest/v1/service/TransactionService.ts +++ b/src/server/rest/v1/service/TransactionService.ts @@ -196,7 +196,7 @@ export default class TransactionService { } // Save await TransactionStorage.saveTransactionOcpiData(req.tenant, transaction.id, transaction.ocpiData); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, action, module: MODULE_NAME, method: 'handlePushTransactionCdr', @@ -231,7 +231,7 @@ export default class TransactionService { } // Save await TransactionStorage.saveTransactionOicpData(req.tenant, transaction.id, transaction.oicpData); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, user: req.user, actionOnUser: (transaction.user ?? null), @@ -685,7 +685,7 @@ export default class TransactionService { // Transaction refunded if (refundConnector && !refundConnector.canBeDeleted(transaction)) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: loggedUser.tenantID, user: loggedUser, @@ -698,7 +698,7 @@ export default class TransactionService { // Transaction billed if (billingImpl && transaction.billingData?.stop?.status === BillingStatus.BILLED) { result.inError++; - await Logging.logError({ + Logging.beError()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: loggedUser.tenantID, user: loggedUser, @@ -811,7 +811,7 @@ export default class TransactionService { OCPPUtils.clearChargingStationConnectorRuntimeData(chargingStation, transaction.connectorId); await ChargingStationStorage.saveChargingStationConnectors(req.tenant, chargingStation.id, chargingStation.connectors); } - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, user: req.user, actionOnUser: transaction.userID, @@ -833,7 +833,7 @@ export default class TransactionService { try { await new OCPPService(Configuration.getChargingStationConfig()).softStopTransaction( req.tenant, transaction, chargingStation, chargingStation.siteArea); - await Logging.logInfo({ + Logging.beInfo()?.log({ ...LoggingHelper.getTransactionProperties(transaction), tenantID: req.tenant.id, user: req.user, actionOnUser: transaction.userID, diff --git a/src/server/rest/v1/service/UserService.ts b/src/server/rest/v1/service/UserService.ts index 298e332633..392ecf88f0 100644 --- a/src/server/rest/v1/service/UserService.ts +++ b/src/server/rest/v1/service/UserService.ts @@ -210,7 +210,7 @@ export default class UserService { } else { await UserStorage.removeSitesFromUser(req.tenant, filteredRequest.userID, sites.map((site) => site.id)); } - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, module: MODULE_NAME, @@ -230,7 +230,7 @@ export default class UserService { if (!user.issuer) { // Delete User await UserStorage.deleteUser(req.tenant, user.id); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: user, module: MODULE_NAME, method: 'handleDeleteUser', @@ -250,7 +250,7 @@ export default class UserService { // Delete User await UserStorage.deleteUser(req.tenant, user.id); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: user, module: MODULE_NAME, method: 'handleDeleteUser', @@ -315,7 +315,7 @@ export default class UserService { // Update Billing await UserService.syncUserAndUpdateBillingData(ServerAction.USER_UPDATE, req.tenant, req.user, user); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: user, module: MODULE_NAME, method: 'handleUpdateUser', @@ -353,7 +353,7 @@ export default class UserService { mobileVersion: filteredRequest.mobileVersion, mobileLastChangedOn: new Date() }); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: user, module: MODULE_NAME, method: 'handleUpdateUserMobileData', @@ -573,7 +573,7 @@ export default class UserService { // Release the lock await LockingManager.release(importUsersLock); // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportUsers', action: action, @@ -648,7 +648,7 @@ export default class UserService { // Release the lock await LockingManager.release(importUsersLock); // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportUsers', action: action, @@ -667,7 +667,7 @@ export default class UserService { // Release the lock await LockingManager.release(importUsersLock); // Log - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'handleImportUsers', action: action, @@ -735,7 +735,7 @@ export default class UserService { // Update Billing await UserService.syncUserAndUpdateBillingData(ServerAction.USER_CREATE, req.tenant, req.user, newUser); // Log - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: req.tenant.id, user: req.user, actionOnUser: req.user, module: MODULE_NAME, method: 'handleCreateUser', @@ -754,7 +754,7 @@ export default class UserService { // Handle dup keys result.inSuccess += error.result.nInserted; result.inError += error.writeErrors.length; - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'insertUsers', action: action, @@ -871,7 +871,7 @@ export default class UserService { usersToBeImported.push(newImportedUser); return true; } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: req.tenant.id, module: MODULE_NAME, method: 'importUser', action: action, @@ -892,7 +892,7 @@ export default class UserService { ...await billingImpl.precheckStartTransactionPrerequisites(user)); } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'checkBillingErrorCodes', @@ -959,7 +959,7 @@ export default class UserService { } } } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'checkAndDeleteUserOCPI', @@ -1000,7 +1000,7 @@ export default class UserService { // For performance reasons, the creation of a customer in the billing system should be done in a LAZY mode await billingImpl.synchronizeUser(user); } catch (error) { - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenant.id, action, module: MODULE_NAME, method: 'syncUserAndUpdateBillingData', user: loggedUser, actionOnUser: user, diff --git a/src/server/rest/v1/service/UtilsService.ts b/src/server/rest/v1/service/UtilsService.ts index de6fcbbf88..e1ea01c8a3 100644 --- a/src/server/rest/v1/service/UtilsService.ts +++ b/src/server/rest/v1/service/UtilsService.ts @@ -104,7 +104,7 @@ export default class UtilsService { message: `The Captcha score is too low, got ${response.data.score as string} but expected ${centralSystemRestConfig.captchaScore}`, }); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant?.id, module: MODULE_NAME, action, method, message: `The Captcha score is ${response.data.score as string} (score limit is ${centralSystemRestConfig.captchaScore})`, diff --git a/src/start.ts b/src/start.ts index a1c386e56c..69251ac8f9 100644 --- a/src/start.ts +++ b/src/start.ts @@ -105,7 +105,7 @@ export default class Bootstrap { } else { const message = `Monitoring Server implementation does not exist '${this.monitoringConfig.implementation}'`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.STARTUP, module: MODULE_NAME, method: 'startServers', message @@ -142,7 +142,6 @@ export default class Bootstrap { } - // ------------------------------------------------------------------------- // Start all the Servers // ------------------------------------------------------------------------- @@ -188,7 +187,7 @@ export default class Bootstrap { await this.logDuration(startTimeGlobalMillis, `${serverStarted.join(', ')} server has been started successfully`, ServerAction.BOOTSTRAP_STARTUP); } catch (error) { Logging.logConsoleError(error); - global.database && await Logging.logError({ + global.database && Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.BOOTSTRAP_STARTUP, module: MODULE_NAME, method: 'start', @@ -202,7 +201,7 @@ export default class Bootstrap { const timeStartMillis = Date.now(); Logging.logConsoleDebug(logMessage); if (global.database) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.STARTUP, module: MODULE_NAME, method: 'start', @@ -217,7 +216,7 @@ export default class Bootstrap { logMessage = `${logMessage} in ${timeDurationSecs} secs`; Logging.logConsoleDebug(logMessage); if (global.database) { - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action, module: MODULE_NAME, method: 'start', @@ -303,7 +302,7 @@ export default class Bootstrap { } } catch (error) { Logging.logConsoleError(error.stack); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.STARTUP, module: MODULE_NAME, method: 'startServers', diff --git a/src/storage/mongodb/MongoDBStorage.ts b/src/storage/mongodb/MongoDBStorage.ts index 3d48f3c559..6b6c46011e 100644 --- a/src/storage/mongodb/MongoDBStorage.ts +++ b/src/storage/mongodb/MongoDBStorage.ts @@ -71,7 +71,7 @@ export default class MongoDBStorage { const changeStream = dbCollection.watch([], { fullDocument: 'updateLookup' }); const message = `Database collection '${tenant.id}.${collectionName}' is being watched`; Utils.isDevelopmentEnv() && Logging.logConsoleDebug(message); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenant.id, action: ServerAction.MONGO_DB, message, module: MODULE_NAME, method: 'watchDatabaseCollection' @@ -96,7 +96,7 @@ export default class MongoDBStorage { action: ServerAction.MONGO_DB }); } - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenantID, action: ServerAction.MONGO_DB, message: 'Check of MongoDB database...', @@ -195,7 +195,7 @@ export default class MongoDBStorage { { fields: { deleted: 1, issuer: 1 } }, { fields: { 'connectors.status': 1 } }, ]); - await Logging.logDebug({ + Logging.beDebug()?.log({ tenantID: tenantID, action: ServerAction.MONGO_DB, message: 'Check of MongoDB database done', @@ -319,7 +319,7 @@ export default class MongoDBStorage { this.dbPingFailed++; const message = `${this.dbPingFailed} database ping(s) failed: ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'ping', @@ -393,7 +393,7 @@ export default class MongoDBStorage { } catch (error) { const message = 'Error while checking Database in tenant \'default\''; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -423,7 +423,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error while checking Database in tenant '${tenantId}'`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -458,7 +458,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error in creating collection '${tenantID}.${tenantCollectionName}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -491,7 +491,7 @@ export default class MongoDBStorage { if (Utils.isDevelopmentEnv()) { const message = `Drop index '${databaseIndex.name as string}' in collection ${tenantCollectionName}`; Utils.isDevelopmentEnv() && Logging.logConsoleDebug(message); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -503,7 +503,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error in dropping index '${databaseIndex.name as string}' in '${tenantCollectionName}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -522,7 +522,7 @@ export default class MongoDBStorage { if (Utils.isDevelopmentEnv()) { const message = `Create index ${JSON.stringify(index)} in collection ${tenantCollectionName}`; Utils.isDevelopmentEnv() && Logging.logConsoleDebug(message); - await Logging.logInfo({ + Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -534,7 +534,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Error in creating index '${JSON.stringify(index.fields)}' with options '${JSON.stringify(index.options)}' in '${tenantCollectionName}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', @@ -547,7 +547,7 @@ export default class MongoDBStorage { } catch (error) { const message = `Unexpected error in handling Collection '${tenantID}.${name}': ${error.message as string}`; Logging.logConsoleError(message); - await Logging.logError({ + Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, action: ServerAction.MONGO_DB, module: MODULE_NAME, method: 'handleIndexesInCollection', diff --git a/src/storage/mongodb/SiteAreaStorage.ts b/src/storage/mongodb/SiteAreaStorage.ts index 930e156ec6..809b339f46 100644 --- a/src/storage/mongodb/SiteAreaStorage.ts +++ b/src/storage/mongodb/SiteAreaStorage.ts @@ -131,7 +131,7 @@ export default class SiteAreaStorage { }, Constants.DB_PARAMS_SINGLE_RECORD, projectFields); // No unique key on OCPI Location (avoid create several Site Area with the same location ID) if (siteAreaMDB.count > 1) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, action: ServerAction.UNKNOWN_ACTION, module: MODULE_NAME, method: 'getSiteAreaByOcpiLocationUid', diff --git a/src/storage/mongodb/TagStorage.ts b/src/storage/mongodb/TagStorage.ts index 9c456c41f6..33cae324a0 100644 --- a/src/storage/mongodb/TagStorage.ts +++ b/src/storage/mongodb/TagStorage.ts @@ -24,7 +24,7 @@ export default class TagStorage { const id = Utils.generateTagID(); existingTag = await TagStorage.getTag(tenant, id); if (existingTag) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'findAvailableID', action: ServerAction.TAG_CREATE, diff --git a/src/storage/mongodb/TransactionStorage.ts b/src/storage/mongodb/TransactionStorage.ts index 22d222f2e0..5b9ffdb10f 100644 --- a/src/storage/mongodb/TransactionStorage.ts +++ b/src/storage/mongodb/TransactionStorage.ts @@ -1223,7 +1223,7 @@ export default class TransactionStorage { const id = Utils.getRandomIntSafe(); existingTransaction = await TransactionStorage.getTransaction(tenant, id); if (existingTransaction) { - await Logging.logWarning({ + Logging.beWarning()?.log({ tenantID: tenant.id, module: MODULE_NAME, method: 'findAvailableID', action: ServerAction.TRANSACTION_STARTED, diff --git a/src/utils/Logging.ts b/src/utils/Logging.ts index 68749efea3..e2cd6e2375 100644 --- a/src/utils/Logging.ts +++ b/src/utils/Logging.ts @@ -87,6 +87,14 @@ export default class Logging { if (Logging.isLevelEnabled(expectedLogLevel)) { return new LightLogger(expectedLogLevel); } + // ------------------------------------------------------------------------------ + // ACHTUNG - returns null when the level is disabled + // ------------------------------------------------------------------------------ + // The purpose here is to avoid evaluating the log parameters and thus + // avoid triggering unnecessary garbage collection of log messages + // Make sure to use optional chaining operator (?.) when calling the log method + // ------------------------------------------------------------------------------ + return null; } public static getConfiguration(): LogConfiguration { From 0c74db56d3abf1e376fa37abaecbd09751240688 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Thu, 22 Dec 2022 10:21:52 +0100 Subject: [PATCH 04/11] logger - revert changes to security tests --- test/api/SecurityTest.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/api/SecurityTest.ts b/test/api/SecurityTest.ts index 37c4e8b4f5..70bd70403e 100644 --- a/test/api/SecurityTest.ts +++ b/test/api/SecurityTest.ts @@ -108,7 +108,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing "=") is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -124,7 +124,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing ":") is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -140,7 +140,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing ",") is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -156,7 +156,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing ";") is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -172,7 +172,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and =) is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -188,7 +188,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and :) is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -204,7 +204,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and ,) is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -220,7 +220,7 @@ describe('Security', () => { it( 'Check that sensitive data string (containing spaces and ;) is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -236,7 +236,7 @@ describe('Security', () => { it( 'Check that sensitive data string matching a ws url with registration token is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -250,7 +250,7 @@ describe('Security', () => { } ); it('Check that sensitive data query string is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -263,7 +263,7 @@ describe('Security', () => { checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages)); }); it('Check that client_id field is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -276,7 +276,7 @@ describe('Security', () => { checkSensitiveDataIsObfuscated(JSON.parse(read.data.detailedMessages)); }); it('Check that client_secret field is anonymized', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -291,7 +291,7 @@ describe('Security', () => { it( 'Check that client_id and client_secret are anonymized in object', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -310,7 +310,7 @@ describe('Security', () => { it( 'Check that sensitive data is anonymized in object with string fields', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -344,7 +344,7 @@ describe('Security', () => { it( 'Check that sensitive data is anonymized in object with query string fields', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', @@ -365,7 +365,7 @@ describe('Security', () => { it( 'Check that sensitive data is anonymized in array with strings', async () => { - const logId: string = Logging.beDebug()?.log({ + const logId: string = await Logging.logDebug({ tenantID: testData.credentials.tenantId, action: ServerAction.HTTP_REQUEST, message: 'Just a test', From e323a5ef55837b6fbf4fe3a726846eb6ca60d100 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Thu, 22 Dec 2022 11:34:58 +0100 Subject: [PATCH 05/11] logger - removed cyclic dependency --- src/utils/LightLogger.ts | 19 ------------------- src/utils/Logging.ts | 32 ++++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 src/utils/LightLogger.ts diff --git a/src/utils/LightLogger.ts b/src/utils/LightLogger.ts deleted file mode 100644 index 3637574a16..0000000000 --- a/src/utils/LightLogger.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Log, LogLevel } from '../types/Log'; - -import Logging from './Logging'; - -export default class LightLogger { - - private logLevel: LogLevel; - - public constructor(logLevel: LogLevel) { - this.logLevel = logLevel; - } - - public log(log: Log): void { - log.level = this.logLevel; - log.timestamp = new Date(); - Logging.lightLog(log); - } -} - diff --git a/src/utils/Logging.ts b/src/utils/Logging.ts index e2cd6e2375..6a17160c62 100644 --- a/src/utils/Logging.ts +++ b/src/utils/Logging.ts @@ -10,7 +10,6 @@ import BackendError from '../exception/BackendError'; import Configuration from '../utils/Configuration'; import Constants from './Constants'; import { HTTPError } from '../types/HTTPError'; -import LightLogger from './LightLogger'; import LogConfiguration from '../types/configuration/LogConfiguration'; import LogStorage from '../storage/mongodb/LogStorage'; import { OCPIResult } from '../types/ocpi/OCPIResult'; @@ -29,6 +28,26 @@ import sizeof from 'object-sizeof'; const MODULE_NAME = 'Logging'; +export abstract class AbstractLightLogger { + public abstract log(log: Log): void ; +} + +export class LightLogger extends AbstractLightLogger { + + private logLevel: LogLevel; + + public constructor(logLevel: LogLevel) { + super(); + this.logLevel = logLevel; + } + + public log(log: Log): void { + log.level = this.logLevel; + log.timestamp = new Date(); + Logging.lightLog(log); + } +} + export default class Logging { private static logConfig: LogConfiguration; private static traceConfig: TraceConfiguration; @@ -67,23 +86,23 @@ export default class Logging { Logging.log(log).catch(() => { /* Intentional */ }); } - public static beError(): LightLogger { + public static beError(): AbstractLightLogger { return Logging.beThatLevel(LogLevel.ERROR); } - public static beWarning(): LightLogger { + public static beWarning(): AbstractLightLogger { return Logging.beThatLevel(LogLevel.WARNING); } - public static beInfo(): LightLogger { + public static beInfo(): AbstractLightLogger { return Logging.beThatLevel(LogLevel.INFO); } - public static beDebug(): LightLogger { + public static beDebug(): AbstractLightLogger { return Logging.beThatLevel(LogLevel.DEBUG); } - public static beThatLevel(expectedLogLevel: LogLevel): LightLogger { + public static beThatLevel(expectedLogLevel: LogLevel): AbstractLightLogger { if (Logging.isLevelEnabled(expectedLogLevel)) { return new LightLogger(expectedLogLevel); } @@ -1127,3 +1146,4 @@ export default class Logging { }; } } + From 02257d8c1c5a9551cba1eadeef69c3dcd1dbdcbb Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 27 Dec 2022 13:58:46 +0100 Subject: [PATCH 06/11] logger - disable performance storage --- src/storage/mongodb/PerformanceStorage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/mongodb/PerformanceStorage.ts b/src/storage/mongodb/PerformanceStorage.ts index 99441074e8..78d7be8dba 100644 --- a/src/storage/mongodb/PerformanceStorage.ts +++ b/src/storage/mongodb/PerformanceStorage.ts @@ -8,7 +8,7 @@ import PerformanceRecord from '../../types/Performance'; import PerformanceValidatorStorage from '../validator/PerformanceValidatorStorage'; import Utils from '../../utils/Utils'; -const PERFS_ENABLED = true; +const PERFS_ENABLED = false; // TODO: To remove when switched to k8s with Prometheus export default class PerformanceStorage { From 4304b236bfba397334647a33644e2b1949ef07c9 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 27 Dec 2022 13:59:49 +0100 Subject: [PATCH 07/11] ws - no-misused-promises cleanup --- .../tasks/BillTransactionAsyncTask.ts | 2 +- .../tasks/SynchronizeCarCatalogsAsyncTask.ts | 2 +- src/async-task/tasks/TagsImportAsyncTask.ts | 2 +- src/async-task/tasks/UsersImportAsyncTask.ts | 2 +- .../tasks/ocpi/OCPICheckCdrsAsyncTask.ts | 2 +- .../tasks/ocpi/OCPICheckLocationsAsyncTask.ts | 2 +- .../tasks/ocpi/OCPICheckSessionsAsyncTask.ts | 2 +- .../tasks/ocpi/OCPIPullCdrsAsyncTask.ts | 2 +- .../tasks/ocpi/OCPIPullLocationsAsyncTask.ts | 2 +- .../tasks/ocpi/OCPIPullSessionsAsyncTask.ts | 2 +- .../tasks/ocpi/OCPIPullTokensAsyncTask.ts | 2 +- .../ocpi/OCPIPushEVSEStatusesAsyncTask.ts | 2 +- .../tasks/ocpi/OCPIPushTokensAsyncTask.ts | 2 +- .../ocpp/ChargingStationClientFactory.ts | 2 +- .../json/JsonRestChargingStationClient.ts | 14 +-- .../ocpp/soap/SoapChargingStationClient.ts | 4 +- src/notification/NotificationHandler.ts | 66 ++++++------- .../tasks/AssetGetConsumptionTask.ts | 2 +- .../tasks/BillPendingTransactionTask.ts | 2 +- .../tasks/BillingPeriodicOperationTask.ts | 2 +- .../tasks/CheckChargingStationTemplateTask.ts | 2 +- .../tasks/CheckOfflineChargingStationsTask.ts | 2 +- .../CheckPreparingSessionNotStartedTask.ts | 2 +- ...heckSessionNotStartedAfterAuthorizeTask.ts | 2 +- .../tasks/CheckUserAccountInactivityTask.ts | 2 +- .../tasks/CloseTransactionsInProgressTask.ts | 2 +- .../tasks/DispatchCollectedFundsTask.ts | 2 +- .../tasks/LoggingDatabaseTableCleanupTask.ts | 4 +- src/scheduler/tasks/SynchronizeCarsTask.ts | 2 +- .../SynchronizeRefundTransactionsTask.ts | 4 +- src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts | 4 +- .../tasks/ocpi/OCPICheckLocationsTask.ts | 4 +- .../tasks/ocpi/OCPICheckSessionsTask.ts | 4 +- src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts | 4 +- .../tasks/ocpi/OCPIPullLocationsTask.ts | 4 +- .../tasks/ocpi/OCPIPullSessionsTask.ts | 4 +- .../tasks/ocpi/OCPIPullTokensTask.ts | 4 +- src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts | 2 +- .../tasks/ocpi/OCPIPushEVSEStatusesTask.ts | 4 +- .../tasks/ocpi/OCPIPushTokensTask.ts | 4 +- .../tasks/oicp/OICPPushEvseDataTask.ts | 4 +- .../tasks/oicp/OICPPushEvseStatusTask.ts | 4 +- src/server/ocpi/OCPIServer.ts | 4 +- src/server/ocpp/json/JsonOCPPServer.ts | 93 +++++++++---------- .../services/JsonChargingStationService.ts | 6 +- .../json/web-socket/JsonRestWSConnection.ts | 2 +- src/server/ocpp/services/OCPPService.ts | 21 ++--- src/server/ocpp/utils/OCPPCommon.ts | 2 +- src/server/oicp/AbstractOICPService.ts | 2 +- src/server/rest/RestServerService.ts | 2 +- .../rest/v1/service/TransactionService.ts | 4 +- src/server/rest/v1/service/UtilsService.ts | 4 +- src/utils/Logging.ts | 64 ++++++------- src/utils/RouterUtils.ts | 2 +- 54 files changed, 191 insertions(+), 203 deletions(-) diff --git a/src/async-task/tasks/BillTransactionAsyncTask.ts b/src/async-task/tasks/BillTransactionAsyncTask.ts index 4773e42844..ab5eb4992a 100644 --- a/src/async-task/tasks/BillTransactionAsyncTask.ts +++ b/src/async-task/tasks/BillTransactionAsyncTask.ts @@ -53,7 +53,7 @@ export default class BillTransactionAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_TRANSACTION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_TRANSACTION, error); } } } diff --git a/src/async-task/tasks/SynchronizeCarCatalogsAsyncTask.ts b/src/async-task/tasks/SynchronizeCarCatalogsAsyncTask.ts index 32b541be11..4930a81fe0 100644 --- a/src/async-task/tasks/SynchronizeCarCatalogsAsyncTask.ts +++ b/src/async-task/tasks/SynchronizeCarCatalogsAsyncTask.ts @@ -24,7 +24,7 @@ export default class SynchronizeCarCatalogsAsyncTask extends AbstractAsyncTask { await carDatabaseImpl.synchronizeCarCatalogs(); } catch (error) { // Log error - await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT_ID, ServerAction.SYNCHRONIZE_CAR_CATALOGS, error); + Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT_ID, ServerAction.SYNCHRONIZE_CAR_CATALOGS, error); } finally { // Release the lock await LockingManager.release(syncCarCatalogsLock); diff --git a/src/async-task/tasks/TagsImportAsyncTask.ts b/src/async-task/tasks/TagsImportAsyncTask.ts index d4f41cfcb2..c127618fce 100644 --- a/src/async-task/tasks/TagsImportAsyncTask.ts +++ b/src/async-task/tasks/TagsImportAsyncTask.ts @@ -95,7 +95,7 @@ export default class TagsImportAsyncTask extends AbstractAsyncTask { ); } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.TAGS_IMPORT, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.TAGS_IMPORT, error); } finally { // Release the lock await LockingManager.release(importTagsLock); diff --git a/src/async-task/tasks/UsersImportAsyncTask.ts b/src/async-task/tasks/UsersImportAsyncTask.ts index 000411d703..38c987d71a 100644 --- a/src/async-task/tasks/UsersImportAsyncTask.ts +++ b/src/async-task/tasks/UsersImportAsyncTask.ts @@ -95,7 +95,7 @@ export default class UsersImportAsyncTask extends AbstractAsyncTask { ); } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.USERS_IMPORT, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.USERS_IMPORT, error); } finally { // Release the lock await LockingManager.release(importUsersLock); diff --git a/src/async-task/tasks/ocpi/OCPICheckCdrsAsyncTask.ts b/src/async-task/tasks/ocpi/OCPICheckCdrsAsyncTask.ts index 65800f53f4..82083f0913 100644 --- a/src/async-task/tasks/ocpi/OCPICheckCdrsAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPICheckCdrsAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPICheckCdrsAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_CDRS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_CDRS, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPICheckLocationsAsyncTask.ts b/src/async-task/tasks/ocpi/OCPICheckLocationsAsyncTask.ts index 928b3648e4..310f4e27f5 100644 --- a/src/async-task/tasks/ocpi/OCPICheckLocationsAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPICheckLocationsAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPICheckLocationsAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_LOCATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_LOCATIONS, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPICheckSessionsAsyncTask.ts b/src/async-task/tasks/ocpi/OCPICheckSessionsAsyncTask.ts index a209e6bd01..9e81159897 100644 --- a/src/async-task/tasks/ocpi/OCPICheckSessionsAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPICheckSessionsAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPICheckSessionsAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPIPullCdrsAsyncTask.ts b/src/async-task/tasks/ocpi/OCPIPullCdrsAsyncTask.ts index 455e54ff56..2f31e395fc 100644 --- a/src/async-task/tasks/ocpi/OCPIPullCdrsAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPIPullCdrsAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPIPullCdrsAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_CDR, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_CDR, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPIPullLocationsAsyncTask.ts b/src/async-task/tasks/ocpi/OCPIPullLocationsAsyncTask.ts index 776dc047be..f1ede60d02 100644 --- a/src/async-task/tasks/ocpi/OCPIPullLocationsAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPIPullLocationsAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPIPullLocationsAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_LOCATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_LOCATIONS, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPIPullSessionsAsyncTask.ts b/src/async-task/tasks/ocpi/OCPIPullSessionsAsyncTask.ts index e670b9af5b..9e0bea587c 100644 --- a/src/async-task/tasks/ocpi/OCPIPullSessionsAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPIPullSessionsAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPIPullSessionsAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_SESSION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_SESSION, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPIPullTokensAsyncTask.ts b/src/async-task/tasks/ocpi/OCPIPullTokensAsyncTask.ts index 2dd5c1df39..d265cb715a 100644 --- a/src/async-task/tasks/ocpi/OCPIPullTokensAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPIPullTokensAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPIPullTokensAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_GET_TOKENS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_GET_TOKENS, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPIPushEVSEStatusesAsyncTask.ts b/src/async-task/tasks/ocpi/OCPIPushEVSEStatusesAsyncTask.ts index 5e87c3e77e..e158d70e32 100644 --- a/src/async-task/tasks/ocpi/OCPIPushEVSEStatusesAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPIPushEVSEStatusesAsyncTask.ts @@ -35,7 +35,7 @@ export default class OCPIPushEVSEStatusesAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_UPDATE_STATUS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_UPDATE_STATUS, error); } } } diff --git a/src/async-task/tasks/ocpi/OCPIPushTokensAsyncTask.ts b/src/async-task/tasks/ocpi/OCPIPushTokensAsyncTask.ts index ed9d850793..f2a203fdf3 100644 --- a/src/async-task/tasks/ocpi/OCPIPushTokensAsyncTask.ts +++ b/src/async-task/tasks/ocpi/OCPIPushTokensAsyncTask.ts @@ -36,7 +36,7 @@ export default class OCPIPushTokensAsyncTask extends AbstractAsyncTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_UPDATE_TOKENS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_UPDATE_TOKENS, error); } } } diff --git a/src/client/ocpp/ChargingStationClientFactory.ts b/src/client/ocpp/ChargingStationClientFactory.ts index df1729fd85..1e488e9cb1 100644 --- a/src/client/ocpp/ChargingStationClientFactory.ts +++ b/src/client/ocpp/ChargingStationClientFactory.ts @@ -17,7 +17,7 @@ export default class ChargingStationClientFactory { // Json Server if (global.centralSystemJsonServer?.hasChargingStationConnected(tenant, chargingStation)) { // Get the local WS Connection Client - chargingClient = await global.centralSystemJsonServer.getChargingStationClient(tenant, chargingStation); + chargingClient = global.centralSystemJsonServer.getChargingStationClient(tenant, chargingStation); } else { // Get the Remote WS Connection Client (Rest) chargingClient = new JsonRestChargingStationClient(tenant.id, chargingStation); diff --git a/src/client/ocpp/json/JsonRestChargingStationClient.ts b/src/client/ocpp/json/JsonRestChargingStationClient.ts index 58fcce968b..a6cbb72277 100644 --- a/src/client/ocpp/json/JsonRestChargingStationClient.ts +++ b/src/client/ocpp/json/JsonRestChargingStationClient.ts @@ -143,8 +143,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient // Create and Open the WS this.wsConnection = new WSClient(this.serverURL, wsClientOptions); // Opened - // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.wsConnection.onopen = async () => { + this.wsConnection.onopen = () => { Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, @@ -159,8 +158,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient resolve(); }; // Closed - // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.wsConnection.onclose = async (code: number) => { + this.wsConnection.onclose = (code: number) => { Logging.beInfo()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, @@ -174,8 +172,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient }); }; // Handle Error Message - // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.wsConnection.onerror = async (error: Error) => { + this.wsConnection.onerror = (error: Error) => { Logging.beError()?.log({ tenantID: this.tenantID, siteID: this.chargingStation.siteID, @@ -192,8 +189,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient reject(new Error(`Error on opening Web Socket connection: ${error.message}'`)); }; // Handle Server Message - // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.wsConnection.onmessage = async (message) => { + this.wsConnection.onmessage = (message) => { try { // Parse the message const [messageType, messageId, command, commandPayload, errorDetails]: OCPPIncomingRequest = JSON.parse(message.data) as OCPPIncomingRequest; @@ -237,7 +233,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient }); } } catch (error) { - await Logging.logException(error as Error, ServerAction.WS_CLIENT_MESSAGE, MODULE_NAME, 'onMessage', this.tenantID); + Logging.logException(error as Error, ServerAction.WS_CLIENT_MESSAGE, MODULE_NAME, 'onMessage', this.tenantID); } }; } catch (error) { diff --git a/src/client/ocpp/soap/SoapChargingStationClient.ts b/src/client/ocpp/soap/SoapChargingStationClient.ts index d6437c9c2a..df32e4399f 100644 --- a/src/client/ocpp/soap/SoapChargingStationClient.ts +++ b/src/client/ocpp/soap/SoapChargingStationClient.ts @@ -39,7 +39,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { break; default: // Log - void Logging.logError({ + Logging.beError()?.log({ tenantID: scsc.tenant.id, action: ServerAction.CHARGING_STATION_CLIENT_INITIALIZATION, siteID: scsc.chargingStation.siteID, @@ -54,7 +54,7 @@ export default class SoapChargingStationClient extends ChargingStationClient { // Client options const options: any = {}; // Create SOAP client - soap.createClient(chargingStationWdsl, options, async (error, client) => { + soap.createClient(chargingStationWdsl, options, (error, client) => { if (error) { Logging.beError()?.log({ tenantID: scsc.tenant.id, diff --git a/src/notification/NotificationHandler.ts b/src/notification/NotificationHandler.ts index a9cb7e43b6..950e147218 100644 --- a/src/notification/NotificationHandler.ts +++ b/src/notification/NotificationHandler.ts @@ -70,7 +70,7 @@ export default class NotificationHandler { } return false; } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.NOTIFICATION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.NOTIFICATION, error); } } @@ -87,7 +87,7 @@ export default class NotificationHandler { ); return notifications.count > 0; } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.NOTIFICATION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.NOTIFICATION, error); } } @@ -129,7 +129,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.END_OF_CHARGE, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.END_OF_CHARGE, error); } } } @@ -174,7 +174,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OPTIMAL_CHARGE_REACHED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OPTIMAL_CHARGE_REACHED, error); } } } @@ -219,7 +219,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.END_OF_SESSION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.END_OF_SESSION, error); } } } @@ -264,7 +264,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.END_OF_SESSION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.END_OF_SESSION, error); } } } @@ -285,7 +285,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendRequestPassword( sourceData, user, tenant, NotificationSeverity.INFO); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.REQUEST_PASSWORD, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.REQUEST_PASSWORD, error); } } } @@ -309,7 +309,7 @@ export default class NotificationHandler { sourceData, user, tenant, NotificationSeverity.WARNING); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_STATUS_CHANGED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_STATUS_CHANGED, error); } } } @@ -331,7 +331,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendNewRegisteredUser( sourceData, user, tenant, NotificationSeverity.INFO); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.NEW_REGISTERED_USER, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.NEW_REGISTERED_USER, error); } } } @@ -352,7 +352,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendAccountVerificationNotification( sourceData, user, tenant, NotificationSeverity.INFO); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_VERIFICATION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_VERIFICATION, error); } } } @@ -388,7 +388,7 @@ export default class NotificationHandler { sourceData, adminUser, tenant, NotificationSeverity.INFO); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.ADMIN_ACCOUNT_VERIFICATION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.ADMIN_ACCOUNT_VERIFICATION, error); } } } @@ -426,7 +426,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.VERIFY_EMAIL, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.VERIFY_EMAIL, error); } } } @@ -450,7 +450,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendVerificationEmailUserImport( sourceData, user, tenant, NotificationSeverity.INFO); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.VERIFICATION_EMAIL_USER_IMPORT, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.VERIFICATION_EMAIL_USER_IMPORT, error); } } } @@ -499,7 +499,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_STATUS_ERROR, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_STATUS_ERROR, error); } } } @@ -527,7 +527,7 @@ export default class NotificationHandler { sourceData, adminUser, tenant, NotificationSeverity.WARNING); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_REGISTERED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_REGISTERED, error); } } } @@ -555,7 +555,7 @@ export default class NotificationHandler { sourceData, adminUser, tenant, NotificationSeverity.WARNING); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.UNKNOWN_USER_BADGED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.UNKNOWN_USER_BADGED, error); } } } @@ -603,7 +603,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.TRANSACTION_STARTED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.TRANSACTION_STARTED, error); } } } @@ -651,7 +651,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PATCH_EVSE_STATUS_ERROR, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PATCH_EVSE_STATUS_ERROR, error); } } } @@ -695,7 +695,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PATCH_EVSE_STATUS_ERROR, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PATCH_EVSE_STATUS_ERROR, error); } } } @@ -739,7 +739,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PATCH_EVSE_ERROR, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PATCH_EVSE_ERROR, error); } } } @@ -775,7 +775,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_INACTIVITY, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_INACTIVITY, error); } } } @@ -820,7 +820,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PREPARING_SESSION_NOT_STARTED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PREPARING_SESSION_NOT_STARTED, error); } } } @@ -863,7 +863,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OFFLINE_CHARGING_STATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OFFLINE_CHARGING_STATIONS, error); } } } @@ -906,7 +906,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_USER_SYNCHRONIZATION_FAILED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_USER_SYNCHRONIZATION_FAILED, error); } } } @@ -949,7 +949,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_USER_SYNCHRONIZATION_FAILED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_USER_SYNCHRONIZATION_FAILED, error); } } } @@ -992,7 +992,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_PERFORM_OPERATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_PERFORM_OPERATIONS, error); } } } @@ -1035,7 +1035,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT_ID, ServerAction.CAR_CATALOG_SYNCHRONIZATION_FAILED, error); + Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT_ID, ServerAction.CAR_CATALOG_SYNCHRONIZATION_FAILED, error); } } } @@ -1080,7 +1080,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.COMPUTE_AND_APPLY_CHARGING_PROFILES_FAILED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.COMPUTE_AND_APPLY_CHARGING_PROFILES_FAILED, error); } } } @@ -1114,7 +1114,7 @@ export default class NotificationHandler { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.END_USER_REPORT_ERROR, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.END_USER_REPORT_ERROR, error); } } } @@ -1155,7 +1155,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.SESSION_NOT_STARTED_AFTER_AUTHORIZE, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.SESSION_NOT_STARTED_AFTER_AUTHORIZE, error); } } } @@ -1194,7 +1194,7 @@ export default class NotificationHandler { }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_NEW_INVOICE, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_NEW_INVOICE, error); } } } @@ -1216,7 +1216,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendBillingAccountCreationLink( sourceData, user, tenant, NotificationSeverity.INFO); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_ACCOUNT_CREATE, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_ACCOUNT_CREATE, error); } } } @@ -1238,7 +1238,7 @@ export default class NotificationHandler { await notificationSource.notificationTask.sendBillingAccountActivationNotification( sourceData, user, tenant, NotificationSeverity.INFO); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_ACCOUNT_ACTIVATE, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_ACCOUNT_ACTIVATE, error); } } } diff --git a/src/scheduler/tasks/AssetGetConsumptionTask.ts b/src/scheduler/tasks/AssetGetConsumptionTask.ts index 8344dae8d2..214d2e081b 100644 --- a/src/scheduler/tasks/AssetGetConsumptionTask.ts +++ b/src/scheduler/tasks/AssetGetConsumptionTask.ts @@ -89,7 +89,7 @@ export default class AssetGetConsumptionTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.RETRIEVE_ASSET_CONSUMPTION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.RETRIEVE_ASSET_CONSUMPTION, error); } finally { // Release the lock await LockingManager.release(assetLock); diff --git a/src/scheduler/tasks/BillPendingTransactionTask.ts b/src/scheduler/tasks/BillPendingTransactionTask.ts index e98b0cec69..d01610f81e 100644 --- a/src/scheduler/tasks/BillPendingTransactionTask.ts +++ b/src/scheduler/tasks/BillPendingTransactionTask.ts @@ -142,7 +142,7 @@ export default class BillPendingTransactionTask extends TenantSchedulerTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_BILL_PENDING_TRANSACTION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_BILL_PENDING_TRANSACTION, error); } } } diff --git a/src/scheduler/tasks/BillingPeriodicOperationTask.ts b/src/scheduler/tasks/BillingPeriodicOperationTask.ts index 13deb18d09..756299d923 100644 --- a/src/scheduler/tasks/BillingPeriodicOperationTask.ts +++ b/src/scheduler/tasks/BillingPeriodicOperationTask.ts @@ -32,7 +32,7 @@ export default class BillingPeriodicOperationTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_PERFORM_OPERATIONS, error as Error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_PERFORM_OPERATIONS, error as Error); } finally { // Release the lock await LockingManager.release(billingLock); diff --git a/src/scheduler/tasks/CheckChargingStationTemplateTask.ts b/src/scheduler/tasks/CheckChargingStationTemplateTask.ts index ae7c68c04d..b2e8ac039d 100644 --- a/src/scheduler/tasks/CheckChargingStationTemplateTask.ts +++ b/src/scheduler/tasks/CheckChargingStationTemplateTask.ts @@ -22,7 +22,7 @@ export default class CheckChargingStationTemplateTask extends TenantSchedulerTas await this.applyTemplateToChargingStations(tenant); } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.UPDATE_CHARGING_STATION_WITH_TEMPLATE, error); } finally { // Release the lock await LockingManager.release(checkChargingStationTemplateLock); diff --git a/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts b/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts index 8067f870a4..604b17b2f4 100644 --- a/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts +++ b/src/scheduler/tasks/CheckOfflineChargingStationsTask.ts @@ -79,7 +79,7 @@ export default class CheckOfflineChargingStationsTask extends TenantSchedulerTas } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OFFLINE_CHARGING_STATION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OFFLINE_CHARGING_STATION, error); } finally { // Release the lock await LockingManager.release(offlineChargingStationLock); diff --git a/src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts b/src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts index c4b400da8d..ce6d637d1c 100644 --- a/src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts +++ b/src/scheduler/tasks/CheckPreparingSessionNotStartedTask.ts @@ -52,7 +52,7 @@ export default class CheckPreparingSessionNotStartedTask extends TenantScheduler } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PREPARING_SESSION_NOT_STARTED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PREPARING_SESSION_NOT_STARTED, error); } finally { // Release the lock await LockingManager.release(sessionNotStartedLock); diff --git a/src/scheduler/tasks/CheckSessionNotStartedAfterAuthorizeTask.ts b/src/scheduler/tasks/CheckSessionNotStartedAfterAuthorizeTask.ts index 267a1472bf..cf245bfec0 100644 --- a/src/scheduler/tasks/CheckSessionNotStartedAfterAuthorizeTask.ts +++ b/src/scheduler/tasks/CheckSessionNotStartedAfterAuthorizeTask.ts @@ -37,7 +37,7 @@ export default class CheckSessionNotStartedAfterAuthorizeTask extends TenantSche } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PREPARING_SESSION_NOT_STARTED, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PREPARING_SESSION_NOT_STARTED, error); } finally { // Release the lock await LockingManager.release(sessionNotStartedLock); diff --git a/src/scheduler/tasks/CheckUserAccountInactivityTask.ts b/src/scheduler/tasks/CheckUserAccountInactivityTask.ts index 3f4e910c4d..e884f2854d 100644 --- a/src/scheduler/tasks/CheckUserAccountInactivityTask.ts +++ b/src/scheduler/tasks/CheckUserAccountInactivityTask.ts @@ -41,7 +41,7 @@ export default class CheckUserAccountInactivityTask extends TenantSchedulerTask } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_INACTIVITY, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.USER_ACCOUNT_INACTIVITY, error); } finally { // Release the lock await LockingManager.release(accountInactivityLock); diff --git a/src/scheduler/tasks/CloseTransactionsInProgressTask.ts b/src/scheduler/tasks/CloseTransactionsInProgressTask.ts index e80c721435..9cf23a89d3 100644 --- a/src/scheduler/tasks/CloseTransactionsInProgressTask.ts +++ b/src/scheduler/tasks/CloseTransactionsInProgressTask.ts @@ -64,7 +64,7 @@ export default class CloseTransactionsInProgressTask extends TenantSchedulerTask `No Transaction have been soft stopped in ${executionDurationSecs}s in Tenant ${Utils.buildTenantName(tenant)}` ); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.TRANSACTION_SOFT_STOP, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.TRANSACTION_SOFT_STOP, error); } finally { // Release the lock await LockingManager.release(transactionsCloseLock); diff --git a/src/scheduler/tasks/DispatchCollectedFundsTask.ts b/src/scheduler/tasks/DispatchCollectedFundsTask.ts index 96a3ed3791..1bd8bd8d1d 100644 --- a/src/scheduler/tasks/DispatchCollectedFundsTask.ts +++ b/src/scheduler/tasks/DispatchCollectedFundsTask.ts @@ -31,7 +31,7 @@ export default class DispatchCollectedFundsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_TRANSFER_DISPATCH_FUNDS, error as Error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.BILLING_TRANSFER_DISPATCH_FUNDS, error as Error); } finally { // Release the lock await LockingManager.release(billingLock); diff --git a/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts b/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts index c88e9b0803..a22598b055 100644 --- a/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts +++ b/src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts @@ -63,7 +63,7 @@ export default class LoggingDatabaseTableCleanupTask extends TenantSchedulerTask }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.LOGS_CLEANUP, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.LOGS_CLEANUP, error); } finally { await LockingManager.release(logsCleanUpLock); } @@ -106,7 +106,7 @@ export default class LoggingDatabaseTableCleanupTask extends TenantSchedulerTask }); } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.PERFORMANCES_CLEANUP, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.PERFORMANCES_CLEANUP, error); } finally { // Release the lock await LockingManager.release(performanceCleanUpLock); diff --git a/src/scheduler/tasks/SynchronizeCarsTask.ts b/src/scheduler/tasks/SynchronizeCarsTask.ts index 354aa8523f..788047442f 100644 --- a/src/scheduler/tasks/SynchronizeCarsTask.ts +++ b/src/scheduler/tasks/SynchronizeCarsTask.ts @@ -27,7 +27,7 @@ export default class SynchronizeCarsTask extends SchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT_ID, ServerAction.SYNCHRONIZE_CAR_CATALOGS, error); + Logging.logActionExceptionMessage(Constants.DEFAULT_TENANT_ID, ServerAction.SYNCHRONIZE_CAR_CATALOGS, error); } finally { // Release the lock await LockingManager.release(syncCarCatalogLock); diff --git a/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts b/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts index bc5d113526..7847be165b 100644 --- a/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts +++ b/src/scheduler/tasks/SynchronizeRefundTransactionsTask.ts @@ -74,7 +74,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa } } catch (error) { actionsDone.error++; - await Logging.logActionExceptionMessage(tenant.id, ServerAction.SYNCHRONIZE_REFUND, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.SYNCHRONIZE_REFUND, error); } } // Log result @@ -95,7 +95,7 @@ export default class SynchronizeRefundTransactionsTask extends TenantSchedulerTa } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.SYNCHRONIZE_REFUND, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.SYNCHRONIZE_REFUND, error); } finally { // Release the lock await LockingManager.release(refundLock); diff --git a/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts index c97a997b86..dae33530e9 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckCdrsTask.ts @@ -29,7 +29,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_CDRS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_CDRS, error); } } @@ -75,7 +75,7 @@ export default class OCPICheckCdrsTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_CDRS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_CDRS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts index 36c4703434..bf30916b88 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckLocationsTask.ts @@ -29,7 +29,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); } } @@ -75,7 +75,7 @@ export default class OCPICheckLocationsTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_LOCATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_LOCATIONS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts b/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts index f5a76dd3a4..944ef33f63 100644 --- a/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPICheckSessionsTask.ts @@ -29,7 +29,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); } } @@ -75,7 +75,7 @@ export default class OCPICheckSessionsTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_CHECK_SESSIONS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts index e0d03d77e7..a8cacb6987 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullCdrsTask.ts @@ -29,7 +29,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_CDRS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_CDRS, error); } } @@ -76,7 +76,7 @@ export default class OCPIPullCdrsTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_CDRS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_CDRS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts index 92a29b972f..72ef8cb1ab 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullLocationsTask.ts @@ -29,7 +29,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_LOCATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_LOCATIONS, error); } } @@ -75,7 +75,7 @@ export default class OCPIPullLocationsTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_LOCATIONS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_LOCATIONS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts b/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts index 85e93a6de6..03c7772858 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullSessionsTask.ts @@ -29,7 +29,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_SESSION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_SESSION, error); } } @@ -75,7 +75,7 @@ export default class OCPIPullSessionsTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_SESSION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_GET_SESSION, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts b/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts index 6716a17dde..04076b174e 100644 --- a/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPullTokensTask.ts @@ -29,7 +29,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_GET_TOKENS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_GET_TOKENS, error); } } @@ -75,7 +75,7 @@ export default class OCPIPullTokensTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_GET_TOKENS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_GET_TOKENS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts b/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts index 185fb89962..42ac280091 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushCdrsTask.ts @@ -126,7 +126,7 @@ export default class OCPIPushCdrsTask extends TenantSchedulerTask { } } } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_PUSH_CDRS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_PUSH_CDRS, error); } } } diff --git a/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts b/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts index b6dac32dbc..3b2183b1d2 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushEVSEStatusesTask.ts @@ -29,7 +29,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, error); } } @@ -74,7 +74,7 @@ export default class OCPIPushEVSEStatusesTask extends TenantSchedulerTask { message: `Push of Locations process for endpoint '${ocpiEndpoint.name}' is completed (Success: ${sendResult.success} / Failure: ${sendResult.failure})` }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_CPO_PUSH_EVSE_STATUSES, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts b/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts index 6829291f10..d4b2f1f2b9 100644 --- a/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts +++ b/src/scheduler/tasks/ocpi/OCPIPushTokensTask.ts @@ -29,7 +29,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_UPDATE_TOKENS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_UPDATE_TOKENS, error); } } @@ -75,7 +75,7 @@ export default class OCPIPushTokensTask extends TenantSchedulerTask { detailedMessages: { result } }); } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_UPDATE_TOKENS, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OCPI_EMSP_UPDATE_TOKENS, error); } finally { await LockingManager.release(ocpiLock); } diff --git a/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts b/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts index 8e21967d32..15b9a21932 100644 --- a/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts +++ b/src/scheduler/tasks/oicp/OICPPushEvseDataTask.ts @@ -29,7 +29,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_DATA, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_DATA, error); } } @@ -75,7 +75,7 @@ export default class OICPPushEvseDataTask extends TenantSchedulerTask { }); } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_DATA, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_DATA, error); } finally { // Release the lock await LockingManager.release(oicpLock); diff --git a/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts b/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts index c840c3283c..90b698fd48 100644 --- a/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts +++ b/src/scheduler/tasks/oicp/OICPPushEvseStatusTask.ts @@ -29,7 +29,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { } } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_STATUSES, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_STATUSES, error); } } @@ -75,7 +75,7 @@ export default class OICPPushEvseStatusTask extends TenantSchedulerTask { }); } catch (error) { // Log error - await Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_STATUSES, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.OICP_PUSH_EVSE_STATUSES, error); } finally { // Release the lock await LockingManager.release(oicpLock); diff --git a/src/server/ocpi/OCPIServer.ts b/src/server/ocpi/OCPIServer.ts index af22dbb1a5..1cf4e996b6 100644 --- a/src/server/ocpi/OCPIServer.ts +++ b/src/server/ocpi/OCPIServer.ts @@ -44,7 +44,7 @@ export default class OCPIServer { message: `Endpoint '${req.path}' not implemented`, ocpiError: OCPIStatusCode.CODE_3000_GENERIC_SERVER_ERROR }); - void Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT_ID, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error); + Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT_ID, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error); res.status(HTTPError.NOT_IMPLEMENTED_ERROR).json(OCPIUtils.toErrorResponse(error)); } }); @@ -135,7 +135,7 @@ export default class OCPIServer { } next(); } catch (error) { - await Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT_ID, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error); + Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT_ID, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error); res.status(error.params?.errorCode ?? HTTPError.GENERAL_ERROR).json(OCPIUtils.toErrorResponse(error)); } } diff --git a/src/server/ocpp/json/JsonOCPPServer.ts b/src/server/ocpp/json/JsonOCPPServer.ts index c343f20d32..406a666d41 100644 --- a/src/server/ocpp/json/JsonOCPPServer.ts +++ b/src/server/ocpp/json/JsonOCPPServer.ts @@ -49,36 +49,31 @@ export default class JsonOCPPServer extends OCPPServer { compression: uWS.SHARED_COMPRESSOR, maxPayloadLength: 64 * 1024, // 64 KB per request idleTimeout: 1 * 3600, // 1 hour of inactivity => Close - // eslint-disable-next-line @typescript-eslint/no-misused-promises - upgrade: async (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => { + upgrade: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => { // Delegate - await this.onUpgrade(res, req, context); + this.onUpgrade(res, req, context); }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - open: async (ws: WebSocket) => { + open: (ws: WebSocket) => { // Delegate - await this.onOpen(ws); + this.onOpen(ws).catch(() => { /* Intentional */ }); }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - message: async (ws: WebSocket, message: ArrayBuffer, isBinary: boolean) => { + message: (ws: WebSocket, message: ArrayBuffer, isBinary: boolean) => { // Delegate const messageStr = Utils.convertBufferArrayToString(message); - await this.onMessage(ws, messageStr, isBinary); + this.onMessage(ws, messageStr, isBinary).catch(() => { /* Intentional */ }); }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - close: async (ws: WebSocket, code: number, message: ArrayBuffer) => { + close: (ws: WebSocket, code: number, message: ArrayBuffer) => { // Convert right away const reason = Utils.convertBufferArrayToString(message); const wsWrapper = ws.wsWrapper as WSWrapper; // Close wsWrapper.closed = true; - await this.logWSConnectionClosed(wsWrapper, ServerAction.WS_SERVER_CONNECTION_CLOSE, code, + this.logWSConnectionClosed(wsWrapper, ServerAction.WS_SERVER_CONNECTION_CLOSE, code, `${WebSocketAction.CLOSE} > WS Connection ID '${wsWrapper.guid}' closed by charging station with code '${code}', reason: '${!Utils.isNullOrEmptyString(reason) ? reason : 'No reason given'}'`); // Remove connection - await this.removeWSWrapper(WebSocketAction.CLOSE, ServerAction.WS_SERVER_CONNECTION_CLOSE, wsWrapper); + this.removeWSWrapper(WebSocketAction.CLOSE, ServerAction.WS_SERVER_CONNECTION_CLOSE, wsWrapper); }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - ping: async (ws: WebSocket, message: ArrayBuffer) => { + ping: (ws: WebSocket, message: ArrayBuffer) => { // Convert const ocppMessage = Utils.convertBufferArrayToString(message); // Update @@ -87,11 +82,10 @@ export default class JsonOCPPServer extends OCPPServer { } // Get the WS if (ws.wsWrapper.wsConnection) { - await ws.wsWrapper.wsConnection.onPing(ocppMessage); + ws.wsWrapper.wsConnection.onPing(ocppMessage); } }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - pong: async (ws: WebSocket, message: ArrayBuffer) => { + pong: (ws: WebSocket, message: ArrayBuffer) => { // Convert const ocppMessage = Utils.convertBufferArrayToString(message); // Update @@ -100,7 +94,7 @@ export default class JsonOCPPServer extends OCPPServer { } // Get the WS if (ws.wsWrapper.wsConnection) { - await ws.wsWrapper.wsConnection.onPong(ocppMessage); + ws.wsWrapper.wsConnection.onPong(ocppMessage); } } // eslint-disable-next-line @typescript-eslint/no-misused-promises @@ -131,7 +125,7 @@ export default class JsonOCPPServer extends OCPPServer { }); } - public async getChargingStationClient(tenant: Tenant, chargingStation: ChargingStation): Promise { + public getChargingStationClient(tenant: Tenant, chargingStation: ChargingStation): ChargingStationClient { // Get the Json Web Socket const jsonWebSocket = this.jsonWSConnections.get(`${tenant.id}~${chargingStation.id}`); if (!jsonWebSocket) { @@ -158,7 +152,7 @@ export default class JsonOCPPServer extends OCPPServer { return this.jsonWSConnections.has(`${tenant.id}~${chargingStation.id}`); } - private async onUpgrade(res: uWS.HttpResponse, req: uWS.HttpRequest, context: uWS.us_socket_context_t) { + private onUpgrade(res: uWS.HttpResponse, req: uWS.HttpRequest, context: uWS.us_socket_context_t) { // Check for WS connection over HTTP const url = req.getUrl(); try { @@ -244,12 +238,12 @@ export default class JsonOCPPServer extends OCPPServer { await this.checkAndStoreWSOpenedConnection(WSServerProtocol.REST, wsWrapper); } } catch (error) { - await Logging.logException(error as Error, ServerAction.WS_SERVER_CONNECTION_OPEN, MODULE_NAME, 'onOpen', Constants.DEFAULT_TENANT_ID); + Logging.logException(error as Error, ServerAction.WS_SERVER_CONNECTION_OPEN, MODULE_NAME, 'onOpen', Constants.DEFAULT_TENANT_ID); if (wsWrapper.tenantID) { - await Logging.logException(error as Error, ServerAction.WS_SERVER_CONNECTION_OPEN, MODULE_NAME, 'onOpen', wsWrapper.tenantID); + Logging.logException(error as Error, ServerAction.WS_SERVER_CONNECTION_OPEN, MODULE_NAME, 'onOpen', wsWrapper.tenantID); } // Close WS - await this.closeWebSocket(WebSocketAction.OPEN, ServerAction.WS_SERVER_CONNECTION_OPEN, wsWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, + this.closeWebSocket(WebSocketAction.OPEN, ServerAction.WS_SERVER_CONNECTION_OPEN, wsWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' has been rejected and closed by server due to an exception: ${error.message as string}`); } finally { this.runningWSMessages--; @@ -288,7 +282,7 @@ export default class JsonOCPPServer extends OCPPServer { wsWrapper.siteAreaID = wsConnection.getSiteAreaID(); wsWrapper.companyID = wsConnection.getCompanyID(); // Check already existing WS Connection - await this.checkAndCloseIdenticalOpenedWSConnection(wsWrapper, wsConnection); + this.checkAndCloseIdenticalOpenedWSConnection(wsWrapper, wsConnection); const message = `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' has been accepted in ${Utils.computeTimeDurationSecs(timeStart)} secs`; Logging.beInfo()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, @@ -302,14 +296,14 @@ export default class JsonOCPPServer extends OCPPServer { message, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } }); // Keep WS connection in cache - await this.setWSConnection(WebSocketAction.OPEN, ServerAction.WS_SERVER_CONNECTION_OPEN, wsConnection, wsWrapper); + this.setWSConnection(WebSocketAction.OPEN, ServerAction.WS_SERVER_CONNECTION_OPEN, wsConnection, wsWrapper); } else { - await this.logWSConnectionClosed(wsWrapper, ServerAction.WS_SERVER_CONNECTION_OPEN, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, + this.logWSConnectionClosed(wsWrapper, ServerAction.WS_SERVER_CONNECTION_OPEN, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.OPEN} > WS Connection ID '${wsWrapper.guid}' has been closed during initialization in ${Utils.computeTimeDurationSecs(timeStart)} secs ('${wsWrapper.url}')`); } } - private async checkAndCloseIdenticalOpenedWSConnection(wsWrapper: WSWrapper, wsConnection: WSConnection): Promise { + private checkAndCloseIdenticalOpenedWSConnection(wsWrapper: WSWrapper, wsConnection: WSConnection): void { // Get connection const existingWSConnection = this.getWSConnectionFromProtocolAndID(wsConnection.getWS().protocol, wsConnection.getID()); @@ -319,7 +313,7 @@ export default class JsonOCPPServer extends OCPPServer { const existingWSWrapper = existingWSConnection.getWS(); if (!existingWSWrapper.closed) { // Ping WS - const result = await this.pingWebSocket(existingWSWrapper); + const result = this.pingWebSocket(existingWSWrapper); if (result.ok) { // Close the old WS and keep the new incoming one Logging.beWarning()?.log({ @@ -329,7 +323,7 @@ export default class JsonOCPPServer extends OCPPServer { message: `${WebSocketAction.OPEN} > Existing WS Connection ID '${existingWSWrapper.guid}' will be closed and replaced by new incoming one with ID '${wsWrapper.guid}'`, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } }); - await this.closeWebSocket(WebSocketAction.OPEN, ServerAction.WS_SERVER_CONNECTION_OPEN, existingWSConnection.getWS(), WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, + this.closeWebSocket(WebSocketAction.OPEN, ServerAction.WS_SERVER_CONNECTION_OPEN, existingWSConnection.getWS(), WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.OPEN} > Existing WS Connection ID '${existingWSWrapper.guid}' has been closed successfully by the server`); } } @@ -366,7 +360,7 @@ export default class JsonOCPPServer extends OCPPServer { try { this.runningWSMessages++; // Check if connection is available in Map - await this.checkWSConnectionFromOnMessage(wsWrapper); + this.checkWSConnectionFromOnMessage(wsWrapper); // OCPP Request? if (ocppMessageType === OCPPMessageType.CALL_MESSAGE) { if (!wsWrapper.closed) { @@ -403,7 +397,7 @@ export default class JsonOCPPServer extends OCPPServer { } } - private async checkWSConnectionFromOnMessage(wsWrapper: WSWrapper) { + private checkWSConnectionFromOnMessage(wsWrapper: WSWrapper) { // Get WS Connection const wsConnection = wsWrapper.wsConnection; // Get WS Connection from cache @@ -419,7 +413,7 @@ export default class JsonOCPPServer extends OCPPServer { detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper) } }); // Add WS connection from OnMessage in cache - await this.setWSConnection(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsConnection, wsWrapper); + this.setWSConnection(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsConnection, wsWrapper); return; } // Should have the same GUID @@ -434,7 +428,7 @@ export default class JsonOCPPServer extends OCPPServer { detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper), wsExistingWrapper: this.getWSWrapperData(wsExistingWrapper) } }); // Ping - const result = await this.pingWebSocket(wsExistingWrapper); + const result = this.pingWebSocket(wsExistingWrapper); if (result.ok) { Logging.beError()?.log({ tenantID: Constants.DEFAULT_TENANT_ID, @@ -445,7 +439,7 @@ export default class JsonOCPPServer extends OCPPServer { detailedMessages: { wsExistingWrapper: this.getWSWrapperData(wsExistingWrapper), wsWrapper: this.getWSWrapperData(wsWrapper) } }); // Close WS - await this.closeWebSocket(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsExistingWrapper, + this.closeWebSocket(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsExistingWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.MESSAGE} > Existing WS Connection ID '${wsExistingWrapper.guid}' has been closed successfully by server (duplicate WS Connection)`); } else { Logging.beWarning()?.log({ @@ -458,11 +452,11 @@ export default class JsonOCPPServer extends OCPPServer { }); } // Keep WS connection in cache - await this.setWSConnection(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsConnection, wsWrapper); + this.setWSConnection(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsConnection, wsWrapper); } } - private async logWSConnectionClosed(wsWrapper: WSWrapper, action: ServerAction, code: number, message: string): Promise { + private logWSConnectionClosed(wsWrapper: WSWrapper, action: ServerAction, code: number, message: string): void { this.isDebug() && Logging.logConsoleDebug(message); if (wsWrapper.tenantID) { Logging.beInfo()?.log({ @@ -530,7 +524,7 @@ export default class JsonOCPPServer extends OCPPServer { return true; } - private async pingWebSocket(wsWrapper: WSWrapper): Promise { + private pingWebSocket(wsWrapper: WSWrapper): WebSocketPingResult { try { // Ping the WS wsWrapper.ping(); @@ -550,7 +544,7 @@ export default class JsonOCPPServer extends OCPPServer { message: `${WebSocketAction.PING} > Failed to ping the WS Connection ID '${wsWrapper.guid}' after ${wsWrapper.nbrPingFailed} trial(s), will be removed from WS cache`, detailedMessages: { wsWrapper: this.getWSWrapperData(wsWrapper), error: error.stack } }); - await this.closeWebSocket(WebSocketAction.PING, ServerAction.WS_SERVER_CONNECTION_PING, wsWrapper, + this.closeWebSocket(WebSocketAction.PING, ServerAction.WS_SERVER_CONNECTION_PING, wsWrapper, WebSocketCloseEventStatusCode.CLOSE_ABNORMAL, `${WebSocketAction.PING} > WS Connection ID '${wsWrapper.guid}' has been closed by server after ${wsWrapper.nbrPingFailed} failed ping`); } else { Logging.beWarning()?.log({ @@ -569,12 +563,12 @@ export default class JsonOCPPServer extends OCPPServer { } } - private async closeWebSocket(wsAction: WebSocketAction, action: ServerAction, wsWrapper: WSWrapper, code: WebSocketCloseEventStatusCode, message: string): Promise { + private closeWebSocket(wsAction: WebSocketAction, action: ServerAction, wsWrapper: WSWrapper, code: WebSocketCloseEventStatusCode, message: string): void { // Close WS if (!wsWrapper.closed) { try { wsWrapper.close(code, message); - await this.logWSConnectionClosed(wsWrapper, action, code, message); + this.logWSConnectionClosed(wsWrapper, action, code, message); } catch (error) { // Just log and ignore issue Logging.beError()?.log({ @@ -587,10 +581,10 @@ export default class JsonOCPPServer extends OCPPServer { } } // Remove connection - await this.removeWSWrapper(wsAction, action, wsWrapper); + this.removeWSWrapper(wsAction, action, wsWrapper); } - private async setWSConnection(wsAction: WebSocketAction, action: ServerAction, wsConnection: WSConnection, wsWrapper: WSWrapper) { + private setWSConnection(wsAction: WebSocketAction, action: ServerAction, wsConnection: WSConnection, wsWrapper: WSWrapper) { // Reference a Json WebSocket connection object if (wsWrapper.protocol === WSServerProtocol.OCPP16) { this.jsonWSConnections.set(wsConnection.getID(), wsConnection as JsonWSConnection); @@ -624,18 +618,18 @@ export default class JsonOCPPServer extends OCPPServer { } } - private async removeWSWrapper(wsAction: WebSocketAction, action: ServerAction, wsWrapper: WSWrapper): Promise { + private removeWSWrapper(wsAction: WebSocketAction, action: ServerAction, wsWrapper: WSWrapper): void { if (wsWrapper.protocol === WSServerProtocol.OCPP16) { - await this.removeWSConnection( + this.removeWSConnection( wsAction, action, wsWrapper.wsConnection, this.jsonWSConnections); } if (wsWrapper.protocol === WSServerProtocol.REST) { - await this.removeWSConnection( + this.removeWSConnection( wsAction, action, wsWrapper.wsConnection, this.jsonRestWSConnections); } } - private async removeWSConnection(wsAction: WebSocketAction, action: ServerAction, wsConnection: WSConnection, wsConnections: Map): Promise { + private removeWSConnection(wsAction: WebSocketAction, action: ServerAction, wsConnection: WSConnection, wsConnections: Map): void { if (wsConnection) { const wsWrapper = wsConnection.getWS(); const existingWsConnection = wsConnections.get(wsConnection.getID()); @@ -680,8 +674,7 @@ export default class JsonOCPPServer extends OCPPServer { } private monitorWSConnections() { - // eslint-disable-next-line @typescript-eslint/no-misused-promises - setTimeout(async () => { + setTimeout(() => { try { // Log size of WS Json Connections (track leak) let sizeOfCurrentRequestsBytes = 0, numberOfCurrentRequests = 0; @@ -759,7 +752,7 @@ export default class JsonOCPPServer extends OCPPServer { tenantID: Constants.DEFAULT_TENANT_ID, module: MODULE_NAME, method: 'checkAndCleanupWebSockets', action: ServerAction.WS_SERVER_CONNECTION_PING, - message, detailedMessages: { invalidConnections, /* validConnections */ } + message, /* detailedMessages: { invalidConnections, validConnections } */ }); } else { Logging.beInfo()?.log({ diff --git a/src/server/ocpp/json/services/JsonChargingStationService.ts b/src/server/ocpp/json/services/JsonChargingStationService.ts index f092f4b273..86a555e2e8 100644 --- a/src/server/ocpp/json/services/JsonChargingStationService.ts +++ b/src/server/ocpp/json/services/JsonChargingStationService.ts @@ -88,11 +88,11 @@ export default class JsonChargingStationService { }; } - private async handle(command: Command, headers: OCPPHeader, payload) { + private async handle(command: Command, headers: OCPPHeader, payload): Promise { try { - return this.chargingStationService[`handle${command}`](headers, payload); + return this.chargingStationService[`handle${command}`](headers, payload) as Promise; } catch (error) { - await Logging.logException(error, OCPPUtils.buildServerActionFromOcppCommand(command), MODULE_NAME, command, headers.tenantID); + Logging.logException(error, OCPPUtils.buildServerActionFromOcppCommand(command), MODULE_NAME, command, headers.tenantID); throw error; } } diff --git a/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts b/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts index c4af0cc70f..555e7f0a8c 100644 --- a/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts +++ b/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts @@ -48,7 +48,7 @@ export default class JsonRestWSConnection extends WSConnection { }); } // Get the client from JSON Server - const chargingStationClient = await global.centralSystemJsonServer.getChargingStationClient(this.getTenant(), chargingStation); + const chargingStationClient = global.centralSystemJsonServer.getChargingStationClient(this.getTenant(), chargingStation); if (!chargingStationClient) { throw new BackendError({ chargingStationID: this.getChargingStationID(), diff --git a/src/server/ocpp/services/OCPPService.ts b/src/server/ocpp/services/OCPPService.ts index 9f0ce8a694..d030c72569 100644 --- a/src/server/ocpp/services/OCPPService.ts +++ b/src/server/ocpp/services/OCPPService.ts @@ -39,7 +39,6 @@ import TransactionStorage from '../../../storage/mongodb/TransactionStorage'; import User from '../../../types/User'; import UserStorage from '../../../storage/mongodb/UserStorage'; import Utils from '../../../utils/Utils'; -import UtilsService from '../../rest/v1/service/UtilsService'; import moment from 'moment'; import momentDurationFormatSetup from 'moment-duration-format'; @@ -102,7 +101,7 @@ export default class OCPPService { }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_BOOT_NOTIFICATION, error, { bootNotification }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_BOOT_NOTIFICATION, error, { bootNotification }); // Reject return { status: RegistrationStatus.REJECTED, @@ -139,7 +138,7 @@ export default class OCPPService { }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_HEARTBEAT, error, { heartbeat }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_HEARTBEAT, error, { heartbeat }); return { currentTime: new Date().toISOString() }; @@ -171,7 +170,7 @@ export default class OCPPService { return {}; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_STATUS_NOTIFICATION, error, { statusNotification }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_STATUS_NOTIFICATION, error, { statusNotification }); return {}; } } @@ -253,7 +252,7 @@ export default class OCPPService { }); } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_METER_VALUES, error, { meterValues }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_METER_VALUES, error, { meterValues }); } return {}; } @@ -288,7 +287,7 @@ export default class OCPPService { }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_AUTHORIZE, error, { authorize }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_AUTHORIZE, error, { authorize }); // Rejected return { idTagInfo: { @@ -320,7 +319,7 @@ export default class OCPPService { return {}; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_DIAGNOSTICS_STATUS_NOTIFICATION, error, { diagnosticsStatusNotification }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_DIAGNOSTICS_STATUS_NOTIFICATION, error, { diagnosticsStatusNotification }); return {}; } } @@ -349,7 +348,7 @@ export default class OCPPService { return {}; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_FIRMWARE_STATUS_NOTIFICATION, error, { firmwareStatusNotification }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_FIRMWARE_STATUS_NOTIFICATION, error, { firmwareStatusNotification }); return {}; } } @@ -412,7 +411,7 @@ export default class OCPPService { }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_START_TRANSACTION, error, { startTransaction }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_START_TRANSACTION, error, { startTransaction }); // Invalid return { transactionId: 0, @@ -446,7 +445,7 @@ export default class OCPPService { }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.CHARGING_STATION_DATA_TRANSFER, error, { dataTransfer }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.CHARGING_STATION_DATA_TRANSFER, error, { dataTransfer }); // Rejected return { status: OCPPDataTransferStatus.REJECTED @@ -520,7 +519,7 @@ export default class OCPPService { }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); - await Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_STOP_TRANSACTION, error, { stopTransaction }); + Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_STOP_TRANSACTION, error, { stopTransaction }); // Invalid return { idTagInfo: { diff --git a/src/server/ocpp/utils/OCPPCommon.ts b/src/server/ocpp/utils/OCPPCommon.ts index e26fa1bab5..cb6ad77719 100644 --- a/src/server/ocpp/utils/OCPPCommon.ts +++ b/src/server/ocpp/utils/OCPPCommon.ts @@ -99,7 +99,7 @@ export default class OCPPCommon { }); return { status: OCPPConfigurationStatus.ACCEPTED }; } catch (error) { - await Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, error); + Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, error); return { status: OCPPConfigurationStatus.REJECTED }; } } diff --git a/src/server/oicp/AbstractOICPService.ts b/src/server/oicp/AbstractOICPService.ts index b6e25fa560..d223870c95 100644 --- a/src/server/oicp/AbstractOICPService.ts +++ b/src/server/oicp/AbstractOICPService.ts @@ -146,7 +146,7 @@ export default abstract class AbstractOICPService { action: ServerAction.OICP_ENDPOINT, detailedMessages: { error: error.stack } }); - await Logging.logActionExceptionMessage(req.user && req.user.tenantID ? req.user.tenantID : Constants.DEFAULT_TENANT_ID, ServerAction.OICP_ENDPOINT, error); + Logging.logActionExceptionMessage(req.user && req.user.tenantID ? req.user.tenantID : Constants.DEFAULT_TENANT_ID, ServerAction.OICP_ENDPOINT, error); let errorCode: any = {}; if (error instanceof AppError || error instanceof AppAuthError) { errorCode = error.params.errorCode; diff --git a/src/server/rest/RestServerService.ts b/src/server/rest/RestServerService.ts index b373d1442d..e79ea3846b 100644 --- a/src/server/rest/RestServerService.ts +++ b/src/server/rest/RestServerService.ts @@ -319,7 +319,7 @@ export default class RestServerService { }); // Check HTTP Verbs if (!['POST', 'GET', 'PUT', 'DELETE'].includes(req.method)) { - await Logging.logActionExceptionMessageAndSendResponse( + Logging.logActionExceptionMessageAndSendResponse( null, new Error(`Unsupported request method ${req.method}`), req, res, next); return; } diff --git a/src/server/rest/v1/service/TransactionService.ts b/src/server/rest/v1/service/TransactionService.ts index 82488f1429..c7f9e402f0 100644 --- a/src/server/rest/v1/service/TransactionService.ts +++ b/src/server/rest/v1/service/TransactionService.ts @@ -70,7 +70,7 @@ export default class TransactionService { res.json(response); next(); } catch (error) { - await Logging.logActionExceptionMessageAndSendResponse(action, error, req, res, next); + Logging.logActionExceptionMessageAndSendResponse(action, error, req, res, next); } } @@ -421,7 +421,7 @@ export default class TransactionService { }; res.json(advenirPayload); } catch (error) { - await Logging.logActionExceptionMessageAndSendResponse(action, error, req, res, next); + Logging.logActionExceptionMessageAndSendResponse(action, error, req, res, next); } } diff --git a/src/server/rest/v1/service/UtilsService.ts b/src/server/rest/v1/service/UtilsService.ts index e1ea01c8a3..e99cc3ef75 100644 --- a/src/server/rest/v1/service/UtilsService.ts +++ b/src/server/rest/v1/service/UtilsService.ts @@ -1067,10 +1067,10 @@ export default class UtilsService { public static async handleUnknownAction(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise { // Action provided if (!action) { - await Logging.logActionExceptionMessageAndSendResponse( + Logging.logActionExceptionMessageAndSendResponse( null, new Error('No Action has been provided'), req, res, next); } else { - await Logging.logActionExceptionMessageAndSendResponse( + Logging.logActionExceptionMessageAndSendResponse( action, new Error(`The Action '${action}' does not exist`), req, res, next); } } diff --git a/src/utils/Logging.ts b/src/utils/Logging.ts index 6a17160c62..d1fb065340 100644 --- a/src/utils/Logging.ts +++ b/src/utils/Logging.ts @@ -539,8 +539,8 @@ export default class Logging { } } - public static async traceExpressError(error: Error, req: Request, res: Response, next: NextFunction): Promise { - await Logging.logActionExceptionMessageAndSendResponse( + public static traceExpressError(error: Error, req: Request, res: Response, next: NextFunction): void { + Logging.logActionExceptionMessageAndSendResponse( error['params'] && error['params']['action'] ? error['params']['action'] : ServerAction.HTTP_ERROR, error, req, res, next); if (Logging.getTraceConfiguration().traceIngressHttp) { // Nothing done yet @@ -707,40 +707,40 @@ export default class Logging { } } - public static async logException(exception: Error, action: ServerAction, - module: string, method: string, tenantID: string, user?: UserToken | User | string): Promise { + public static logException(exception: Error, action: ServerAction, + module: string, method: string, tenantID: string, user?: UserToken | User | string): void { if (exception instanceof AppAuthError) { - await Logging.logActionAppAuthException(tenantID, action, exception); + Logging.logActionAppAuthException(tenantID, action, exception); } else if (exception instanceof AppError) { - await Logging.logActionAppException(tenantID, action, exception); + Logging.logActionAppException(tenantID, action, exception); } else if (exception instanceof OCPPError) { - await Logging.logActionOcppException(tenantID, action, exception); + Logging.logActionOcppException(tenantID, action, exception); } else if (exception instanceof BackendError) { - await Logging.logActionBackendException(tenantID, action, exception); + Logging.logActionBackendException(tenantID, action, exception); } else { - await Logging.logError( + Logging.beError()?.log( Logging.buildLogError(action, module, method, tenantID, user, exception)); } } // Used to log exception in catch(...) only - public static async logActionExceptionMessage(tenantID: string, action: ServerAction, exception: Error, detailedMessages = {}): Promise { + public static logActionExceptionMessage(tenantID: string, action: ServerAction, exception: Error, detailedMessages = {}): void { if (exception instanceof AppError) { - await Logging.logActionAppException(tenantID, action, exception, detailedMessages); + Logging.logActionAppException(tenantID, action, exception, detailedMessages); } else if (exception instanceof BackendError) { - await Logging.logActionBackendException(tenantID, action, exception, detailedMessages); + Logging.logActionBackendException(tenantID, action, exception, detailedMessages); } else if (exception instanceof AppAuthError) { - await Logging.logActionAppAuthException(tenantID, action, exception, detailedMessages); + Logging.logActionAppAuthException(tenantID, action, exception, detailedMessages); } else if (exception instanceof OCPPError) { - await Logging.logActionOcppException(tenantID, action, exception); + Logging.logActionOcppException(tenantID, action, exception); } else { - await Logging.logActionException(tenantID, action, exception, detailedMessages); + Logging.logActionException(tenantID, action, exception, detailedMessages); } } // Used to log exception in catch(...) only - public static async logActionExceptionMessageAndSendResponse(action: ServerAction, exception: Error, - req: Request, res: Response, next: NextFunction, tenantID = Constants.DEFAULT_TENANT_ID): Promise { + public static logActionExceptionMessageAndSendResponse(action: ServerAction, exception: Error, + req: Request, res: Response, next: NextFunction, tenantID = Constants.DEFAULT_TENANT_ID): void { // Clear password if (action === ServerAction.LOGIN && req.body.password) { req.body.password = '####'; @@ -752,15 +752,15 @@ export default class Logging { tenantID = req.tenant.id; } if (exception instanceof AppError) { - await Logging.logActionAppException(tenantID, action, exception); + Logging.logActionAppException(tenantID, action, exception); } else if (exception instanceof BackendError) { - await Logging.logActionBackendException(tenantID, action, exception); + Logging.logActionBackendException(tenantID, action, exception); } else if (exception instanceof AppAuthError) { - await Logging.logActionAppAuthException(tenantID, action, exception); + Logging.logActionAppAuthException(tenantID, action, exception); } else if (exception instanceof OCPPError) { - await Logging.logActionOcppException(tenantID, action, exception); + Logging.logActionOcppException(tenantID, action, exception); } else { - await Logging.logActionException(tenantID, action, exception); + Logging.logActionException(tenantID, action, exception); } // Send error if (!res.headersSent) { @@ -870,8 +870,8 @@ export default class Logging { } } - private static async logActionException(tenantID: string, action: ServerAction, exception: any, detailedMessages = {}): Promise { - await Logging.logError({ + private static logActionException(tenantID: string, action: ServerAction, exception: any, detailedMessages = {}): void { + Logging.beError()?.log({ tenantID: tenantID, user: exception.user, module: exception.module, @@ -882,9 +882,9 @@ export default class Logging { }); } - private static async logActionAppException(tenantID: string, action: ServerAction, exception: AppError, detailedMessages = {}): Promise { + private static logActionAppException(tenantID: string, action: ServerAction, exception: AppError, detailedMessages = {}): void { Utils.handleExceptionDetailedMessages(exception); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenantID, chargingStationID: exception.params.chargingStationID, siteID: exception.params.siteID, @@ -903,9 +903,9 @@ export default class Logging { }); } - private static async logActionBackendException(tenantID: string, action: ServerAction, exception: BackendError, detailedMessages = {}): Promise { + private static logActionBackendException(tenantID: string, action: ServerAction, exception: BackendError, detailedMessages = {}): void { Utils.handleExceptionDetailedMessages(exception); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenantID, chargingStationID: exception.params.chargingStationID, siteID: exception.params.siteID, @@ -925,9 +925,9 @@ export default class Logging { } // Used to check URL params (not in catch) - private static async logActionAppAuthException(tenantID: string, action: ServerAction, exception: AppAuthError, detailedMessages = {}): Promise { + private static logActionAppAuthException(tenantID: string, action: ServerAction, exception: AppAuthError, detailedMessages = {}): void { Utils.handleExceptionDetailedMessages(exception); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenantID, user: exception.params.user, chargingStationID: exception.params.chargingStationID, @@ -946,9 +946,9 @@ export default class Logging { }); } - private static async logActionOcppException(tenantID: string, action: ServerAction, exception: OCPPError, detailedMessages = {}): Promise { + private static logActionOcppException(tenantID: string, action: ServerAction, exception: OCPPError, detailedMessages = {}): void { Utils.handleExceptionDetailedMessages(exception); - await Logging.logError({ + Logging.beError()?.log({ tenantID: tenantID, chargingStationID: exception.params.chargingStationID, siteID: exception.params.siteID, diff --git a/src/utils/RouterUtils.ts b/src/utils/RouterUtils.ts index b8587161a2..c9ce27bec8 100644 --- a/src/utils/RouterUtils.ts +++ b/src/utils/RouterUtils.ts @@ -37,7 +37,7 @@ export default class RouterUtils { // Trace } catch (error) { Utils.isDevelopmentEnv() && Logging.logConsoleError(error.stack); - void Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT_ID, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error); + Logging.logActionExceptionMessage(req.tenant?.id ?? Constants.DEFAULT_TENANT_ID, error.params?.action ?? ServerAction.OCPI_ENDPOINT, error); res.status(error.params?.errorCode ?? HTTPError.GENERAL_ERROR).json(OCPIUtils.toErrorResponse(error)); next(); } From 973f3b3a3ea58cf4478809213c04449f1f644f5c Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 27 Dec 2022 16:16:34 +0100 Subject: [PATCH 08/11] websockets - bumped version uws - 20.15.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b5d1f25db3..776986fea1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,7 +71,7 @@ "tslib": "^2.4.0", "tz-lookup": "^6.1.25", "urlencode": "^1.1.0", - "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0", + "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.15.0", "validator": "^13.7.0", "ws": "^8.10.0" }, @@ -43728,7 +43728,7 @@ }, "uWebSockets.js": { "version": "git+ssh://git@github.com/uNetworking/uWebSockets.js.git#806df48c9da86af7b3341f3e443388c7cd15c3de", - "from": "uWebSockets.js@github:uNetworking/uWebSockets.js#v20.10.0" + "from": "uWebSockets.js@github:uNetworking/uWebSockets.js#v20.15.0" }, "v8-compile-cache-lib": { "version": "3.0.1", diff --git a/package.json b/package.json index b99b74632c..7789444f25 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,7 @@ "tslib": "^2.4.0", "tz-lookup": "^6.1.25", "urlencode": "^1.1.0", - "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0", + "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.15.0", "validator": "^13.7.0", "ws": "^8.10.0" }, From 1bcb310603550878899e771fbf9a3c967e0fcff6 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Tue, 27 Dec 2022 16:17:13 +0100 Subject: [PATCH 09/11] websocket - check tenant data consistency --- src/server/ocpp/utils/OCPPUtils.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/server/ocpp/utils/OCPPUtils.ts b/src/server/ocpp/utils/OCPPUtils.ts index 82d3f9c022..b3bf16b4f3 100644 --- a/src/server/ocpp/utils/OCPPUtils.ts +++ b/src/server/ocpp/utils/OCPPUtils.ts @@ -1244,6 +1244,14 @@ export default class OCPPUtils { message: `Tenant ID '${tenantID}' does not exist!` }); } + // Check consistency + if (!tenant?.id || !tenant?.components) { + throw new BackendError({ + chargingStationID, + module: MODULE_NAME, method: 'checkAndGetChargingStationData', + message: `Tenant ID '${tenantID}' data is not consistent - sounds like the database is under pressure!` + }); + } // Get the Charging Station let token: RegistrationToken; const chargingStation = await ChargingStationStorage.getChargingStation( From 9e611a7bc456c86a0eaeae3fdba73c2d28049256 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Wed, 28 Dec 2022 15:37:19 +0100 Subject: [PATCH 10/11] perf- feature toggles to switch on/off optional stuff --- src/server/ExpressUtils.ts | 20 +++-- src/server/ocpp/json/JsonOCPPServer.ts | 75 ++++++++++++------- .../json/web-socket/JsonRestWSConnection.ts | 4 +- .../ocpp/json/web-socket/JsonWSConnection.ts | 22 ++++-- .../ocpp/json/web-socket/WSConnection.ts | 4 +- src/server/ocpp/services/OCPPService.ts | 39 +++++----- src/utils/FeatureToggles.ts | 10 +++ 7 files changed, 111 insertions(+), 63 deletions(-) diff --git a/src/server/ExpressUtils.ts b/src/server/ExpressUtils.ts index bb5a9494f5..3ea9cf3d11 100644 --- a/src/server/ExpressUtils.ts +++ b/src/server/ExpressUtils.ts @@ -1,3 +1,4 @@ +import FeatureToggles, { Feature } from '../utils/FeatureToggles'; import express, { Application, NextFunction, Request, Response } from 'express'; import Constants from '../utils/Constants'; @@ -51,7 +52,7 @@ export default class ExpressUtils { limit: bodyLimit })); // Health Check Handling - app.get(Constants.HEALTH_CHECK_ROUTE, ExpressUtils.healthCheckService.bind(this)); + app.get(Constants.HEALTH_CHECK_ROUTE, (req: Request, res: Response, next: NextFunction) => ExpressUtils.healthCheckService(req, res, next)); // Use app.use(locale(Constants.SUPPORTED_LOCALES)); return app; @@ -62,12 +63,19 @@ export default class ExpressUtils { expressApplication.use(Logging.traceExpressError.bind(this)); } - private static async healthCheckService(req: Request, res: Response, next: NextFunction): Promise { - const pingSuccess = await global.database.ping(); - if (pingSuccess) { - res.sendStatus(StatusCodes.OK); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + private static healthCheckService(req: Request, res: Response, next: NextFunction): void { + if (FeatureToggles.isFeatureActive(Feature.HEALTH_CHECK_PING_DATABASE)) { + global.database.ping().then((pingSuccess) => { + if (pingSuccess) { + res.sendStatus(StatusCodes.OK); + } else { + res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR); + } + }).catch(() => { /* Intentional */ }); } else { - res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR); + // TODO - FIND ANOTHER METRIC TO CHECK THE READINESS and LIVENESS PROBE + res.sendStatus(StatusCodes.OK); } } } diff --git a/src/server/ocpp/json/JsonOCPPServer.ts b/src/server/ocpp/json/JsonOCPPServer.ts index 406a666d41..40a98c8d1c 100644 --- a/src/server/ocpp/json/JsonOCPPServer.ts +++ b/src/server/ocpp/json/JsonOCPPServer.ts @@ -1,6 +1,7 @@ import * as uWS from 'uWebSockets.js'; import { App, HttpRequest, HttpResponse, WebSocket, us_socket_context_t } from 'uWebSockets.js'; +import FeatureToggles, { Feature } from '../../../utils/FeatureToggles'; import { ServerAction, ServerType, WSServerProtocol } from '../../../types/Server'; import { WebSocketAction, WebSocketCloseEventStatusCode, WebSocketPingResult } from '../../../types/WebSocket'; @@ -34,8 +35,12 @@ export default class JsonOCPPServer extends OCPPServer { public constructor(centralSystemConfig: CentralSystemConfiguration, chargingStationConfig: ChargingStationConfiguration) { super(centralSystemConfig, chargingStationConfig); - // Start job to clean WS connections - this.checkAndCleanupAllWebSockets(); + if (FeatureToggles.isFeatureActive(Feature.WS_SEND_PING_AUTOMATICALLY)) { + // Nothing to do - the uWS layer takes care to ping the WS for us! + } else { + // Start job to ping and clean WS connections (if necessary) + this.checkAndCleanupAllWebSockets(); + } // Monitor WS activity this.monitorWSConnections(); } @@ -43,12 +48,21 @@ export default class JsonOCPPServer extends OCPPServer { public start(): void { // Keep it global global.centralSystemJsonServer = this; + // uWS can send pings automatically before the idleTimeout is reached + let idleTimeout: number; + const sendPingsAutomatically = FeatureToggles.isFeatureActive(Feature.WS_SEND_PING_AUTOMATICALLY); + if (sendPingsAutomatically) { + idleTimeout = 2 * 60; // 2 minutes of inactivity close + } else { + idleTimeout = 3600; // 1 hour of inactivity ==> close + } // Start the WS server Logging.logConsoleDebug(`Starting ${ServerType.JSON_SERVER} Server...`); App({}).ws('/*', { compression: uWS.SHARED_COMPRESSOR, maxPayloadLength: 64 * 1024, // 64 KB per request - idleTimeout: 1 * 3600, // 1 hour of inactivity => Close + idleTimeout, + sendPingsAutomatically, upgrade: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => { // Delegate this.onUpgrade(res, req, context); @@ -63,15 +77,18 @@ export default class JsonOCPPServer extends OCPPServer { this.onMessage(ws, messageStr, isBinary).catch(() => { /* Intentional */ }); }, close: (ws: WebSocket, code: number, message: ArrayBuffer) => { - // Convert right away - const reason = Utils.convertBufferArrayToString(message); const wsWrapper = ws.wsWrapper as WSWrapper; - // Close - wsWrapper.closed = true; - this.logWSConnectionClosed(wsWrapper, ServerAction.WS_SERVER_CONNECTION_CLOSE, code, - `${WebSocketAction.CLOSE} > WS Connection ID '${wsWrapper.guid}' closed by charging station with code '${code}', reason: '${!Utils.isNullOrEmptyString(reason) ? reason : 'No reason given'}'`); - // Remove connection - this.removeWSWrapper(WebSocketAction.CLOSE, ServerAction.WS_SERVER_CONNECTION_CLOSE, wsWrapper); + try { + // Convert right away + const reason = Utils.convertBufferArrayToString(message); + // Close + wsWrapper.closed = true; + this.logWSConnectionClosed(wsWrapper, ServerAction.WS_SERVER_CONNECTION_CLOSE, code, + `${WebSocketAction.CLOSE} > WS Connection ID '${wsWrapper.guid}' closed by charging station with code '${code}', reason: '${!Utils.isNullOrEmptyString(reason) ? reason : 'No reason given'}'`); + } finally { + // Remove connection + this.removeWSWrapper(WebSocketAction.CLOSE, ServerAction.WS_SERVER_CONNECTION_CLOSE, wsWrapper); + } }, ping: (ws: WebSocket, message: ArrayBuffer) => { // Convert @@ -97,19 +114,24 @@ export default class JsonOCPPServer extends OCPPServer { ws.wsWrapper.wsConnection.onPong(ocppMessage); } } - // eslint-disable-next-line @typescript-eslint/no-misused-promises - }).any(Constants.HEALTH_CHECK_ROUTE, async (res: HttpResponse) => { + }).any(Constants.HEALTH_CHECK_ROUTE, (res: HttpResponse) => { res.onAborted(() => { res.aborted = true; }); - const pingSuccess = await global.database.ping(); - if (!res.aborted) { - if (pingSuccess) { - res.end('OK'); - } else { - res.writeStatus('500'); - res.end('KO'); - } + if (FeatureToggles.isFeatureActive(Feature.HEALTH_CHECK_PING_DATABASE)) { + global.database.ping().then((pingSuccess) => { + if (!res.aborted) { + if (pingSuccess) { + res.end('OK'); + } else { + res.writeStatus('500'); + res.end('KO'); + } + } + }).catch(() => { /* Intentional */ }); + } else { + // TODO - FIND ANOTHER METRIC TO CHECK THE READINESS and LIVENESS PROBE + res.end('OK'); } }).any('/*', (res: HttpResponse) => { res.writeStatus('404'); @@ -711,13 +733,12 @@ export default class JsonOCPPServer extends OCPPServer { } private checkAndCleanupAllWebSockets() { - // eslint-disable-next-line @typescript-eslint/no-misused-promises - setTimeout(async () => { + setTimeout(() => { try { // Check Json connections - await this.checkAndCleanupWebSockets(this.jsonWSConnections, 'CS'); + this.checkAndCleanupWebSockets(this.jsonWSConnections, 'CS'); // Check Rest connections - await this.checkAndCleanupWebSockets(this.jsonRestWSConnections, 'REST'); + this.checkAndCleanupWebSockets(this.jsonRestWSConnections, 'REST'); } finally { // Relaunch it this.checkAndCleanupAllWebSockets(); @@ -725,7 +746,7 @@ export default class JsonOCPPServer extends OCPPServer { }, Configuration.getChargingStationConfig().pingIntervalOCPPJSecs * 1000); } - private async checkAndCleanupWebSockets(wsConnections: Map, type: 'CS'|'REST') { + private checkAndCleanupWebSockets(wsConnections: Map, type: 'CS'|'REST'): void { const validConnections: Record[] = [], invalidConnections: Record[] = []; const timeStart = Date.now(); const wsConnectionKeys = Array.from(wsConnections.keys()); @@ -736,7 +757,7 @@ export default class JsonOCPPServer extends OCPPServer { // Get the WS const wsWrapper = wsConnection.getWS(); // Check WS - const result = await this.pingWebSocket(wsWrapper); + const result = this.pingWebSocket(wsWrapper); if (result.ok) { validConnections.push(this.getWSWrapperData(wsWrapper)); } else { diff --git a/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts b/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts index 555e7f0a8c..2b87797cf7 100644 --- a/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts +++ b/src/server/ocpp/json/web-socket/JsonRestWSConnection.ts @@ -82,10 +82,10 @@ export default class JsonRestWSConnection extends WSConnection { return result; } - public async onPing(message: string): Promise { + public onPing(message: string): void { } - public async onPong(message: string): Promise { + public onPong(message: string): void { } private isValidOcppClientCommand(command: Command): boolean { diff --git a/src/server/ocpp/json/web-socket/JsonWSConnection.ts b/src/server/ocpp/json/web-socket/JsonWSConnection.ts index e817aa748c..9f41553ffc 100644 --- a/src/server/ocpp/json/web-socket/JsonWSConnection.ts +++ b/src/server/ocpp/json/web-socket/JsonWSConnection.ts @@ -1,4 +1,5 @@ import ChargingStation, { Command } from '../../../../types/ChargingStation'; +import FeatureToggles, { Feature } from '../../../../utils/FeatureToggles'; import { OCPPProtocol, OCPPVersion } from '../../../../types/ocpp/OCPPServer'; import BackendError from '../../../../exception/BackendError'; @@ -120,12 +121,14 @@ export default class JsonWSConnection extends WSConnection { super.setChargingStation(chargingStation); } - public async onPing(message: string): Promise { - await this.updateChargingStationLastSeen(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public onPing(message: string): void { + this.updateChargingStationLastSeen().catch(() => { /* Intentional */ }); } - public async onPong(message: string): Promise { - await this.updateChargingStationLastSeen(); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public onPong(message: string): void { + this.updateChargingStationLastSeen().catch(() => { /* Intentional */ }); } private async updateChargingStationLastSeen(): Promise { @@ -134,11 +137,16 @@ export default class JsonWSConnection extends WSConnection { (Date.now() - this.lastSeen.getTime()) > (Configuration.getChargingStationConfig().pingIntervalOCPPJSecs * 1000 / 2)) { // Update last seen this.lastSeen = new Date(); - const chargingStation = await ChargingStationStorage.getChargingStation(this.getTenant(), - this.getChargingStationID(), { issuer: true }, ['id']); - if (chargingStation) { + if (FeatureToggles.isFeatureActive(Feature.OCPP_OPTIMIZE_LAST_SEEN_UPDATE)) { await ChargingStationStorage.saveChargingStationRuntimeData(this.getTenant(), this.getChargingStationID(), { lastSeen: this.lastSeen }); + } else { + const chargingStation = await ChargingStationStorage.getChargingStation(this.getTenant(), + this.getChargingStationID(), { issuer: true }, ['id']); + if (chargingStation) { + await ChargingStationStorage.saveChargingStationRuntimeData(this.getTenant(), this.getChargingStationID(), + { lastSeen: this.lastSeen }); + } } } } diff --git a/src/server/ocpp/json/web-socket/WSConnection.ts b/src/server/ocpp/json/web-socket/WSConnection.ts index 1771993344..dd6cea0dc2 100644 --- a/src/server/ocpp/json/web-socket/WSConnection.ts +++ b/src/server/ocpp/json/web-socket/WSConnection.ts @@ -342,7 +342,7 @@ export default abstract class WSConnection { public abstract handleRequest(command: Command, commandPayload: Record | string): Promise; - public abstract onPing(message: string): Promise; + public abstract onPing(message: string): void; - public abstract onPong(message: string): Promise; + public abstract onPong(message: string): void; } diff --git a/src/server/ocpp/services/OCPPService.ts b/src/server/ocpp/services/OCPPService.ts index d030c72569..d12c8717df 100644 --- a/src/server/ocpp/services/OCPPService.ts +++ b/src/server/ocpp/services/OCPPService.ts @@ -1,6 +1,7 @@ import { ChargePointErrorCode, ChargePointStatus, OCPPAttribute, OCPPAuthorizationStatus, OCPPAuthorizeRequestExtended, OCPPAuthorizeResponse, OCPPBootNotificationRequestExtended, OCPPBootNotificationResponse, OCPPDataTransferRequestExtended, OCPPDataTransferResponse, OCPPDataTransferStatus, OCPPDiagnosticsStatusNotificationRequestExtended, OCPPDiagnosticsStatusNotificationResponse, OCPPFirmwareStatusNotificationRequestExtended, OCPPFirmwareStatusNotificationResponse, OCPPHeartbeatRequestExtended, OCPPHeartbeatResponse, OCPPLocation, OCPPMeasurand, OCPPMeterValue, OCPPMeterValuesRequest, OCPPMeterValuesRequestExtended, OCPPMeterValuesResponse, OCPPNormalizedMeterValue, OCPPNormalizedMeterValues, OCPPPhase, OCPPProtocol, OCPPReadingContext, OCPPSampledValue, OCPPStartTransactionRequestExtended, OCPPStartTransactionResponse, OCPPStatusNotificationRequestExtended, OCPPStatusNotificationResponse, OCPPStopTransactionRequestExtended, OCPPStopTransactionResponse, OCPPUnitOfMeasure, OCPPValueFormat, OCPPVersion, RegistrationStatus } from '../../../types/ocpp/OCPPServer'; import { ChargingProfilePurposeType, ChargingRateUnitType } from '../../../types/ChargingProfile'; import ChargingStation, { ChargerVendor, Connector, ConnectorCurrentLimitSource, ConnectorType, CurrentType, StaticLimitAmps } from '../../../types/ChargingStation'; +import FeatureToggles, { Feature } from '../../../utils/FeatureToggles'; import Tenant, { TenantComponents } from '../../../types/Tenant'; import Transaction, { InactivityStatus, TransactionAction } from '../../../types/Transaction'; @@ -118,13 +119,15 @@ export default class OCPPService { if (!heartbeat) { heartbeat = {} as OCPPHeartbeatRequestExtended; } - OCPPValidator.getInstance().validateHeartbeat(heartbeat); - // Set Heart Beat Object - heartbeat.chargeBoxID = chargingStation.id; - heartbeat.timestamp = new Date(); - heartbeat.timezone = Utils.getTimezone(chargingStation.coordinates); - // Save Heart Beat - await OCPPStorage.saveHeartbeat(tenant, heartbeat); + if (FeatureToggles.isFeatureActive(Feature.OCPP_STORE_HEARTBEATS)) { + OCPPValidator.getInstance().validateHeartbeat(heartbeat); + // Set Heart Beat Object + heartbeat.chargeBoxID = chargingStation.id; + heartbeat.timestamp = new Date(); + heartbeat.timezone = Utils.getTimezone(chargingStation.coordinates); + // Save Heart Beat + await OCPPStorage.saveHeartbeat(tenant, heartbeat); + } Logging.beInfo()?.log({ ...LoggingHelper.getChargingStationProperties(chargingStation), tenantID: tenant.id, @@ -133,16 +136,13 @@ export default class OCPPService { message: 'Heartbeat saved', detailedMessages: { heartbeat } }); - return { - currentTime: new Date().toISOString() - }; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_HEARTBEAT, error, { heartbeat }); - return { - currentTime: new Date().toISOString() - }; } + return { + currentTime: new Date().toISOString() + }; } public async handleStatusNotification(headers: OCPPHeader, statusNotification: OCPPStatusNotificationRequestExtended): Promise { @@ -167,12 +167,11 @@ export default class OCPPService { // Update only the given Connector ID await this.processConnectorFromStatusNotification(tenant, chargingStation, statusNotification); } - return {}; } catch (error) { this.addChargingStationToException(error, headers.chargeBoxIdentity); Logging.logActionExceptionMessage(headers.tenantID, ServerAction.OCPP_STATUS_NOTIFICATION, error, { statusNotification }); - return {}; } + return {}; } public async handleMeterValues(headers: OCPPHeader, meterValues: OCPPMeterValuesRequestExtended): Promise { @@ -197,8 +196,10 @@ export default class OCPPService { } // Get Transaction const transaction = await this.getTransactionFromMeterValues(tenant, chargingStation, headers, meterValues); - // Save Meter Values - await OCPPStorage.saveMeterValues(tenant, normalizedMeterValues); + if (FeatureToggles.isFeatureActive(Feature.OCPP_STORE_METER_VALUES)) { + // Save Meter Values + await OCPPStorage.saveMeterValues(tenant, normalizedMeterValues); + } // Update Transaction this.updateTransactionWithMeterValues(chargingStation, transaction, normalizedMeterValues.values); // Create Consumptions @@ -752,7 +753,7 @@ export default class OCPPService { detailedMessages: { statusNotification, connector } }); // Notify Users - await this.notifyStatusNotification(tenant, chargingStation, connector, statusNotification); + this.notifyStatusNotification(tenant, chargingStation, connector, statusNotification); } } @@ -955,7 +956,7 @@ export default class OCPPService { return transactionUpdated; } - private async notifyStatusNotification(tenant: Tenant, chargingStation: ChargingStation, connector: Connector, statusNotification: OCPPStatusNotificationRequestExtended) { + private notifyStatusNotification(tenant: Tenant, chargingStation: ChargingStation, connector: Connector, statusNotification: OCPPStatusNotificationRequestExtended): void { // Faulted? if (connector.status !== ChargePointStatus.AVAILABLE && connector.status !== ChargePointStatus.FINISHING && // TODO: To remove after fix of ABB bug having Finishing status with an Error Code to avoid spamming Admins diff --git a/src/utils/FeatureToggles.ts b/src/utils/FeatureToggles.ts index 58ee7044e6..316d116216 100644 --- a/src/utils/FeatureToggles.ts +++ b/src/utils/FeatureToggles.ts @@ -5,6 +5,11 @@ export enum Feature { BILLING_PREVENT_CUSTOMER_DELETION, BILLING_SHOW_PRICING_DETAIL, BILLING_PLATFORM_USE_EXPRESS_ACCOUNT, + WS_SEND_PING_AUTOMATICALLY, + OCPP_STORE_HEARTBEATS, + OCPP_STORE_METER_VALUES, + OCPP_OPTIMIZE_LAST_SEEN_UPDATE, + HEALTH_CHECK_PING_DATABASE, } export default class FeatureToggles { @@ -13,6 +18,11 @@ export default class FeatureToggles { Feature.BILLING_INVOICES_EXCLUDE_PENDING_ITEMS, Feature.BILLING_PREVENT_CUSTOMER_DELETION, Feature.BILLING_PLATFORM_USE_EXPRESS_ACCOUNT, + Feature.WS_SEND_PING_AUTOMATICALLY, + // Feature.OCPP_STORE_HEARTBEATS, + // Feature.OCPP_STORE_METER_VALUES, + Feature.OCPP_OPTIMIZE_LAST_SEEN_UPDATE, + // Feature.HEALTH_CHECK_PING_DATABASE ]; // Check whether the feature is active or not! From 0010af8b07171ddc1033e51bcaadab39468b1e87 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Thu, 29 Dec 2022 15:59:06 +0100 Subject: [PATCH 11/11] ocpp - monitor memory usage --- src/server/ocpp/json/JsonOCPPServer.ts | 41 ++++++++++++++++++++++++++ src/utils/FeatureToggles.ts | 4 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/server/ocpp/json/JsonOCPPServer.ts b/src/server/ocpp/json/JsonOCPPServer.ts index 40a98c8d1c..ab6744c347 100644 --- a/src/server/ocpp/json/JsonOCPPServer.ts +++ b/src/server/ocpp/json/JsonOCPPServer.ts @@ -43,6 +43,10 @@ export default class JsonOCPPServer extends OCPPServer { } // Monitor WS activity this.monitorWSConnections(); + // Monitor Memory Usage + if (FeatureToggles.isFeatureActive(Feature.OCPP_MONITOR_MEMORY_USAGE)) { + this.monitorMemoryUsage(); + } } public start(): void { @@ -732,6 +736,43 @@ export default class JsonOCPPServer extends OCPPServer { }, Configuration.getChargingStationConfig().monitoringIntervalOCPPJSecs * 1000); } + private monitorMemoryUsage() { + setInterval(() => { + try { + // get Node memory usage + const beginDate = new Date().getTime(); + const memoryUsage = process.memoryUsage(); + const elapsedTime = new Date().getTime() - beginDate; + const memoryUsagePercentage = ((memoryUsage.heapUsed / memoryUsage.rss) * 100); + const usagePercentage = memoryUsagePercentage.toFixed(2); + const heapTotal = (memoryUsage.heapTotal / 1024 / 1024).toFixed(2); + const heapUsed = (memoryUsage.heapUsed / 1024 / 1024).toFixed(2); + const external = (memoryUsage.external / 1024 / 1024).toFixed(2); + const rss = (memoryUsage.rss / 1024 / 1024).toFixed(2); // total amount of memory allocated to the process - to be clarified! + const message = `Memory Usage ${usagePercentage}% - total heap: ${heapTotal} MiB - heap used: ${heapUsed} MiB - rss: ${rss} MiB - external: ${external} MiB - elapsed time: ${elapsedTime}`; + const dataToLog = { + tenantID: Constants.DEFAULT_TENANT_ID, + action: ServerAction.PERFORMANCES, module: MODULE_NAME, method: 'monitorMemoryUsage', + message + }; + // TODO - remove it - JUST FOR TROUBLESHOOTING STRESS TESTS + Logging.beError()?.log(dataToLog); + // if (memoryUsagePercentage > 90) { + // Logging.beError()?.log(dataToLog); + // } else if (memoryUsagePercentage > 80) { + // Logging.beWarning()?.log(dataToLog); + // } else { + // Logging.beDebug()?.log(dataToLog); + // } + if (this.isDebug()) { + Logging.logConsoleDebug(message); + } + } catch (error) { + /* Intentional */ + } + }, 5 * 60 * 1000); // every minute - TODO - add new configuration for it! + } + private checkAndCleanupAllWebSockets() { setTimeout(() => { try { diff --git a/src/utils/FeatureToggles.ts b/src/utils/FeatureToggles.ts index 316d116216..435037c8e0 100644 --- a/src/utils/FeatureToggles.ts +++ b/src/utils/FeatureToggles.ts @@ -9,6 +9,7 @@ export enum Feature { OCPP_STORE_HEARTBEATS, OCPP_STORE_METER_VALUES, OCPP_OPTIMIZE_LAST_SEEN_UPDATE, + OCPP_MONITOR_MEMORY_USAGE, HEALTH_CHECK_PING_DATABASE, } @@ -22,7 +23,8 @@ export default class FeatureToggles { // Feature.OCPP_STORE_HEARTBEATS, // Feature.OCPP_STORE_METER_VALUES, Feature.OCPP_OPTIMIZE_LAST_SEEN_UPDATE, - // Feature.HEALTH_CHECK_PING_DATABASE + Feature.OCPP_MONITOR_MEMORY_USAGE, + // Feature.HEALTH_CHECK_PING_DATABASE, ]; // Check whether the feature is active or not!