Reputation: 1232
I am using Gulp as a part of a simple build system for processing text and images, and have defined a series of generic tasks for copying, processing, and deleting these files. Both Gulp and the plugins used give a lot of output in the console, but how can this output be preserved in a file?
Ideally, the exact contents of the console would be logged to console.log
in the same format as it appeared in the console (without color, as is common in the console):
[13:35:21] Images: 208 items
[13:35:23] gulp-imagemin: Minified 208 images (saved 0 B - 0%)
[13:35:23] Finished 'build:images' after 19 s
[13:35:23] Starting 'clean:responsive'...
[13:35:23] Deleting /responsive/**/*
[13:35:23] Finished 'clean:responsive' after 171 ms
[13:35:23] Starting 'default'...
[13:35:23] Finished 'default' after 57 μs
Many of the Gulp plugins focused on logging seem to mainly do this in the console, which is already achieved, and only gulp-messenger saved it to text (as json). Can this be achieved with for example gulp-util?
Upvotes: 2
Views: 4111
Reputation: 1232
As Sven Schoenung suggests in comments, this is best done outside of Gulp itself. In essence, when running the task in terminal two options work as expected:
To run "silently", that is, without console output:
gulp task-name > output.log 2>&1
To run "normally", that is, with console output:
gulp task-name 2>&1 | tee output.log
Both will save the output of the console to output.log
in the root of the Gulp working directory.
Upvotes: 5