File size: 1,154 Bytes
c4ae742 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // apps/api/src/log.ts
// Structured logger with API-key redaction. Per-request child loggers
// carry req_id; per-job/item children attach job_id / item_id.
import pino from "pino";
export interface LogContext {
reqId?: string;
jobId?: string;
itemId?: string;
}
const REDACT_PATHS = [
// outgoing fetch headers
'*.headers.authorization',
'*.headers.Authorization',
'*.headers["api-key"]',
// settings or options snapshot fields
"*.apiKey",
"*.api_key",
"*.judge.apiKey",
"*.rubricGeneration.apiKey",
// any nested options snapshot column
"options_snapshot.apiKey",
"options_snapshot.judge.apiKey",
"options_snapshot.rubricGeneration.apiKey",
];
export function createLogger(level: string) {
return pino({
level,
redact: {
paths: REDACT_PATHS,
censor: "[REDACTED]",
},
// pino-pretty in dev only; runtime uses JSON
transport:
process.env.NODE_ENV === "production"
? undefined
: {
target: "pino-pretty",
options: { colorize: true, translateTime: "HH:MM:ss.l" },
},
});
}
export type Logger = ReturnType<typeof createLogger>;
|