MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / redactSensitive

Function redactSensitive

packages/logger/index.ts:36–69  ·  view source on GitHub ↗
(value: unknown, depth = 0)

Source from the content-addressed store, hash-verified

34const MAX_REDACT_DEPTH = 5;
35
36function redactSensitive(value: unknown, depth = 0): unknown {
37 if (value instanceof Error) {
38 return {
39 ...value,
40 message: value.message,
41 stack: value.stack,
42 name: value.name,
43 };
44 }
45 if (
46 depth >= MAX_REDACT_DEPTH ||
47 value === null ||
48 typeof value !== 'object'
49 ) {
50 return value;
51 }
52 if (value instanceof Date) {
53 return value;
54 }
55 if (Array.isArray(value)) {
56 return value.map((v) => redactSensitive(v, depth + 1));
57 }
58
59 const result: Record<string, unknown> = {};
60 for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
61 const lowered = key.toLowerCase();
62 if (SENSITIVE_KEY_PATTERNS.some((k) => lowered.includes(k))) {
63 result[key] = '[REDACTED]';
64 } else {
65 result[key] = redactSensitive(val, depth + 1);
66 }
67 }
68 return result;
69}
70
71export function createLogger({ name }: { name: string }): ILogger {
72 const service = [process.env.LOG_PREFIX, name, process.env.NODE_ENV ?? 'dev']

Callers 1

createLoggerFunction · 0.85

Calls 2

mapMethod · 0.45
someMethod · 0.45

Tested by

no test coverage detected