feat: 运行时日志系统,Pino + pino-pretty + pino-roll,console/file 双输出,敏感信息 redaction
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import type { ApiErrorResponse, CheckFailure, CheckResult, HealthResponse, RuntimeMode } from "../shared/api";
|
||||
import type { StoredCheckResult } from "./checker/types";
|
||||
import type { Logger } from "./logger";
|
||||
|
||||
import { checkerRegistry } from "./checker/runner";
|
||||
import { createNoopLogger } from "./logger";
|
||||
|
||||
export function createApiError(error: string, status: number): ApiErrorResponse {
|
||||
return { error, status };
|
||||
@@ -47,13 +49,14 @@ export function jsonResponse(
|
||||
});
|
||||
}
|
||||
|
||||
export function mapCheckResult(row: StoredCheckResult, type: string): CheckResult {
|
||||
export function mapCheckResult(row: StoredCheckResult, type: string, logger?: Logger): CheckResult {
|
||||
const log = logger ?? createNoopLogger();
|
||||
let failure: CheckFailure | null = null;
|
||||
if (row.failure) {
|
||||
try {
|
||||
failure = JSON.parse(row.failure) as CheckFailure;
|
||||
} catch {
|
||||
console.warn(`无法解析 failure 数据: target_id=${row.target_id}, timestamp=${row.timestamp}`);
|
||||
log.warn({ targetId: row.target_id, timestamp: row.timestamp }, "无法解析 failure 数据");
|
||||
failure = null;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +66,7 @@ export function mapCheckResult(row: StoredCheckResult, type: string): CheckResul
|
||||
try {
|
||||
observation = JSON.parse(row.observation) as Record<string, unknown>;
|
||||
} catch {
|
||||
console.warn(`无法解析 observation 数据: target_id=${row.target_id}, timestamp=${row.timestamp}`);
|
||||
log.warn({ targetId: row.target_id, timestamp: row.timestamp }, "无法解析 observation 数据");
|
||||
observation = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user