Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove logging functionality #51

Open
lansana opened this issue Jun 8, 2017 · 2 comments
Open

Remove logging functionality #51

lansana opened this issue Jun 8, 2017 · 2 comments

Comments

@lansana
Copy link

lansana commented Jun 8, 2017

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: webpack/webpack-dev-server#109

Thanks!

@PatrickJS
Copy link
Owner

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
Copy link

nicolae-olariu commented Aug 28, 2018

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants