I have a load of console.logs in my code, but I only need to see them/ turn them on if I need to see them on a site, so I want a way to be able to enable/ disbale them from in browser console by setting up a couple of snippets, such as: adysis.debug(‘enable’) , adysis.debug(‘disable’) but how can i get these to them trigger the console.logs in the code, I got no clue at all at the moment on how to do it?
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
It sounds like you want to control the visibility of
console.log
statements in your code using commands likeadysis.debug('enable')
andadysis.debug('disable')
that you can run from the browser console. To achieve this, you can create a custom debugging utility that wraps around the console.log function and toggles its behavior based on your commands.To disable ALL the console’s methods use
Proxy
.Use
console.disabled = true/false
to disable/enable console.If you want it disabled initially: