36 lines
745 B
TypeScript
36 lines
745 B
TypeScript
import pino, { type DestinationStream, type Logger } from "pino";
|
|
|
|
const redactedPaths = [
|
|
"apiKey",
|
|
"authorization",
|
|
"password",
|
|
"token",
|
|
"*.apiKey",
|
|
"*.authorization",
|
|
"*.password",
|
|
"*.token",
|
|
"headers.authorization",
|
|
"req.headers.authorization",
|
|
];
|
|
|
|
export function createLogger(
|
|
service: string,
|
|
options: { destination?: DestinationStream } = {},
|
|
): Logger {
|
|
return pino(
|
|
{
|
|
level: process.env.LOG_LEVEL?.trim() || "info",
|
|
base: {
|
|
service,
|
|
environment: process.env.NODE_ENV ?? "development",
|
|
version: process.env.APP_VERSION ?? "development",
|
|
},
|
|
redact: {
|
|
paths: redactedPaths,
|
|
censor: "[Redacted]",
|
|
},
|
|
},
|
|
options.destination,
|
|
);
|
|
}
|