JimTheDev JimTheDev - 2 months ago 9
Node.js Question

When using gulp. Is there any way to suppress the 'Started' and 'Finished' log entries for certain tasks

When using gulp. Is there any way to suppress the 'Started' and 'Finished' log entries for certain tasks? I want to use the dependency tree, but I have a few tasks in the tree that I don't want logging for because they are intermediary steps that have their own logging facilities.

Answer

[UPDATE]

As of July 2014, a --silent option has been added to gulp (https://github.com/gulpjs/gulp/commit/3a62b2b3dbefdf91c06e523245ea3c8f8342fa2c#diff-6515adedce347f8386e21d15eb775605).

This is demonstrated in @slamborne answer below, and you should favor using it instead of the below solution if it matches your use case.

[/UPDATE]

Here is a way of doing it (inside your gulpfile):

var cl = console.log;
console.log = function () {
    var args = Array.prototype.slice.call(arguments);
    if (args.length) {
        if (/^\[.*gulp.*\]$/.test(args[0])){
            return;
        }
    }
    return cl.apply(console, args);
};

... and that will ignore EVERY message sent using gutil.log.

The trick here obviously is to inspect messages sent to console.log for a first argument that looks like "[gulp]" (see gulp.util.log source code) and eventually ignore it entirely.

Now, this really is dirty - you really shouldn't do that without parental supervision, and you have been warned :-)

Comments