How to use the log function from gulp-util

Find comprehensive JavaScript gulp-util.log code examples handpicked from public code repositorys.

gulp-util.log is a function in the Gulp build system that logs a message to the console with optional metadata and colorization.

13
14
15
16
17
18
19
20
21
var tsFiles = [].concat(config.tsFiles, tsUnitFiles);

/* Watch changed typescripts file and compile it */
gulp.task('watch-ts', function () {
    return gulp.watch(tsFiles, function (file) {
        util.log('Compiling ' + file.path + '...');
        return compileTs(file.path, true);
    });
});
fork icon149
star icon525
watch icon44

+ 3 other calls in file

69
70
71
72
73
74
75
76
77
          }
        }))
        .pipe(reduceAttrs())
        .pipe(gulp.dest(path.resolve(__dirname, '../dist/sprite/')))
        .on('error', (err) => {
          gutil.log(gutil.colors.red(err.message));
        })
  );
});
fork icon123
star icon997
watch icon31

+ 7 other calls in file

How does gulp-util.log work?

The gulp-util.log function in the Gulp build system is used to log messages to the console with optional metadata and colorization. When called, gulp-util.log takes one or more arguments that represent the message to be logged and any metadata associated with the message. By default, gulp-util.log logs messages with colorized output that can help distinguish different types of messages. For example, error messages are typically displayed in red, while success messages are displayed in green. The colorization can be disabled using the colors option. In addition to the message text, gulp-util.log can also log metadata such as a timestamp or a source file name. This can be useful for tracking the progress of a build process or for debugging issues. It's worth noting that gulp-util.log has been deprecated since Gulp 4.0 and is no longer recommended for use. Instead, the gulplog library should be used for logging in Gulp 4.0 and later versions. In summary, gulp-util.log is a function in the Gulp build system that logs messages to the console with optional metadata and colorization, and has been deprecated in favor of the gulplog library in Gulp 4.0 and later versions.

