55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { z } from 'zod';
|
|
import { Fastify } from '../types';
|
|
|
|
export function devRoutes(app: Fastify) {
|
|
|
|
// Combined logging endpoint (only when explicitly enabled)
|
|
if (process.env.DANGEROUSLY_LOG_TO_SERVER_FOR_AI_AUTO_DEBUGGING) {
|
|
app.post('/logs-combined-from-cli-and-mobile-for-simple-ai-debugging', {
|
|
schema: {
|
|
body: z.object({
|
|
timestamp: z.string(),
|
|
level: z.string(),
|
|
message: z.string(),
|
|
messageRawObject: z.any().optional(),
|
|
source: z.enum(['mobile', 'cli']),
|
|
platform: z.string().optional()
|
|
})
|
|
}
|
|
}, async (request, reply) => {
|
|
const { timestamp, level, message, source, platform } = request.body;
|
|
|
|
// Log ONLY to separate remote logger (file only, no console)
|
|
const logData = {
|
|
source,
|
|
platform,
|
|
timestamp
|
|
};
|
|
|
|
// Use the file-only logger if available
|
|
const { fileConsolidatedLogger } = await import('@/utils/log');
|
|
|
|
if (!fileConsolidatedLogger) {
|
|
// Should never happen since we check env var above, but be safe
|
|
return reply.send({ success: true });
|
|
}
|
|
|
|
switch (level.toLowerCase()) {
|
|
case 'error':
|
|
fileConsolidatedLogger.error(logData, message);
|
|
break;
|
|
case 'warn':
|
|
case 'warning':
|
|
fileConsolidatedLogger.warn(logData, message);
|
|
break;
|
|
case 'debug':
|
|
fileConsolidatedLogger.debug(logData, message);
|
|
break;
|
|
default:
|
|
fileConsolidatedLogger.info(logData, message);
|
|
}
|
|
|
|
return reply.send({ success: true });
|
|
});
|
|
}
|
|
} |