Skip to content

Instantly share code, notes, and snippets.

@ryanneufeld
Last active December 15, 2015 03:59
Show Gist options
  • Select an option

  • Save ryanneufeld/5198854 to your computer and use it in GitHub Desktop.

Select an option

Save ryanneufeld/5198854 to your computer and use it in GitHub Desktop.
"use strict";
module.exports = function(grunt) {
// Override process.stdout to log the name+args of the current task before
// every logged line.
var hooker = require('hooker');
var newline = true;
hooker.hook(process.stdout, 'write', function(str) {
var prefix = grunt.task.current.nameArgs;
//I want to check for logFile here.
if (newline && prefix && str !== '\n') {
newline = false;
str = '[' + prefix + '] ' + str;
}
newline = /\n/.test(str);
return hooker.filter(this, [str]);
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd-hh:MM:ss") %> v<%= pkg.version %> */\n'
},
build: {
expand: true,
cwd: 'js/raw',
src: '**/*.js',
dest: 'js/min/',
ext: '.js'
},
logFile : 'uglify.log'
},
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['uglify']);
};
@cowboy
Copy link
Copy Markdown

cowboy commented Mar 19, 2013

var fs = require('fs');
var hooker = require('hooker');
hooker.hook(process.stdout, 'write', function(str) {
  var filename = grunt.task.current.nameArgs;
  if (filename) {
    filename = 'log-' + filename.replace(/:/g, '-') + '.txt';
    fs.appendFile(filename, grunt.log.uncolor(str));
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment