Sharepoint - SPFx: disabling console traces (by SPFx libraries)

No, that is not possible at this time. Interesting idea though. Can you as it a feature request to the github issue list?


noop it for now by adding this before any of the SPFx stuff gets loaded.

console.log(// extra wrapper so below code is taken out on minification
(function() {
    var noop = function noop() {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    window.log = {};

    methods.forEach(function (method) {
        if (Function.prototype.bind && (typeof console === 'object' || typeof console === 'function') && typeof console.log === 'object') {
            console[method] = this.call(console[method], console);
        }
        if (console[method]) {
            window.log[method] = console[method].bind(console);
            console[method] = noop;
        }
    }, Function.prototype.bind);
  return "console is overriden"
})());

Then put it back the way it was or just use log instead. As an aside, it really shouldn't have shipped this way.

Tags:

Spfx