Skip to content

Remove logging functionality #51

Open

Description

@lansana

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!

Activity

  1. PatrickJS commented on Jul 17, 2017

    @PatrickJS
    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>
  2. nicolae-olariu commented on Aug 28, 2018

    @nicolae-olariu

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions