Merge pull request #24478 from backstage/blam/scaffolder-logger-fox
scaffolder: Redactions and keeping the log format
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user