refactor: structured logging across server
Create server/src/lib/logger.ts with info/warn/error methods that add [botfights:tag] timestamps. Replace bare console.log/warn/error calls in index.ts, seed.ts, routes/fights.ts, engine/queue.ts, engine/mock.ts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
7bd110684d
commit
f62323c59f
@@ -1,4 +1,5 @@
|
||||
import { db, schema } from '../db/index.js'
|
||||
import { logger } from '../lib/logger.js'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import { runFightAsync, isInFight } from './orchestrator.js'
|
||||
import { seedMockBots } from './mock.js'
|
||||
@@ -69,7 +70,7 @@ export async function joinQueue(botId: string): Promise<string> {
|
||||
throw new Error('Bot is deactivated due to webhook errors. Re-test your webhook to reactivate.')
|
||||
}
|
||||
|
||||
console.log(`[queue] joinQueue botId=${botId} name=${bot.name} webhook=${bot.webhookUrl}`)
|
||||
logger.info('queue', `joinQueue botId=${botId} name=${bot.name} webhook=${bot.webhookUrl}`)
|
||||
|
||||
// Don't allow same bot twice in queue
|
||||
const existing = waitingQueue.findIndex(e => e.botId === botId)
|
||||
@@ -145,7 +146,7 @@ async function startFight(botAId: string, botBId: string): Promise<string> {
|
||||
}
|
||||
|
||||
async function matchAgainstMock(botId: string, webhookUrl: string): Promise<string> {
|
||||
console.log(`[queue] matchAgainstMock botId=${botId} webhook=${webhookUrl}`)
|
||||
logger.info('queue', `matchAgainstMock botId=${botId} webhook=${webhookUrl}`)
|
||||
const allBots = await db.select({
|
||||
id: schema.bots.id,
|
||||
webhookUrl: schema.bots.webhookUrl,
|
||||
@@ -155,7 +156,7 @@ async function matchAgainstMock(botId: string, webhookUrl: string): Promise<stri
|
||||
const mockBots = allBots.filter(b => b.id !== botId && b.webhookUrl.startsWith('http://mock.local'))
|
||||
|
||||
if (mockBots.length === 0) {
|
||||
console.log('[queue] No mock bots found, seeding...')
|
||||
logger.info('queue', 'No mock bots found, seeding...')
|
||||
await seedMockBots()
|
||||
return matchAgainstMock(botId, webhookUrl)
|
||||
}
|
||||
@@ -166,6 +167,6 @@ async function matchAgainstMock(botId: string, webhookUrl: string): Promise<stri
|
||||
mockBots.sort((a, b) => Math.abs(a.eloRating - botElo) - Math.abs(b.eloRating - botElo))
|
||||
const opponent = mockBots[0]
|
||||
|
||||
console.log(`[queue] starting fight: ${botId} vs mock ${opponent.id}`)
|
||||
logger.info('queue', `starting fight: ${botId} vs mock ${opponent.id}`)
|
||||
return runFightAsync(botId, opponent.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user