Hey
When I am done with a larger project I would like to add the below line in Page Code or even in Site Code that would turn all console.log functions off. This would be a huge time saver and also when going back to a page I want to work with activate that on that page.
Turning it off
wixCore.console(false);
Turning it on
wixCore.console(true);
6 Likes
Hi Andreas,
You can achieve something similar today with creating your own log function you can turn on/off.
Example:
// public/logger.js file
let isLoggingEnabled = true;
export function log(message) {
if (isLoggingEnabled) {
console.log(message);
}
}
// some page code
import {log} from 'public/logger'
$w.onReady(function () {
log("hello")
});
Hi Tomer, like the solution.
I haven’t tested it, but I believe the issue with this way is we lose the stack trace that tells us what line it was logging from. Is there a way to get that back?
@chris-derrell That’s a good point!
In our developer console we do not show the full stack trace yet.
But - in the browser developer tools you will still see the full stack trace and see the origin of the call - instead of it being the top frame, it will probably be one frame below in the stack.