feat: reworking

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-04-23 15:01:09 +02:00
parent 93f28237d8
commit 5f0c46fa23
2 changed files with 24 additions and 18 deletions
@@ -85,17 +85,20 @@ export class WinstonLogger implements RootLoggerService {
let redactionPattern: RegExp | undefined = undefined;
return {
format: format(info => {
if (redactionPattern) {
for (const [key, value] of Object.entries(info)) {
if (typeof value === 'string') {
info[key] = value.replace(redactionPattern, '[REDACTED]');
}
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 info;
})(),
}
return obj;
};
return {
format: format(replace)(),
add(newRedactions) {
let added = 0;
for (const redactionToTrim of newRedactions) {
@@ -107,17 +107,20 @@ export class WinstonLogger implements RootLoggerService {
let redactionPattern: RegExp | undefined = undefined;
return {
format: format(info => {
if (redactionPattern) {
for (const [key, value] of Object.entries(info)) {
if (typeof value === 'string') {
info[key] = value.replace(redactionPattern, '[REDACTED]');
}
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 info;
})(),
}
return obj;
};
return {
format: format(replace)(),
add(newRedactions) {
let added = 0;
for (const redactionToTrim of newRedactions) {