web applications – How can I cleanly set up debug logging in my javascript frontend?


I basically want to be able to “turn on debug logging” like you can do with many applications that run in a shell. The naive way of implementing it would be to insert a statement like this in every one of my functions:

if (DEBUG) console.log('Executing <name of function>');

But having this in every function seems a bit annoying. Is there a more established or cleaner way of doing this?