Skip to content

Commit

Permalink
Fix #74
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Dec 15, 2020
1 parent 2e0d103 commit d8b0525
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/LoggerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,20 @@ export class LoggerHelper {

public static cloneObjectRecursively<T>(
obj: T,
maskValuesFn: (key: number | string, value: unknown) => unknown,
maskValuesFn?: (key: number | string, value: unknown) => unknown,
done: unknown[] = [],
clonedObject: T = Object.create(Object.getPrototypeOf(obj)) as T
): T {
done.push(obj);
Object.keys(obj).forEach((currentKey: string | number) => {
Object.getOwnPropertyNames(obj).forEach((currentKey: string | number) => {
if (!done.includes(obj[currentKey])) {
if (obj[currentKey] == null) {
clonedObject[currentKey] = obj[currentKey];
} else if (typeof obj[currentKey] !== "object") {
clonedObject[currentKey] = maskValuesFn(currentKey, obj[currentKey]);
clonedObject[currentKey] =
maskValuesFn != null
? maskValuesFn(currentKey, obj[currentKey])
: obj[currentKey];
} else {
clonedObject[currentKey] = LoggerHelper.cloneObjectRecursively(
obj[currentKey],
Expand Down
4 changes: 3 additions & 1 deletion src/LoggerWithoutCallSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ export class LoggerWithoutCallSite {
relevantCallSites.length = stackLimit;
}

const errorObject: IErrorObject = JSON.parse(JSON.stringify(error));
const errorObject: IErrorObject = (LoggerHelper.cloneObjectRecursively(
error
) as unknown) as IErrorObject;
errorObject.nativeError = error;
errorObject.details = { ...error };
errorObject.name = errorObject.name ?? "Error";
Expand Down

0 comments on commit d8b0525

Please sign in to comment.