Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

Refactor: Remove verbose console logging from various modules and increase Fastify's body limit to 5MB.

luoleibbf7d9586db9
diff --git a/apps/collector/src/database/repositories/base.repository.ts b/apps/collector/src/database/repositories/base.repository.ts
index 72ce335..928e189 100644
--- a/apps/collector/src/database/repositories/base.repository.ts
+++ b/apps/collector/src/database/repositories/base.repository.ts
@@ -263,18 +263,13 @@ export abstract class BaseRepository {
return [];
}
- // Debug logging for Agent mode chain enrichment
- if (proxyConfig && chainParts.length < 3) {
- console.info(`[buildRuleFlowPath] Rule: ${rule}, Chain: ${chain}, Parts: ${JSON.stringify(chainParts)}, ProxyConfig keys: ${Object.keys(proxyConfig).length}`);
- }
+ // Debug logging removed to reduce noise in production
// Enrich chain with proxy config if available and chain is short
let enrichedParts = chainParts;
if (proxyConfig && chainParts.length < 3) {
enrichedParts = this.enrichChainWithProxyConfig(chainParts, proxyConfig);
- if (enrichedParts.length > chainParts.length) {
- console.info(`[buildRuleFlowPath] Enriched: ${JSON.stringify(chainParts)} -> ${JSON.stringify(enrichedParts)}`);
- }
+ // Chain enrichment result logging removed
}
// Try to find rule in enriched chain
@@ -324,9 +319,7 @@ export abstract class BaseRepository {
return chainParts;
}
- // Debug: log proxyConfig sample
- const sampleEntries = Object.entries(proxyConfig).slice(0, 3);
- console.info(`[enrichChain] chainParts: ${JSON.stringify(chainParts)}, proxyConfig sample: ${JSON.stringify(sampleEntries)}`);
+ // Debug logging removed to reduce noise in production
// Build complete path by tracing backwards through proxy config
const completePath = [...chainParts];
@@ -342,7 +335,7 @@ export abstract class BaseRepository {
let foundParent = false;
for (const [name, config] of Object.entries(proxyConfig)) {
if (config.now === current && !visited.has(name)) {
- console.info(`[enrichChain] Found parent: ${name}.now = ${config.now} (current: ${current})`);
+ // Parent found in proxy config
completePath.push(name);
visited.add(name);
current = name;
@@ -351,8 +344,7 @@ export abstract class BaseRepository {
}
}
if (!foundParent) {
- console.info(`[enrichChain] No parent found for current: ${current}`);
- break;
+ break; // No parent found
}
iterations++;
}
@@ -367,13 +359,10 @@ export abstract class BaseRepository {
// Current completePath: [finalProxy, group1, group2] (where group2.now = group1, group1.now = finalProxy)
// We want: [group2, group1, finalProxy] for proper flow path
- const result = completePath.reverse();
- console.info(`[enrichChain] Result: ${JSON.stringify(result)}`);
- return result;
+ return completePath.reverse();
}
- console.info(`[enrichChain] No enrichment possible, returning original`);
- return chainParts;
+ return chainParts; // No enrichment possible
}
/**
diff --git a/apps/collector/src/database/repositories/rule.repository.ts b/apps/collector/src/database/repositories/rule.repository.ts
index f0cb272..6a1fa06 100644
--- a/apps/collector/src/database/repositories/rule.repository.ts
+++ b/apps/collector/src/database/repositories/rule.repository.ts
@@ -433,11 +433,11 @@ export class RuleRepository extends BaseRepository {
FROM rule_chain_traffic WHERE backend_id = ? ORDER BY rule, chain
`);
rows = stmt.all(backendId) as typeof rows;
- console.info(`[getAllRuleChainFlows] DB rows count: ${rows.length}, sample: ${JSON.stringify(rows.slice(0, 2))}`);
+ // DB query result logging removed
}
if (realtimeRows) {
- console.info(`[getAllRuleChainFlows] realtimeRows count: ${realtimeRows.length}, sample: ${JSON.stringify(realtimeRows.slice(0, 2))}`);
+ // Realtime rows logging removed
for (const rt of realtimeRows) {
const index = rows.findIndex((r) => r.rule === rt.rule && r.chain === rt.chain);
if (index >= 0) {
@@ -474,10 +474,7 @@ export class RuleRepository extends BaseRepository {
}
const flowPath = this.buildRuleFlowPathWithConfig(rule, row.chain, proxyConfig);
- // Debug: log first few rows
- if (rows.indexOf(row) < 3) {
- console.info(`[getAllRuleChainFlows] Row ${rows.indexOf(row)}: rule=${rule}, chain=${row.chain}, flowPath=${JSON.stringify(flowPath)}`);
- }
+ // Row processing debug logging removed
if (flowPath.length < 2) continue;
for (let i = 0; i < flowPath.length; i++) {
diff --git a/apps/collector/src/modules/app/app.ts b/apps/collector/src/modules/app/app.ts
index 46dc68b..443171c 100644
--- a/apps/collector/src/modules/app/app.ts
+++ b/apps/collector/src/modules/app/app.ts
@@ -103,7 +103,8 @@ export async function createApp(options: AppOptions) {
} = options;
// Create Fastify instance
- const app = Fastify({ logger });
+ // Increase body limit to 5MB for agent config sync (large Clash/Surge configs)
+ const app = Fastify({ logger, bodyLimit: 5 * 1024 * 1024 });
// Register CORS
await app.register(cors, {
@@ -523,8 +524,6 @@ export async function createApp(options: AppOptions) {
}
}
- // Debug log for chain data
- console.info(`[Agent Report] Chain data: chains=${JSON.stringify(update.chains)}, rule=${update.rule}, domain=${update.domain}`);
realtimeStore.recordTraffic(
backendId,
@@ -613,12 +612,12 @@ export async function createApp(options: AppOptions) {
app.post('/api/agent/config', async (request, reply) => {
const body = request.body as AgentConfigPayload;
const backendId = parseBackendId(body?.backendId);
- console.info(`[Agent Config] Received config for backendId: ${backendId}, agentId: ${body?.agentId}`);
+ // Agent config received (log removed to reduce noise)
if (backendId === null) {
return reply.status(400).send({ error: 'Invalid backendId' });
}
if (!isAgentBackendAuthorized(backendId, request, reply)) {
- console.info(`[Agent Config] Backend not authorized: ${backendId}`);
+ // Backend not authorized (error returned to client)
return;
}
const agentId = parseAgentId(body.agentId);
@@ -626,7 +625,7 @@ export async function createApp(options: AppOptions) {
return reply.status(400).send({ error: 'Invalid agentId' });
}
if (!isAgentBindingAllowed(backendId, agentId, reply)) {
- console.info(`[Agent Config] Binding not allowed for agent: ${agentId}`);
+ // Agent binding not allowed (error returned to client)
return;
}
@@ -634,7 +633,7 @@ export async function createApp(options: AppOptions) {
return reply.status(400).send({ error: 'Missing config payload' });
}
- console.info(`[Agent Config] Storing config for backendId: ${backendId}, proxies count: ${Object.keys(body.config?.proxies || {}).length}`);
+ // Config stored successfully (log removed to reduce noise)
realtimeStore.setAgentConfig(backendId, body.config);
return { success: true, backendId, hash: body.config.hash };
@@ -644,12 +643,12 @@ export async function createApp(options: AppOptions) {
app.post('/api/agent/policy-state', async (request, reply) => {
const body = request.body as { backendId: number; agentId: string; policyState: { proxies: Record<string, unknown>; providers: Record<string, unknown>; timestamp: number } };
const backendId = parseBackendId(body?.backendId);
- console.info(`[Agent Policy State] Received policy state for backendId: ${backendId}, agentId: ${body?.agentId}`);
+ // Agent policy state received (log removed to reduce noise)
if (backendId === null) {
return reply.status(400).send({ error: 'Invalid backendId' });
}
if (!isAgentBackendAuthorized(backendId, request, reply)) {
- console.info(`[Agent Policy State] Backend not authorized: ${backendId}`);
+ // Backend not authorized (error returned to client)
return;
}
@@ -657,7 +656,7 @@ export async function createApp(options: AppOptions) {
return reply.status(400).send({ error: 'Missing policyState payload' });
}
- console.info(`[Agent Policy State] Storing policy state for backendId: ${backendId}, proxies count: ${Object.keys(body.policyState?.proxies || {}).length}`);
+ // Policy state stored successfully (log removed to reduce noise)
realtimeStore.setAgentPolicyState(backendId, body.policyState as import('../realtime/realtime.store.js').AgentPolicyState);
return { success: true, backendId, timestamp: body.policyState.timestamp };
@@ -666,7 +665,7 @@ export async function createApp(options: AppOptions) {
// Compatibility routes: Gateway APIs
app.get('/api/gateway/proxies', async (request, reply) => {
const backendId = getBackendIdFromQuery(request.query as Record<string, unknown>);
- console.info(`[Gateway API /proxies] backendId: ${backendId}`);
+ // Gateway API /proxies called (log removed to reduce noise)
if (backendId === null) {
return reply.status(404).send({ error: 'No backend specified or active' });
}
@@ -953,7 +952,7 @@ export async function createApp(options: AppOptions) {
.map(r => r.raw ? parseSurgeRule(r.raw) : null)
.filter((r): r is NonNullable<typeof r> => r !== null)
.map(r => ({ type: r.type, payload: r.payload, proxy: r.policy, size: 0 }));
- console.info(`[Gateway API /rules] Agent mode Surge rules count: ${parsedRules.length}, sample:`, parsedRules.slice(0, 3));
+ // Agent mode Surge rules logging removed
return { rules: parsedRules, _source: 'agent-cache' };
}
diff --git a/apps/collector/src/modules/stats/stats.controller.ts b/apps/collector/src/modules/stats/stats.controller.ts
index 05706b2..8bff1ef 100644
--- a/apps/collector/src/modules/stats/stats.controller.ts
+++ b/apps/collector/src/modules/stats/stats.controller.ts
@@ -391,7 +391,7 @@ const statsController: FastifyPluginAsync = async (fastify: FastifyInstance): Pr
}
const result = await service.getRuleStatsWithRouting(backendId, timeRange);
- console.info(`[Stats API /rules] backendId: ${backendId}, rules count: ${result.length}, sample:`, result.slice(0, 3));
+ // Stats API response logging removed
return result;
});
diff --git a/apps/collector/src/modules/stats/stats.service.ts b/apps/collector/src/modules/stats/stats.service.ts
index b39aa47..024f4b1 100644
--- a/apps/collector/src/modules/stats/stats.service.ts
+++ b/apps/collector/src/modules/stats/stats.service.ts
@@ -134,7 +134,7 @@ export class StatsService {
return `${name}=ch:${counts.clickhouse},sqlite:${counts.sqlite},ch_rate:${chRate.toFixed(1)}%`;
})
.join(' | ');
- console.info(`[Stats Route Metrics] ${parts} window_sec=${(elapsedMs / 1000).toFixed(1)}`);
+ // Stats route metrics logging removed
}
this.routeMetricsWindowStartedAt = now;
@@ -1136,7 +1136,7 @@ export class StatsService {
// Get proxy config for Agent mode to enrich short chains
const agentConfig = this.realtimeStore.getAgentConfig(backendId);
const proxyConfig = agentConfig?.proxies;
- console.info(`[StatsService.getRuleChainFlow] backendId: ${backendId}, rule: ${rule}, agentConfig exists: ${!!agentConfig}, proxyConfig keys: ${proxyConfig ? Object.keys(proxyConfig).length : 0}`);
+ // Rule chain flow request logging removed
return this.db.getRuleChainFlow(backendId, rule, timeRange.start, timeRange.end, realtimeRows, proxyConfig);
}
@@ -1178,7 +1178,7 @@ export class StatsService {
// Get proxy config for Agent mode to enrich short chains
const agentConfig = this.realtimeStore.getAgentConfig(backendId);
const proxyConfig = agentConfig?.proxies;
- console.info(`[StatsService.getAllRuleChainFlows] backendId: ${backendId}, agentConfig exists: ${!!agentConfig}, proxyConfig keys: ${proxyConfig ? Object.keys(proxyConfig).length : 0}`);
+ // All rule chain flows request logging removed
return this.db.getAllRuleChainFlows(backendId, timeRange.start, timeRange.end, realtimeRows, proxyConfig);
}
diff --git a/apps/collector/src/modules/websocket/websocket.server.ts b/apps/collector/src/modules/websocket/websocket.server.ts
index 3cbbd29..2442f09 100644
--- a/apps/collector/src/modules/websocket/websocket.server.ts
+++ b/apps/collector/src/modules/websocket/websocket.server.ts
@@ -156,7 +156,7 @@ export class StatsWebSocketServer {
});
this.wss.on('connection', async (ws: WebSocket, req: IncomingMessage) => {
- console.log(`[WebSocket] Connection attempt from ${req.socket.remoteAddress}`);
+ // Connection attempt logging removed to reduce noise
// Verify authentication
try {
@@ -179,14 +179,14 @@ export class StatsWebSocketServer {
// Check if auth is required and verify token
if (this.authService.isAuthRequired()) {
if (!token) {
- console.log(`[WebSocket] Rejected connection from ${req.socket.remoteAddress}: Missing token or cookie`);
+ // Missing token rejected (logging removed)
ws.close(4001, 'Authentication required');
return;
}
const verifyResult = await this.authService.verifyToken(token);
if (!verifyResult.valid) {
- console.log(`[WebSocket] Rejected connection from ${req.socket.remoteAddress}: Invalid token`);
+ // Invalid token rejected (logging removed)
ws.close(4003, 'Invalid token');
return;
}
@@ -197,8 +197,7 @@ export class StatsWebSocketServer {
return;
}
- console.log(`[WebSocket] connection authorized from ${req.socket.remoteAddress}`);
- console.log(`[WebSocket] Client connected, total: ${this.clients.size + 1}`);
+ // Client connected (logging removed to reduce noise in production)
const clientInfo: ClientInfo = {
ws,
@@ -238,7 +237,7 @@ export class StatsWebSocketServer {
if (clientInfo.backendId !== msg.backendId) {
clientInfo.backendId = msg.backendId;
changed = true;
- console.log(`[WebSocket] Client subscribed to backend: ${backend.name} (ID: ${msg.backendId})`);
+ // Client subscribed to backend (logging removed)
}
} else {
console.warn(`[WebSocket] Client tried to subscribe to non-existent backend: ${msg.backendId}`);
@@ -404,7 +403,7 @@ export class StatsWebSocketServer {
ws.on('close', () => {
this.clients.delete(ws);
- console.log(`[WebSocket] Client disconnected, remaining: ${this.clients.size}`);
+ // Client disconnected (logging removed to reduce noise)
});
ws.on('error', (err) => {
@@ -1075,7 +1074,7 @@ export class StatsWebSocketServer {
if (sentCount > 0) {
this.wsMetrics.broadcastSentClients += sentCount;
this.maybeLogWsMetrics();
- console.log(`[WebSocket] Broadcasted stats to ${sentCount} clients`);
+ // Broadcast log removed to reduce noise in production
}
}