watch-console.ts

28 lines | 943 B Blame History Raw Download
import { NotificationBubbles } from "../../codeeditor-app/elements/notification-bubbles/notification-bubbles";

export function watchConsole(fn: (type: 'log' | 'info' | 'warn' | 'error', ...value: any[]) => void) {
    // define a new console
    var console: any = (function (oldCons) {
        return {
            log: function (...data: any[]) {
                oldCons.log(...data);
                fn('log', data);
            },
            info: function (...data: any[]) {
                oldCons.info(...data);
                fn('info', data);
            },
            warn: function (...data: any[]) {
                oldCons.warn(...data);
                fn('warn', data);
            },
            error: function (...data: any[]) {
                oldCons.error(...data);
                fn('error', data);
            }
        };
    }(window.console));

    //Then redefine the old console
    window.console = console;
}