fix: enable debug logging and improve DCL sync observability
- Fix logger bug where debug level (0) was treated as falsy - Change `||` to `??` in config.js to properly handle log level 0 - Debug logs now work correctly when LOG_LEVEL=debug - Add server startup logging - Log port, environment, and log level on server start - Helps verify configuration is loaded correctly - Add DCL API request debug logging - Log full API request parameters when LOG_LEVEL=debug - API key is redacted (shows first/last 4 chars only) - Helps troubleshoot DCL sync issues - Update CLAUDE.md documentation - Add Logging section with log levels and configuration - Document debug logging feature for DCL service - Add this fix to Recent Commits section Note: .env file added locally with LOG_LEVEL=debug (not committed) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Elysia, t } from 'elysia';
|
||||
import { cors } from '@elysiajs/cors';
|
||||
import { jwt } from '@elysiajs/jwt';
|
||||
import { JWT_SECRET, logger } from './config.js';
|
||||
import { JWT_SECRET, logger, LOG_LEVEL } from './config.js';
|
||||
import {
|
||||
registerUser,
|
||||
authenticateUser,
|
||||
@@ -283,13 +283,13 @@ const app = new Elysia()
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await enqueueJob(user.id);
|
||||
const result = await enqueueJob(user.id, 'lotw_sync');
|
||||
|
||||
if (!result.success && result.existingJob) {
|
||||
return {
|
||||
success: true,
|
||||
jobId: result.existingJob,
|
||||
message: 'A sync job is already running',
|
||||
message: 'A LoTW sync job is already running',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -299,7 +299,41 @@ const app = new Elysia()
|
||||
set.status = 500;
|
||||
return {
|
||||
success: false,
|
||||
error: `Failed to queue sync job: ${error.message}`,
|
||||
error: `Failed to queue LoTW sync job: ${error.message}`,
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* POST /api/dcl/sync
|
||||
* Queue a DCL sync job (requires authentication)
|
||||
* Returns immediately with job ID
|
||||
*/
|
||||
.post('/api/dcl/sync', async ({ user, set }) => {
|
||||
if (!user) {
|
||||
logger.warn('/api/dcl/sync: Unauthorized access attempt');
|
||||
set.status = 401;
|
||||
return { success: false, error: 'Unauthorized' };
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await enqueueJob(user.id, 'dcl_sync');
|
||||
|
||||
if (!result.success && result.existingJob) {
|
||||
return {
|
||||
success: true,
|
||||
jobId: result.existingJob,
|
||||
message: 'A DCL sync job is already running',
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('Error in /api/dcl/sync', { error: error.message });
|
||||
set.status = 500;
|
||||
return {
|
||||
success: false,
|
||||
error: `Failed to queue DCL sync job: ${error.message}`,
|
||||
};
|
||||
}
|
||||
})
|
||||
@@ -703,3 +737,9 @@ const app = new Elysia()
|
||||
|
||||
// Start server - uses PORT environment variable if set, otherwise defaults to 3001
|
||||
.listen(process.env.PORT || 3001);
|
||||
|
||||
logger.info('Server started', {
|
||||
port: process.env.PORT || 3001,
|
||||
nodeEnv: process.env.NODE_ENV || 'unknown',
|
||||
logLevel: LOG_LEVEL,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user