fix: bind Logger.sanitize
This commit is contained in:
@@ -186,7 +186,7 @@ class Logger {
|
|||||||
* @param input The data to sanitize
|
* @param input The data to sanitize
|
||||||
* @returns The sanitized data
|
* @returns The sanitized data
|
||||||
*/
|
*/
|
||||||
private sanitize<T>(input: T): T {
|
private sanitize = <T>(input: T, level = 0): T => {
|
||||||
// Short circuit if we're not in production to enable easier debugging
|
// Short circuit if we're not in production to enable easier debugging
|
||||||
if (!env.isProduction) {
|
if (!env.isProduction) {
|
||||||
return input;
|
return input;
|
||||||
@@ -200,6 +200,10 @@ class Logger {
|
|||||||
"content",
|
"content",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (level > 3) {
|
||||||
|
return "[…]" as any as T;
|
||||||
|
}
|
||||||
|
|
||||||
if (isString(input)) {
|
if (isString(input)) {
|
||||||
if (sensitiveFields.some((field) => input.includes(field))) {
|
if (sensitiveFields.some((field) => input.includes(field))) {
|
||||||
return "[Filtered]" as any as T;
|
return "[Filtered]" as any as T;
|
||||||
@@ -215,20 +219,22 @@ class Logger {
|
|||||||
|
|
||||||
for (const key of Object.keys(output)) {
|
for (const key of Object.keys(output)) {
|
||||||
if (isObject(output[key])) {
|
if (isObject(output[key])) {
|
||||||
output[key] = this.sanitize(output[key]);
|
output[key] = this.sanitize(output[key], level + 1);
|
||||||
} else if (isArray(output[key])) {
|
} else if (isArray(output[key])) {
|
||||||
output[key] = output[key].map(this.sanitize);
|
output[key] = output[key].map((value: unknown) =>
|
||||||
|
this.sanitize(value, level + 1)
|
||||||
|
);
|
||||||
} else if (sensitiveFields.includes(key)) {
|
} else if (sensitiveFields.includes(key)) {
|
||||||
output[key] = "[Filtered]";
|
output[key] = "[Filtered]";
|
||||||
} else {
|
} else {
|
||||||
output[key] = this.sanitize(output[key]);
|
output[key] = this.sanitize(output[key], level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new Logger();
|
export default new Logger();
|
||||||
|
|||||||
Reference in New Issue
Block a user