Merge pull request #24478 from backstage/blam/scaffolder-logger-fox

scaffolder: Redactions and keeping the log format
This commit is contained in:
Ben Lambert
2024-04-23 15:30:31 +02:00
committed by GitHub
7 changed files with 86 additions and 28 deletions
@@ -85,16 +85,20 @@ export class WinstonLogger implements RootLoggerService {
let redactionPattern: RegExp | undefined = undefined;
const replace = (obj: TransformableInfo) => {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === 'object') {
obj[key] = replace(obj[key] as TransformableInfo);
} else if (typeof obj[key] === 'string') {
obj[key] = obj[key]?.replace(redactionPattern, '[REDACTED]');
}
}
}
return obj;
};
return {
format: format(info => {
if (redactionPattern && typeof info.message === 'string') {
info.message = info.message.replace(redactionPattern, '[REDACTED]');
}
if (redactionPattern && typeof info.stack === 'string') {
info.stack = info.stack.replace(redactionPattern, '[REDACTED]');
}
return info;
})(),
format: format(replace)(),
add(newRedactions) {
let added = 0;
for (const redactionToTrim of newRedactions) {