Grouped logging
Lets say that we have some console.log
in our code, some of them are related to contact form other are related to user actions. We can split those logs into 2 sections: contact-form
and user-actions
. When we open our website, console displays all of those messages at once but we only want to debug user actions so what do we do? – remove console.log in contact form section? nope, there’s better option – grouped logging.
At first lets write down all section names and create a var that will hold only those we want to debug:
1 | // Values: 'contact-form', user-actions' |
Looks good, this way we won’t have to look for the names of groups. Now we only have to create a function that will group logs, here’s a code for it:
1 | var log = function() { |
Here’s how to use it:
1 | // This won't be logged because contact-form isn't in debug array |
That’s all folks, thanks for reading!