33'use strict' ;
44var fs = require ( 'fs' ) ;
55var path = require ( 'path' ) ;
6- var gutil = require ( 'gulp-util ' ) ;
6+ var log = require ( 'gulplog ' ) ;
77var chalk = require ( 'chalk' ) ;
88var yargs = require ( 'yargs' ) ;
99var Liftoff = require ( 'liftoff' ) ;
@@ -17,6 +17,7 @@ var completion = require('./lib/shared/completion');
1717var verifyDeps = require ( './lib/shared/verifyDependencies' ) ;
1818var cliVersion = require ( './package.json' ) . version ;
1919var getBlacklist = require ( './lib/shared/getBlacklist' ) ;
20+ var toConsole = require ( './lib/shared/log/toConsole' ) ;
2021
2122// Logging functions
2223var logVerify = require ( './lib/shared/log/verify' ) ;
@@ -51,27 +52,22 @@ if (opts.continue) {
5152 process . env . UNDERTAKER_SETTLE = 'true' ;
5253}
5354
54- // This is a hold-over until we have a better logging system
55- // with log levels
56- var shouldLog = ! opts . silent && ! opts . tasksSimple ;
57-
58- if ( ! shouldLog ) {
59- gutil . log = function ( ) { } ;
60- }
55+ // Set up event listeners for logging.
56+ toConsole ( log , opts ) ;
6157
6258cli . on ( 'require' , function ( name ) {
63- gutil . log ( 'Requiring external module' , chalk . magenta ( name ) ) ;
59+ log . info ( 'Requiring external module' , chalk . magenta ( name ) ) ;
6460} ) ;
6561
6662cli . on ( 'requireFail' , function ( name ) {
67- gutil . log ( chalk . red ( 'Failed to load external module' ) , chalk . magenta ( name ) ) ;
63+ log . error ( chalk . red ( 'Failed to load external module' ) , chalk . magenta ( name ) ) ;
6864} ) ;
6965
7066cli . on ( 'respawn' , function ( flags , child ) {
7167 var nodeFlags = chalk . magenta ( flags . join ( ', ' ) ) ;
7268 var pid = chalk . magenta ( child . pid ) ;
73- gutil . log ( 'Node flags detected:' , nodeFlags ) ;
74- gutil . log ( 'Respawned to PID:' , pid ) ;
69+ log . info ( 'Node flags detected:' , nodeFlags ) ;
70+ log . info ( 'Respawned to PID:' , pid ) ;
7571} ) ;
7672
7773function run ( ) {
@@ -93,9 +89,9 @@ function handleArguments(env) {
9389 }
9490
9591 if ( opts . version ) {
96- gutil . log ( 'CLI version' , cliVersion ) ;
92+ log . info ( 'CLI version' , cliVersion ) ;
9793 if ( env . modulePackage && typeof env . modulePackage . version !== 'undefined' ) {
98- gutil . log ( 'Local version' , env . modulePackage . version ) ;
94+ log . info ( 'Local version' , env . modulePackage . version ) ;
9995 }
10096 exit ( 0 ) ;
10197 }
@@ -105,7 +101,7 @@ function handleArguments(env) {
105101 if ( path . resolve ( pkgPath ) !== path . normalize ( pkgPath ) ) {
106102 pkgPath = path . join ( env . configBase , pkgPath ) ;
107103 }
108- gutil . log ( 'Verifying plugins in ' + pkgPath ) ;
104+ log . info ( 'Verifying plugins in ' + pkgPath ) ;
109105 return getBlacklist ( function ( err , blacklist ) {
110106 if ( err ) {
111107 return logBlacklistError ( err ) ;
@@ -118,24 +114,24 @@ function handleArguments(env) {
118114 }
119115
120116 if ( ! env . modulePath ) {
121- gutil . log (
117+ log . error (
122118 chalk . red ( 'Local gulp not found in' ) ,
123119 chalk . magenta ( tildify ( env . cwd ) )
124120 ) ;
125- gutil . log ( chalk . red ( 'Try running: npm install gulp' ) ) ;
121+ log . error ( chalk . red ( 'Try running: npm install gulp' ) ) ;
126122 exit ( 1 ) ;
127123 }
128124
129125 if ( ! env . configPath ) {
130- gutil . log ( chalk . red ( 'No gulpfile found' ) ) ;
126+ log . error ( chalk . red ( 'No gulpfile found' ) ) ;
131127 exit ( 1 ) ;
132128 }
133129
134130 // Chdir before requiring gulpfile to make sure
135131 // we let them chdir as needed
136132 if ( process . cwd ( ) !== env . cwd ) {
137133 process . chdir ( env . cwd ) ;
138- gutil . log (
134+ log . info (
139135 'Working directory changed to' ,
140136 chalk . magenta ( tildify ( env . cwd ) )
141137 ) ;
@@ -145,7 +141,7 @@ function handleArguments(env) {
145141 var range = findRange ( env . modulePackage . version , ranges ) ;
146142
147143 if ( ! range ) {
148- return gutil . log (
144+ return log . error (
149145 chalk . red ( 'Unsupported gulp version' , env . modulePackage . version )
150146 ) ;
151147 }
0 commit comments