PatrickJS / angular-hmr

:fire: Angular Hot Module Replacement for Hot Module Reloading
https://patrickjs.com
Apache License 2.0
506 stars 45 forks source link

Remove logging functionality #51

Open lansana opened 7 years ago

lansana commented 7 years ago

Please view my question on StackOverflow for context/code example: https://stackoverflow.com/questions/44435999/angular2-hmr-hot-module-replacement-remove-the-logs

I just want to be able to opt out of the logging. I don't need a log for every single module that was reloaded, maybe just a single log saying successfully reloaded. Is there a way to override this functionality?

More context can be found in the same issue in webpack: https://github.com/webpack/webpack-dev-server/issues/109

Thanks!

PatrickJS commented 7 years ago

here's a temp workaround that you can add to your index file

<script>
// This is a workaround used alongside the webpack-dev-server hot-module-reload feature
//  - it's quite chatty on the console, and there's no currently no configuration option
//    to silence it. Only used in development.
// Prevent messages starting with [HMR] or [WDS] from being printed to the console
(function(global) {
    var console_log = global.console.log
    global.console.log = function() {
        if (!(
            arguments.length == 1 &&
            typeof arguments[0] === 'string' &&
            arguments[0].match(/^\[(HMR|WDS)\]/)
        )) {
            console_log.apply(global.console,arguments)
        }
    }
})(window)
</script>
nicolae-olariu commented 6 years ago

Thank you @gdi2290 ! It works wonderful for console.log. [WDS] messages are rendered through the console.info and I've updated a bit your snippet for anyone needing this. Let me know if it can be improved. Thanks a lot!

<script>
// This is a workaround used alongside the webpack-dev-server hot-module-reload feature
//  - it's quite chatty on the console, and there's no currently no configuration option
//    to silence it. Only used in development.
// Prevent messages starting with [HMR] or [WDS] from being printed to the console
(function(global) {
    var nativeConsoleLog = global.console.log,
    nativeConsoleInfo = global.console.info,
    condition = function(args) {
        return !(args.length == 1 &&
                    typeof args[0] === 'string' &&
                    args[0].match(/^\[(HMR|WDS)\]/));
    };

    global.console.log = function() {
        condition(arguments) && nativeConsoleLog.apply(global.console, arguments);
    }

    global.console.info = function () {
        condition(arguments) && nativeConsoleInfo.apply(global.console, arguments);
    }
})(window)
</script>