Skip to content

Commit

Permalink
🖥️ feat: Match STDOUT Logs with Debug File Logs (danny-avila#1944)
Browse files Browse the repository at this point in the history
* chore: improve token balance logging post-request

* feat: match stdout logging with file debug logging when using DEBUG_CONSOLE
  • Loading branch information
danny-avila authored Mar 1, 2024
1 parent 1a870c7 commit 378343e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/winston.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion models/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 4 additions & 2 deletions models/spendTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 378343e

Please sign in to comment.