Add in Pino logging and make UI consistent across the app.

This commit is contained in:
Cameron Redmore 2025-04-25 19:34:17 +01:00
parent 727746030c
commit 300040bd58
19 changed files with 590 additions and 235 deletions

View file

@ -10,8 +10,6 @@ export async function askGemini(content)
const GOOGLE_API_KEY = await getSetting('GEMINI_API_KEY');
console.log('Google API Key:', GOOGLE_API_KEY); // Debugging line to check the key
if (!GOOGLE_API_KEY)
{
throw new Error('Google API key is not set in the database.');

View file

@ -0,0 +1,47 @@
import { PrismaClient } from '@prisma/client';
import build from 'pino-abstract-transport';
const prisma = new PrismaClient();
export default async function(opts)
{
return build(async(source) =>
{
for await (const obj of source)
{
try
{
const { time, level, msg, ...meta } = obj;
// Pino levels are numeric, convert to string names if needed
const levelMap = {
'10': 'trace',
'20': 'debug',
'30': 'info',
'40': 'warn',
'50': 'error',
'60': 'fatal'
};
const levelString = levelMap[level] || 'info'; // Default to info
await prisma.log.create({
data: {
timestamp: new Date(time),
level: levelString,
message: msg,
// Store remaining properties in the meta field if it exists
meta: Object.keys(meta).length > 0 ? meta : undefined,
},
});
}
catch (error)
{
console.error('Failed to write log to database:', error);
}
}
}, {
async close(err)
{
await prisma.$disconnect();
}
});
}