69 lines
1.3 KiB
TypeScript
69 lines
1.3 KiB
TypeScript
import pino from "pino";
|
|
|
|
const isProduction = process.env["NODE_ENV"] === "production";
|
|
|
|
// In production, suppress Playwright debug output that bypasses pino.
|
|
if (isProduction) {
|
|
delete process.env["DEBUG"];
|
|
}
|
|
|
|
const redactPaths: string[] = [
|
|
// Auth & credentials
|
|
"**.cookie",
|
|
"**.cookies",
|
|
"**.set-cookie",
|
|
"**.authorization",
|
|
"**.password",
|
|
"**.secret",
|
|
|
|
// Tokens
|
|
"**.token",
|
|
"**.xsec_token",
|
|
"**.access_token",
|
|
"**.refresh_token",
|
|
|
|
// API keys
|
|
"**.api_key",
|
|
"**.apikey",
|
|
|
|
// Sessions
|
|
"**.sessionid",
|
|
"**.session_id",
|
|
|
|
// Playwright StorageState structures
|
|
"**.cookies[*].value",
|
|
"**.origins[*].localStorage[*].value",
|
|
];
|
|
|
|
const errorSerializer = (err: Error): Record<string, unknown> => {
|
|
const serialized: Record<string, unknown> = {
|
|
type: err.constructor?.name ?? "Error",
|
|
message: err.message,
|
|
};
|
|
|
|
if (!isProduction && err.stack) {
|
|
serialized["stack"] = err.stack;
|
|
}
|
|
|
|
return serialized;
|
|
};
|
|
|
|
export const logger: pino.Logger = pino({
|
|
level: process.env["LOG_LEVEL"] ?? "info",
|
|
redact: {
|
|
paths: redactPaths,
|
|
censor: "[REDACTED]",
|
|
},
|
|
serializers: {
|
|
err: errorSerializer,
|
|
error: errorSerializer,
|
|
},
|
|
...(isProduction
|
|
? {}
|
|
: {
|
|
transport: {
|
|
target: "pino-pretty",
|
|
},
|
|
}),
|
|
});
|