ge35zg
Last Updated: October 01, 2018
·
4.337K
· dpashkevich

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.

console.error() vs console.trace()

Now I always prefer the former and have cleaner output!

P.S. Also true for FireBug!

5 Responses
Add your response

4316

Also console.debug()

over 1 year ago ·
5287

@shell Great find, thanks! Looks like at the moment it's identical to log but has more letters :)

over 1 year ago ·
29001

Life saver. Thank you! Now i just have a lot of errors in console:))

over 1 year ago ·
30856

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

https://ucf83efca8a493fc687933df92eb.previews.dropboxusercontent.com/p/thumb/AAPE3yg6i7p9qwp1SxjSkX369x6o87CGxbgsNN4O674lxb0y1qTXsZwFTBcgPFIiToN8RawPNG-zMB5HkcHJAUgEPhBVtrsvq9aT3Xu5B2qpPlZhvG8VNUZ-XQT-u97NmvffemLpxiZeQuGLfeUEc6wRpdISY5dglk_yChnM1mDCJREi0Q5y3LR9qF1PulsEdegdJOvhdBCZrF7yYNiPyAeCP8ycEGZARlZn6iJ_1A560sFeaeg_PeWMG-qK8VPWh1w/p.png?size=800x600&size_mode=3

about 1 month ago ·
30857

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 groupjavascript
console.groupEnd();
```
That produces something like
Inline-style:
alt text

about 1 month ago ·