Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import pino, { type DestinationStream, type Logger, type LoggerOptions } from "pino";
|
||||
|
||||
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
||||
|
||||
export type ToolctrlLogger = Pick<Logger, "debug" | "info" | "warn" | "error" | "child">;
|
||||
|
||||
const REDACT_PATHS = [
|
||||
"authorization",
|
||||
"headers.authorization",
|
||||
"req.headers.authorization",
|
||||
"request.headers.authorization",
|
||||
"cookie",
|
||||
"headers.cookie",
|
||||
"req.headers.cookie",
|
||||
"request.headers.cookie",
|
||||
"password",
|
||||
"*.password",
|
||||
"token",
|
||||
"*.token",
|
||||
"secret",
|
||||
"*.secret",
|
||||
"apiKey",
|
||||
"*.apiKey",
|
||||
"redisUrl",
|
||||
"*.redisUrl",
|
||||
"connectionString",
|
||||
"*.connectionString",
|
||||
] as const;
|
||||
|
||||
export interface CreateLoggerOptions extends Omit<LoggerOptions, "base" | "level" | "redact"> {
|
||||
level?: LogLevel;
|
||||
stream?: DestinationStream;
|
||||
}
|
||||
|
||||
export function resolveLogLevel(env: NodeJS.ProcessEnv = process.env): LogLevel {
|
||||
return (env.TOOLCTRL_LOG_LEVEL ?? env.LOG_LEVEL ?? "info") as LogLevel;
|
||||
}
|
||||
|
||||
export function createLogger(options: CreateLoggerOptions = {}): ToolctrlLogger {
|
||||
const { level = resolveLogLevel(), stream, ...pinoOptions } = options;
|
||||
|
||||
return pino(
|
||||
{
|
||||
...pinoOptions,
|
||||
base: undefined,
|
||||
level,
|
||||
redact: {
|
||||
paths: [...REDACT_PATHS],
|
||||
censor: "[Redacted]",
|
||||
},
|
||||
},
|
||||
stream,
|
||||
);
|
||||
}
|
||||
|
||||
export function createChildLogger(logger: ToolctrlLogger, bindings: Record<string, unknown>): ToolctrlLogger {
|
||||
return logger.child(bindings);
|
||||
}
|
||||
|
||||
export const defaultLogger = createLogger();
|
||||
Reference in new issue
Block a user