r/javascript • • Dec 16 '18

Coming from Python to JS NSFW

const print = console.log

I found my safe space.

607 Upvotes

156 comments sorted by

View all comments

94

u/mishugashu Dec 16 '18

If I came across that shit at work, I'd git blame in a heartbeat and tell you to never do that again.

But if you're doing it in personal projects, more power to you, I guess. Nothing really wrong with it code-wise.

0

u/[deleted] Dec 17 '18

[deleted]

5

u/Bonsoir_Elliott Dec 17 '18

Genuine question: why is it bad to have ‘console.log’ in the code? Is it bad to generate logs in a Node app?

5

u/FrancisStokes Dec 17 '18

Console logs do not have a level associated with them, so you have no way to run your app with only error logs, or with debugging information. That makes it easy to not only write bad logs, but to get to a situation where you can't remove a bunch of related but distributed logs without some effort. Basically, logging without levels and organisation leads to bad code hygiene.

6

u/13steinj Dec 17 '18

Aren't the 4 levels info, error, warn, (output to stderr), and log (output to stdout)?

1

u/Haramboid Dec 17 '18

Yes but that’s not very versatile. A good logger usually has multiple channels, separate from levels so you can categorize logs on the process you’re actually trying to debug.

4

u/mrbojingle Dec 17 '18

like console.group?