Finding out where that console.log output is coming from

While trying to solve a problem, we have all sometimes done a little console.log outputting to help us gain additional understanding. While it’s far from the most effect way of debugging, it’s more annoying when those statements appear in your production logs. That was my scenario today.

Thankfully, with a simple grep command I was able to identified all of my “debugging” statements and the lines they occurred on.

$ grep -nr console * | grep -v “node_modules/*” | grep -v “static/”

endpoints/browser_stats.js:35:        if(error) { console.log(error); }
endpoints/browser_stats.js:51:        if(error) { console.log(error); }
endpoints/browser_stats.js:67:        if(error) { console.log(error); }
endpoints/events.js:16:    console.log(eventsUrl);
endpoints/events.js:17:    console.log(hitsUrl);
endpoints/events.js:20:        if(error) { console.log(error); }
endpoints/events.js:27:            if(error) { console.log(error); }
passport.js:23:      console.log(“Auth”);

In this case, I filtered out any matches from node_modules and static javascript files. Keep in mind that in some cases it’s a node module causing the output.

A simple command to help keep your production logs clean and readable.