DEV Community

Discussion on: why you should not use console.log( ) for debugging ?

Collapse
 
lewiskori profile image
Lewis kori

Why not just use the debugger available in most IDE's and text editors?

They offer a ton of benefits such as breakpoints etc

Also in case you are using vscode, the turbo console log extension helps in managing the log statements and you can easily remove all the log statements with one command.

Collapse
 
danyson profile image
Danyson

Yes, that looks handy. When you are a developer, there might be couple of situations where you work with terminal based editors or IDEs without plug-ins for debugging.

Collapse
 
lewiskori profile image
Lewis kori

absolutely. Thanks for the write up.
excellent work.

Collapse
 
ibibgor profile image
Oscar

Besides breakpoints, a lot of tools offer Logpoints or Tracepoints. They do not break execution but only output the contents of a variable.

Collapse
 
vit100 profile image
Vitaliy Markitanov • Edited

'''Why not just use the debugger available in most IDE's and text editors?'''

Because 'debug' can be used not only during debugging in IDE, but on servers, where you don't have IDE.

Collapse
 
lewiskori profile image
Lewis kori

Well that's true. I haven't encountered a scenario where I print variables in production servers. But I do see your point.

There's a comment here on pino-logger with sentry. Granted, sentry isn't a one size fits all, but I would use this in a server for logging.

an even better option is you use pino-logger, it has methods like logger.error, logger.info etc and you can send those logs to be collected somewhere like a file or even a third party service like sentry. I dont recommend using the debug module like this when loggers exist

Collapse
 
dominikbraun profile image
DB

Just let people debug their programs the way they like it. It is a misconception that IDE debuggers are the best debugging tool - the best debugging tool is the one you know best. If you feel comfortable with console.log, just use that.

Collapse
 
samrocksc profile image
Sam Clark

I think one of the biggest arguments to make here is that almost all modern consumption of logging is done in a cloud interface which is expecting a formatted object. By utilizing console.log, most time people aren't stringifying the data, and just using the strings.

It creates clutter and future technical debt when you've ran up 2000 dollars in logging fees on a lambda service.

Not a critique, just food for thought.

Collapse
 
roelroel profile image
Roel de Brouwer

I never get them to work properly. They always randomly stop working.

Collapse
 
lewiskori profile image
Lewis kori

The debugger or turbo console log?

Collapse
 
robbeclaessens profile image
Robbe Claessens

The problem I find with debugging is sometimes the breakpoints dont work with async functions. Debugger statement helps, but not that handy.