18
19
20
21
22
23
24
25
26
27
        .pipe(babel({
            presets: ['env']
        }))
        .pipe(uglify())
        .on('error', err=> {
             gutil.log(gutil.colors.red('[Error]'), err.toString()); 
        })
        .pipe(gulp.dest('dist'))
});
```
fork icon80
star icon708
watch icon83

+ 7 other calls in file

71
72
73
74
75
76
77
78
79
80
// gulp tag -> Tag this release
gulp.task('tag', gulp.series('changes', function() {
  const version = require('./package.json').version;
  const tag     = 'v' + version;

  gutil.log('Tagging this release', tag);
  return gulp.src('.changes')
    .pipe( exec('git add package.json CHANGELOG.md') )
    .pipe( exec('git commit --allow-empty -m "Version ' + version + '"') )
    .pipe( exec('git tag ' + tag + ' --file .changes') )
fork icon112
star icon520
watch icon14

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const gulp = require("gulp");
const gutil = require("gulp-util");

// Define a Gulp task
gulp.task("my-task", function () {
  // Log a message to the console
  gutil.log("Starting my-task...");

  // Do some work...

  // Log a success message to the console
  gutil.log(gutil.colors.green("Finished my-task!"));
});

In this example, we define a Gulp task called my-task that logs a message to the console using gulp-util.log. The message is colorized in the default green color to indicate success. We then do some work inside the task, and log another success message to the console when the task completes.

34
35
36
37
38
39
40
41
42
43
      gutil.log(`> in file '${gutil.colors.cyan(path.dirname(file.relative) + path.sep + path.basename(file.path))}', flattened path '${gutil.colors.cyan(expr.arguments[0].value)}' into '${gutil.colors.cyan(result)}'`);
    }
    result = result.replace(/[.](ts|js)/g, '')
    expr.arguments[0] = arg.raw.charAt(0) + result + arg.raw.charAt(0);
  } else {
    gutil.log(`> Non Literal argument for 'require' in '${gutil.colors.cyan(path.dirname(file.relative) + path.sep + path.basename(file.path))}' location: ${arg.loc.start.line}:${arg.loc.start.column}`)
  }
} else {
  if (logAmount && logAmount > 2) {
    gutil.log('> failed test: expr.arguments.length && expr.arguments[0].value[0] == \'.\' : ' + expr.arguments[0].value);
fork icon41
star icon109
watch icon20

+ 14 other calls in file

52
53
54
55
56
57
58
59
60
61
  this.emit('error', new PluginError('create-example',
        'Streams not supported!'));
} else if (file.isBuffer()) {
  const stream = this;
  const exampleFile = ExampleFile.fromPath(file.path);
  gutil.log('Creating example ' + file.relative);
  const args = {
    config: config,
    title: exampleFile.title(),
    fileName: exampleFile.url()
fork icon530
star icon3
watch icon11

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
if (file.isStream()) {
  this.emit('error', new gutil.PluginError('cmd2commonjs', 'Streaming not supported'));
}

try {
  gutil.log(file.path);
  const content = ranma.cjsify(file.contents.toString('utf8'));
  file.contents = new Buffer(content);
} catch (err) {
  this.emit('error', new gutil.PluginError('cmd2commonjs', err.toString()));
fork icon26
star icon140
watch icon7

+ 7 other calls in file

50
51
52
53
54
55
56
57
58
59
if (isProd()) {
  return build('autotrack.js').then(({code, map}) => {
    fs.outputFileSync('autotrack.js', code, 'utf-8');
    fs.outputFileSync('autotrack.js.map', map, 'utf-8');
    const size = (gzipSize.sync(code) / 1000).toFixed(1);
    gutil.log(
        `Built autotrack.js ${gutil.colors.gray(`(${size} Kb gzipped)`)}`);
  }).catch((err) => {
    logBuildErrors(err);
    throw new Error('failed to build autotrack.js');
fork icon614
star icon0
watch icon194

+ 7 other calls in file

4
5
6
7
8
9
10
11
12
13
var combiner = require('stream-combiner2')

var handleError = function (err) {
    var colors = gutil.colors;
    console.log('\n')
    gutil.log(colors.red('Error!'))
    gutil.log('fileName: ' + colors.red(err.fileName))
    gutil.log('lineNumber: ' + colors.red(err.lineNumber))
    gutil.log('message: ' + err.message)
    gutil.log('plugin: ' + colors.yellow(err.plugin))
fork icon372
star icon0
watch icon355

+ 27 other calls in file

112
113
114
115
116
117
118
119
120
// use gulp version -t 1.2.3
gulp.task( 'version', function() {
  var args = minimist( process.argv.slice(3) );
  var version = args.t;
  if ( !version || !/^\d\.\d+\.\d+/.test( version ) ) {
    gutil.log( 'invalid version: ' + chalk.red( version ) );
    return;
  }
  gutil.log( 'ticking version to ' + chalk.green( version ) );
fork icon329
star icon0
watch icon96

+ 7 other calls in file

25
26
27
28
29
30
31
32
33
34
  file.path = file.path.replace(srcEx, libFragment);
  callback(null, file);
}))
.pipe(newer(dest))
.pipe(through.obj((file, enc, callback) => {
  gutil.log('Compiling', '"' + chalk.cyan(file._path) + '"...');
  callback(null, file);
}))
.pipe(babel())
.pipe(gulp.dest(dest));
fork icon47
star icon0
watch icon14

+ 3 other calls in file

89
90
91
92
93
94
95
96
97
98
99
});


gulp.task('watch:stylesheets', function () {
  gulp.src(src.styles.app)
    .pipe(sass().on('error', function (err) {
      gutil.log(chalk.white.bgRed(' Error '));
      gutil.log(chalk.red(err.message));
    }))
    .pipe(rename(out.styles.fileMinified))
    .pipe(chmod(0o755))
fork icon31
star icon38
watch icon0

+ 19 other calls in file

16
17
18
19
20
21
22
23
24
25
const presets = ['babel-preset-es2015', 'babel-preset-es2016', 'babel-preset-es2017', 'babel-preset-stage-2'].map(require.resolve);

gulp.task('prod', () => {
  webpack(builds.production, (err, stats) => {
    if (err) throw new gutil.PluginError('webpack:build', err);
    gutil.log('[webpack:build]', stats.toString({
      colors: true,
    }));
  });
});
fork icon5
star icon7
watch icon7

+ 7 other calls in file

108
109
110
111
112
113
114
115
116
117
  } else {
    throw err
  }
})
nsis.on('close', function () {
  gulpUtil.log('Installer ready!', releasesDir.path(finalPackageName))
  deferred.resolve()
})

return deferred.promise
fork icon3
star icon26
watch icon0

89
90
91
92
93
94
95
96
97
98
let MASIdentity = utils.getMASSigningId(manifest)
let MASInstallerIdentity = utils.getMASInstallerSigningId(manifest)

if (utils.releaseForMAS()) {
  if (!MASIdentity || !MASInstallerIdentity) {
    gulpUtil.log('--mas-sign and --mas-installer-sign are required to release for Mac App Store!')
    process.exit(0)
  }
  let cmds = [
    'codesign --deep -f -s "' + MASIdentity + '" --entitlements resources/osx/child.plist -v "' + finalAppDir.path() + '/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libffmpeg.dylib"',
fork icon3
star icon26
watch icon0

+ 4 other calls in file

92
93
94
95
96
97
98
99
100
  if (error || stderr) {
    console.log('ERROR while building DEB package:')
    console.log(error)
    console.log(stderr)
  } else {
    gulpUtil.log('DEB package ready!', debPath)
  }
  deferred.resolve()
})
fork icon3
star icon26
watch icon0

34
35
36
37
38
39
40
41
42
43
{
    'use strict';


    return function (err)
    {
        gutil.log(gutil.colors.red('[' + title + ']'), err.toString());
        this.emit('end');
    };
};
fork icon0
star icon2
watch icon0

29
30
31
32
33
34
35
36
37
38
39
        .pipe(shell([
          'git commit --all --message "Version ' + version + '"',
          (type != 'patch' ? 'git tag --annotate "v' + version + '" --message "Version ' + version + '"' : 'true')
        ], {ignoreErrors: false}))
        .pipe(tap(function() {
          gutil.log(color.green("Version bumped to ") + color.yellow(version) + color.green(", don't forget to push!"));
        }));
    });


};
fork icon0
star icon2
watch icon0

74
75
76
77
78
79
80
81
82
83
    entries: ENTRY_FILE,
    debug: true
})
.transform(babelify)
.bundle().on('error', function(error){
      gutil.log(gutil.colors.red('[Build Error]', error.message));
      this.emit('end');
})
.pipe(gulpif(!isProduction(), exorcist(sourcemapPath)))
.pipe(source(OUTPUT_FILE))
fork icon107
star icon0
watch icon0

89
90
91
92
93
94
95
96
97
98
99
100
  }


  if (!count) {
    gutil.log('No animations activated.');
  } else {
    gutil.log(count + (count > 1 ? ' animations' : ' animation') + ' activated.');
  }


  return target;
}
fork icon2
star icon0
watch icon0