diff --git a/README.md b/README.md index bdd8523..0f9e7db 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,15 @@ Default: `true` Option to prevent the livereload if the executed tasks encountered an error. If set to `false`, the livereload will only be triggered if all tasks completed successfully. +#### options.silent +Type: `Boolean` +Default: `false` +Aliases: `silently` + +Option to mute log messages. Ignored when running grunt in verbose mode. + +This is *only a task level option* and cannot be configured per target. + ### Examples ```js diff --git a/tasks/watch.js b/tasks/watch.js index 36eee85..2e01084 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -18,9 +18,16 @@ module.exports = function(grunt) { var taskrun = require('./lib/taskrunner')(grunt); + // Default or verbose logger + var logger = function() { + var options = taskrun.options; + var silent = (typeof options.silent === 'undefined') ? options.silently : options.silent; + return silent ? grunt.verbose : grunt.log; + }; + // Default date format logged var dateFormat = function(time) { - grunt.log.writeln(String( + logger().writeln(String( 'Completed in ' + time.toFixed(3) + 's at ' + @@ -32,7 +39,7 @@ module.exports = function(grunt) { taskrun.on('start', function() { Object.keys(changedFiles).forEach(function(filepath) { // Log which file has changed, and how. - grunt.log.ok('File "' + filepath + '" ' + changedFiles[filepath] + '.'); + logger().ok('File "' + filepath + '" ' + changedFiles[filepath] + '.'); }); // Reset changedFiles changedFiles = Object.create(null); @@ -77,7 +84,7 @@ module.exports = function(grunt) { dateFormat = df; } - if (taskrun.running === false) { grunt.log.writeln(waiting); } + if (taskrun.running === false) { logger().writeln(waiting); } // Initialize taskrun var targets = taskrun.init(name, {target: target});