Last active
November 8, 2022 08:19
-
-
Save loopmode/b84e1d26fe40fbc3f21615d82b085804 to your computer and use it in GitHub Desktop.
Better console.trace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using console.trace in several places when debugging can be quite the PITA because it prints the entire | |
// stack directly to the output and makes it difficult to find and read other log messages | |
// | |
// this variant will print a neatly collapsed object with a "stack" property that you can manually expand when needed | |
console.log('>>', { trace: new Error().stack?.slice(12).split('\n') }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// attention!! redux dev tools will override console.trace themselves :) | |
console.trace = (...args) => { | |
console.log.apply(console, [ | |
...Array.from(args), | |
{ | |
trace: new Error().stack?.slice(12).split('\n'), | |
}, | |
]); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// attention!! redux dev tools will override console.trace themselves :) | |
console.trace = (...args: any[]) => { | |
console.log.apply(console, [ | |
...Array.from(args), | |
{ | |
trace: new Error().stack?.slice(12).split('\n'), | |
}, | |
] as any); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment