Skip to content

Instantly share code, notes, and snippets.

@loopmode
Last active November 8, 2022 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loopmode/b84e1d26fe40fbc3f21615d82b085804 to your computer and use it in GitHub Desktop.
Save loopmode/b84e1d26fe40fbc3f21615d82b085804 to your computer and use it in GitHub Desktop.
Better console.trace
// 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') });
// 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'),
},
]);
};
// 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