From 378343e13624f68eb5255db662fe709a089fb7a2 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Fri, 1 Mar 2024 13:42:04 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=96=A5=EF=B8=8F=20feat:=20Match=20STDOUT?= =?UTF-8?q?=20Logs=20with=20Debug=20File=20Logs=20(#1944)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: improve token balance logging post-request * feat: match stdout logging with file debug logging when using DEBUG_CONSOLE --- config/winston.js | 2 +- models/Transaction.js | 8 +++++++- models/spendTokens.js | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/winston.js b/config/winston.js index 6cba153f163..0c167b807ff 100644 --- a/config/winston.js +++ b/config/winston.js @@ -106,7 +106,7 @@ if ( transports.push( new winston.transports.Console({ level: 'debug', - format: winston.format.combine(consoleFormat, debugTraverse), + format: winston.format.combine(fileFormat, debugTraverse), }), ); } else { diff --git a/models/Transaction.js b/models/Transaction.js index e608203592e..dcca3315a4a 100644 --- a/models/Transaction.js +++ b/models/Transaction.js @@ -36,11 +36,17 @@ transactionSchema.statics.create = async function (transactionData) { } // Adjust the user's balance - return await Balance.findOneAndUpdate( + const updatedBalance = await Balance.findOneAndUpdate( { user: transaction.user }, { $inc: { tokenCredits: transaction.tokenValue } }, { upsert: true, new: true }, ).lean(); + + return { + user: transaction.user.toString(), + [transaction.tokenType]: transaction.tokenValue, + balance: updatedBalance.tokenCredits, + }; }; module.exports = mongoose.model('Transaction', transactionSchema); diff --git a/models/spendTokens.js b/models/spendTokens.js index f52075b13d1..3d83581762e 100644 --- a/models/spendTokens.js +++ b/models/spendTokens.js @@ -49,8 +49,10 @@ const spendTokens = async (txData, tokenUsage) => { prompt && completion && logger.debug('[spendTokens] Transaction data record against balance:', { - prompt, - completion, + user: prompt.user, + prompt: prompt.prompt, + completion: completion.completion, + balance: completion.balance, }); } catch (err) { logger.error('[spendTokens]', err);