gulp TaskLogger
A helper for gulp, to log at task start, end, and any other log, with time, and string formatting, and collor personalisation, and more .., Can be used as a cli program loggin helper too out of gulp.
Notice:
Gulp version 4 have no gulp.start(), logging the start and end of our tasks can be just important, gulp-task-logger is a nice helper that make it a breeze.
install:
npm i gulp-task-logger --save
use example:
Here an example (you find it, in git repo)
var gulp = watch = stripJsonComments = source = var TaskLogger = ; // <===== require const path = ; const tl = ; // <==== initiation without options (default) // here a watch taskgulp; var jsonCommentWatchEvt = null //json comments gulp; { if !done tl; //<======= log at task start [notice if(!done)! it's to make sure we are only logging ourselves, when we are calling the function ourselves without done! if it's the normal from cli task execution, then the log will happen by gulp] } { // var dest = path.join(__dirname, 'app/json/', getRelevantPath_usingBase(base, evt.path)) gulp }
require
var TaskLogger = ;
create an instance
Default options:
const tl = ;
With options:
const tl = // options go here;
List of options properties
taskName: '' prefix: '' colors: taskName: 'cyan' time: 'gray' startMessage: 'yellow' endMessage: 'yellow' msg: 'white' prefix: 'red' duration: 'magenta' startMessage: 'Starting' endMessage: 'Finished' startMsgFormat: '[time] startMessage \'taskName\'...' endMsgFormat: '[time] endMessage \'taskName\' after duration' logFormat: '[time] msg' //'[time] prefix msg'
Explanation:
three sections:
Formatting:
startMsgFormat: '[time] startMessage \'taskName\'...' endMsgFormat: '[time] endMessage \'taskName\' after duration' logFormat: '[time] msg' //'[time] prefix msg'
Using the same properties some there values come from options, each one of the properties will be replaced with it's corresponding value, all properties have a default value, even if you don't precise it (defaulting to '').
There is 7 properties:
Properties |
---|
taskName |
time |
startMessage |
endMessage |
msg |
prefix |
duration |
prcise using this keyword your formatting, then set there value in options too, except duration, and time, and msg. The two first automatically calculated, and msg you provide, when calling one of the three logging functions.
logging
3 functions for know
// by default log a message + time at start // By default show end task message equivalent to the default one of gulp // same but for start
With options you can change the formatting as the value of each part of the properties.
task()
tl // this set which task you want to log about
If the code is synchronous, you can set it once and call the logging functions as you like.
Otherwise if you are not sure you must use:
tl; // log right away and each time
note task() return the instance itself, you can use any of the available methods.
colors
gulp-task-logger deppend on 'colors' So you can use any of the colors it provide.
Here you can find a test example: https://github.com/MohamedLamineAllal/gulpTaskLogger/tree/master/test
Here another example: https://github.com/MohamedLamineAllal/gulpTaskLogger/tree/master/test/AnotherExample_Blade
const gulp = ;const TaskLogger = // <=======const fs = ;const path = ;const execSync = ; const tl = ;//<--------------- let watcher; { watcher = gulp; // watcher.on('add', function (pth) { watcher; ;} gulp;
////// documentation to be continued!
// more features are to be expected!
// feedback appreciated!
//Notice: Bug was fixed! duration is not defined !! If you encounter that, update your package.