Use console.error() instead of console.trace()
What's always been annoying me about console.trace()
is that the stack trace is always expanded when output to the console. This quickly obstructs the view if you perform many traces at a time.
What I found is that console.error()
actually logs stack trace in the same way, only it's initially collapsed (see screenshot). As a bonus you can optionally pass a message that would serve as a title for your trace.
Now I always prefer the former and have cleaner output!
P.S. Also true for FireBug!
Written by Dmitry Pashkevich
Related protips
4 Responses
@shell Great find, thanks! Looks like at the moment it's identical to log but has more letters :)
Life saver. Thank you! Now i just have a lot of errors in console:))
This was driving me crazy, and console.error makes it hard to see real errors if there are lots of trace logs. so after a lot of messing around I came up with this.
javascript
console.groupCollapsed('name for trace', 'additional data to show');
console.log('data to hide in the collapsed group');
console.trace(); // trace to hide in group
console.groupEnd();
That produces something like
Formatting was messed up, trying again
javascript
console.groupCollapsed('name for trace', 'additional data to show');
javascript
console.log('data to hide in the collapsed group');
javascript
console.trace(); // trace to hide in group
javascript
console.groupEnd();
```
That produces something like
Inline-style: