Created
May 10, 2018 11:28
-
-
Save jancbeck/903fc7ca305703a929590fc7a546bc9f to your computer and use it in GitHub Desktop.
Dynamically search and replace server logs when they change. Uses gulp.js and node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "process-log", | |
"version": "1.0.0", | |
"description": "Dynamically search and replace server logs when they change", | |
"main": "gulpfile.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [ | |
"logs" | |
], | |
"author": "Jan Beck", | |
"license": "MIT", | |
"dependencies": { | |
"gulp": "^3.9.1", | |
"gulp-replace": "^0.6.1", | |
"minimist": "^1.2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// USAGE: gulp process-log -s <SEARCH> -r <REPLACE> -f <FILE> | |
var gulp = require('gulp'), | |
replace = require('gulp-replace'), | |
path = require('path'), | |
minimist = require('minimist'), | |
options = minimist(process.argv.slice(2)), | |
FgMagenta = "\x1b[35m", | |
FgCyan = "\x1b[36m", | |
FgNormal = "\x1b[0m"; | |
gulp.task('process-log', function(){ | |
// watch given file for changes | |
gulp.watch(String(options.f), function(event){ | |
console.log('Processing file', FgMagenta, String(event.path), FgNormal ); | |
gulp.src([event.path]) | |
// perform search replace with given options | |
.pipe(replace(String(options.s), String(options.r))) | |
// overwrite original | |
.pipe(gulp.dest(path.dirname(event.path))); | |
console.log('Replaced all instances of', FgCyan, String(options.s), FgNormal, 'with', FgCyan, String(options.r), FgNormal ); | |
return true; | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment