pricing - pffff - logs :(
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -17,6 +17,7 @@ import Constants from '../../../utils/Constants';
import Cypher from '../../../utils/Cypher';
import I18nManager from '../../../utils/I18nManager';
import Logging from '../../../utils/Logging';
+import LoggingHelper from '../../../utils/LoggingHelper';
import PricingEngine from '../../pricing/PricingEngine';
import PricingHelper from '../../pricing/PricingHelper';
import { Request } from 'express';
@@ -31,6 +32,7 @@ import Utils from '../../../utils/Utils';
import moment from 'moment';
const MODULE_NAME = 'StripeBillingIntegration';
+
export default class StripeBillingIntegration extends BillingIntegration {
private static readonly STRIPE_MAX_LIST = 100;
@@ -1108,9 +1110,14 @@ export default class StripeBillingIntegration extends BillingIntegration {
pricingData = [ PricingHelper.accumulatePricedConsumption(pricingData) ] ;
}
pricingData = pricingData.map((pricingConsumptionData) => this.enrichTransactionPricingData(transaction, pricingConsumptionData));
- void PricingHelper.logInfo(this.tenant, transaction, {
+ void Logging.logInfo({
+ tenantID: this.tenant.id,
+ module: MODULE_NAME,
+ action: ServerAction.PRICING,
+ method: 'resolvePricingContext',
message: `Final pricing - Transaction: ${transaction.id}`,
detailedMessages: pricingData,
+ ...LoggingHelper.getSessionProperties(transaction)
});
return pricingData;
}

MODIFY
src/integration/pricing/PricingEngine.ts
src/integration/pricing/PricingEngine.ts
@@ -6,13 +6,17 @@ import ChargingStation from '../../types/ChargingStation';
import Constants from '../../utils/Constants';
import Consumption from '../../types/Consumption';
import ConsumptionPricer from './ConsumptionPricer';
-import PricingHelper from './PricingHelper';
+import Logging from '../../utils/Logging';
+import LoggingHelper from '../../utils/LoggingHelper';
import PricingStorage from '../../storage/mongodb/PricingStorage';
+import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
import Transaction from '../../types/Transaction';
import Utils from '../../utils/Utils';
import moment from 'moment';
+const MODULE_NAME = 'PricingEngine';
+
export default class PricingEngine {
public static async resolvePricingContext(tenant: Tenant, transaction: Transaction, chargingStation: ChargingStation): Promise<ResolvedPricingModel> {
@@ -35,9 +39,14 @@ export default class PricingEngine {
},
pricingDefinitions
};
- await PricingHelper.logInfo(tenant, transaction, {
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ module: MODULE_NAME,
+ action: ServerAction.PRICING,
+ method: 'resolvePricingContext',
message: `Pricing context has been resolved - ${pricingDefinitions.length} pricing definitions have been found`,
- detailedMessages: { resolvedPricingModel }
+ detailedMessages: { resolvedPricingModel },
+ ...LoggingHelper.getSessionProperties(transaction)
});
return Promise.resolve(resolvedPricingModel);
}
@@ -66,9 +75,13 @@ export default class PricingEngine {
).map((pricingDefinition) =>
PricingEngine.shrinkPricingDefinition(pricingDefinition)
);
- await PricingHelper.logInfo(tenant, transaction, {
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ module: MODULE_NAME,
+ action: ServerAction.PRICING,
method: 'getPricingDefinitions4Entity',
- message: `Pricing context resolution - ${actualPricingDefinitions.length || 0} pricing definitions found for ${entityType}: '${entityID}'`
+ message: `Pricing context resolution - ${actualPricingDefinitions.length || 0} pricing definitions found for ${entityType}: '${entityID}'`,
+ ...LoggingHelper.getSessionProperties(transaction)
});
return actualPricingDefinitions || [];
}

MODIFY
src/integration/pricing/PricingHelper.ts
src/integration/pricing/PricingHelper.ts
import { DimensionType, PricedConsumptionData, PricedDimensionData, PricingDimensions } from '../../types/Pricing';
import Decimal from 'decimal.js';
-import { Log } from '../../types/Log';
-import Logging from '../../utils/Logging';
-import { ServerAction } from '../../types/Server';
-import Tenant from '../../types/Tenant';
-import Transaction from '../../types/Transaction';
import Utils from '../../utils/Utils';
export default class PricingHelper {
@@ -67,34 +62,4 @@ export default class PricingHelper {
accumulatedData[dimensionType].roundedAmount = Utils.createDecimal(accumulatedData[dimensionType].roundedAmount).plus(pricedData[dimensionType].roundedAmount).toNumber();
}
}
-
- public static async logInfo(tenant: Tenant, transaction: Transaction, params: Partial<Log>): Promise<void> {
- const commonProperties = PricingHelper.getLogCommonProperties(tenant, transaction);
- await Logging.logInfo({
- ...commonProperties,
- ...params,
- } as Log);
- }
-
- public static async logWarning(tenant: Tenant, transaction: Transaction, params: Partial<Log>): Promise<void> {
- const commonProperties = PricingHelper.getLogCommonProperties(tenant, transaction);
- await Logging.logWarning({
- ...commonProperties,
- ...params,
- } as Log);
- }
-
- public static getLogCommonProperties(tenant: Tenant, transaction: Transaction): Partial<Log> {
- return {
- tenantID: tenant.id,
- siteID: transaction.siteID,
- siteAreaID: transaction.siteAreaID,
- companyID: transaction.companyID,
- chargingStationID: transaction.chargeBoxID,
- source: transaction.chargeBoxID,
- actionOnUser: transaction.user,
- action: ServerAction.PRICING,
- };
- }
-
}

MODIFY
src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts
src/integration/pricing/simple-pricing/BuiltInPricingIntegration.ts
@@ -4,14 +4,19 @@ import { PricedConsumption, PricingDimensions, PricingSource, ResolvedPricingDef
import ChargingStation from '../../../types/ChargingStation';
import Consumption from '../../../types/Consumption';
+import Logging from '../../../utils/Logging';
+import LoggingHelper from '../../../utils/LoggingHelper';
import PricingEngine from '../PricingEngine';
import PricingHelper from '../PricingHelper';
import PricingIntegration from '../PricingIntegration';
+import { ServerAction } from '../../../types/Server';
import { SimplePricingSetting } from '../../../types/Setting';
import Tenant from '../../../types/Tenant';
import Transaction from '../../../types/Transaction';
import Utils from '../../../utils/Utils';
+const MODULE_NAME = 'BuiltInPricingIntegration';
+
export default class BuiltInPricingIntegration extends PricingIntegration<SimplePricingSetting> {
constructor(tenant: Tenant, readonly settings: SimplePricingSetting) {
super(tenant, settings);
@@ -19,25 +24,32 @@ export default class BuiltInPricingIntegration extends PricingIntegration<Simple
public async startSession(transaction: Transaction, consumptionData: Consumption, chargingStation: ChargingStation): Promise<PricedConsumption> {
const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation);
- await PricingHelper.logInfo(this.tenant, transaction, {
+ await Logging.logInfo({
+ tenantID: this.tenant.id,
+ module: MODULE_NAME,
+ action: ServerAction.PRICING,
+ method: 'startSession',
message: `Session START - Transaction: ${transaction.id} - Accumulated amount: ${pricedConsumption.cumulatedRoundedAmount} ${pricedConsumption.currencyCode}`,
+ ...LoggingHelper.getSessionProperties(transaction)
});
return pricedConsumption;
}
public async updateSession(transaction: Transaction, consumptionData: Consumption, chargingStation: ChargingStation): Promise<PricedConsumption> {
const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation);
- // await PricingHelper.logInfo(this.tenant, transaction, {
- // message: `Session UPDATE - Transaction: ${transaction.id} - Accumulated amount: ${pricedConsumption.cumulatedRoundedAmount} ${pricedConsumption.currencyCode}`,
- // });
return pricedConsumption;
}
public async stopSession(transaction: Transaction, consumptionData: Consumption, chargingStation: ChargingStation): Promise<PricedConsumption> {
const pricedConsumption = await this.computePrice(transaction, consumptionData, chargingStation);
- await PricingHelper.logInfo(this.tenant, transaction, {
+ await Logging.logInfo({
+ tenantID: this.tenant.id,
+ module: MODULE_NAME,
+ action: ServerAction.PRICING,
+ method: 'stopSession',
message: `Session STOP - Transaction: ${transaction.id} - Accumulated amount: ${pricedConsumption.cumulatedRoundedAmount} ${pricedConsumption.currencyCode}`,
- detailedMessages: { pricedConsumption }
+ detailedMessages: { pricedConsumption },
+ ...LoggingHelper.getSessionProperties(transaction)
});
return pricedConsumption;
}
@@ -88,9 +100,14 @@ export default class BuiltInPricingIntegration extends PricingIntegration<Simple
const resolvedPricingModel: ResolvedPricingModel = await PricingEngine.resolvePricingContext(tenant, transaction, chargingStation);
if (!resolvedPricingModel.pricingDefinitions?.length) {
resolvedPricingModel.pricingDefinitions = [ this.getDefaultPricingDefinition() ];
- await PricingHelper.logWarning(tenant, transaction, {
+ await Logging.logWarning({
+ tenantID: this.tenant.id,
+ module: MODULE_NAME,
+ action: ServerAction.PRICING,
+ method: 'resolvePricingContext',
message: 'No pricing definition found - Simple Pricing logic will be used as a fallback',
- detailedMessages: { resolvedPricingModel }
+ detailedMessages: { resolvedPricingModel },
+ ...LoggingHelper.getSessionProperties(transaction)
});
}
return resolvedPricingModel;

ADD
src/utils/LoggingHelper.ts
+import { Log } from '../types/Log';
+import Transaction from '../types/Transaction';
+
+export default class LoggingHelper {
+
+ public static getSessionProperties(transaction: Transaction): Partial<Log> {
+ return {
+ siteID: transaction.siteID,
+ siteAreaID: transaction.siteAreaID,
+ companyID: transaction.companyID,
+ chargingStationID: transaction.chargeBoxID,
+ source: transaction.chargeBoxID,
+ actionOnUser: transaction.user,
+ };
+ }
+}

pricing - pffff - logs :(