watch-console.ts

28 lines | 906 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 (text: any) {
                oldCons.log(text);
                fn('log', text);
            },
            info: function (text: any) {
                oldCons.info(text);
                fn('info', text);
            },
            warn: function (text: any) {
                oldCons.warn(text);
                fn('warn', text);
            },
            error: function (text: any) {
                oldCons.error(text);
                fn('error', text);
            }
        };
    }(window.console));

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