check-log.ts 1.0 KB

12345678910111213141516171819202122
  1. const { prisma } = require('../src/models');
  2. async function check() {
  3. const count = await prisma.aiCallLog.count();
  4. console.log('AiCallLog 总记录:', count);
  5. if (count > 0) {
  6. const latest = await prisma.aiCallLog.findMany({ take: 15, orderBy: { id: 'desc' } });
  7. console.log('\n最近 15 条:');
  8. latest.forEach(l =>
  9. console.log(` ${l.callType.padEnd(14)} ${l.provider.padEnd(18)} ${l.success ? 'OK' : 'FAIL'} ${String(l.duration).padStart(6)}ms ${String(l.textLen || '').padStart(6)}字 ${l.errorMsg || ''}`)
  10. );
  11. const stats: any = await prisma.$queryRaw`SELECT callType, COUNT(*) as cnt, SUM(duration) as totalMs FROM AiCallLog GROUP BY callType ORDER BY cnt DESC`;
  12. console.log('\n按类型统计:');
  13. stats.forEach((s: any) => console.log(` ${s.callType}: ${s.cnt}次, ${Math.round(s.totalMs / 1000)}s`));
  14. } else {
  15. console.log('(日志为空,服务可能未重启加载新代码)');
  16. }
  17. await prisma.$disconnect();
  18. }
  19. check().catch(e => { console.error(e); process.exit(1); });