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

Allow muting log messages #467

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silent i think is more standard-ish

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came to same conclusion. See second commit. I provided an alias though for better consistency, in case silently is used elsewhere (e.g. when using grunt-contrib-connect). If you consider this feature creep lets remove the alias though.


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
Expand Down
13 changes: 10 additions & 3 deletions tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand All @@ -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);
Expand Down Expand Up @@ -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});
Expand Down