From 91435656e03b43374006ff48aec3f10b1319aea6 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 19 Jun 2024 11:16:56 +0200 Subject: [PATCH] add decayLoggingView use in balanceResolver.balance to compress log output --- .../src/graphql/resolver/BalanceResolver.ts | 9 +++++---- backend/src/logging/DecayLogging.view.ts | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 backend/src/logging/DecayLogging.view.ts diff --git a/backend/src/graphql/resolver/BalanceResolver.ts b/backend/src/graphql/resolver/BalanceResolver.ts index a702cc08f..8103e0cff 100644 --- a/backend/src/graphql/resolver/BalanceResolver.ts +++ b/backend/src/graphql/resolver/BalanceResolver.ts @@ -15,6 +15,7 @@ import { calculateDecay } from '@/util/decay' import { GdtResolver } from './GdtResolver' import { getLastTransaction } from './util/getLastTransaction' import { transactionLinkSummary } from './util/transactionLinkSummary' +import { DecayLoggingView } from '@/logging/DecayLogging.view' @Resolver() export class BalanceResolver { @@ -85,9 +86,9 @@ export class BalanceResolver { ) logger.info( 'calculatedDecay', - lastTransaction.balance, - lastTransaction.balanceDate, - calculatedDecay, + lastTransaction.balance.toString(), + lastTransaction.balanceDate.toISOString(), + new DecayLoggingView(calculatedDecay), ) // The final balance is reduced by the link amount withheld @@ -115,7 +116,7 @@ export class BalanceResolver { count, linkCount, }) - logger.info('new Balance', balance, balanceGDT, count, linkCount, newBalance) + logger.info('new Balance', balance.toString(), balanceGDT?.toString(), count, linkCount, newBalance.toString()) return newBalance } diff --git a/backend/src/logging/DecayLogging.view.ts b/backend/src/logging/DecayLogging.view.ts new file mode 100644 index 000000000..aef7c6da6 --- /dev/null +++ b/backend/src/logging/DecayLogging.view.ts @@ -0,0 +1,20 @@ +import { Decay } from '@/graphql/model/Decay' +import { AbstractLoggingView } from '@logging/AbstractLogging.view' + +export class DecayLoggingView extends AbstractLoggingView { + public constructor(private self: Decay) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + balance: this.decimalToString(this.self.balance), + decay: this.decimalToString(this.self.decay), + roundedDecay: this.decimalToString(this.self.roundedDecay), + start: this.dateToString(this.self.start), + end: this.dateToString(this.self.end), + duration: this.self.duration + } + } +}