Last active
September 25, 2022 15:58
-
-
Save nickpeihl/31ebb3f98728715d199df042c975a018 to your computer and use it in GitHub Desktop.
Fake NGINX access.log
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
const faker = require('faker'); | |
const moment = require('moment'); | |
const fs = require('fs'); | |
const stream = fs.createWriteStream('./access.log', { | |
flags: 'a' | |
}); | |
function writeToStream(n) { | |
for (; n < 1000000; n++) { | |
const access = faker.fake(`{{internet.ip}} - - [${timestamp()}] "GET /{{internet.domainWord}}/{{lorem.slug}} HTTP/1.1" 200 {{random.number}} "-" "{{internet.userAgent}}"`); | |
if (!stream.write(`${access}\n`)) { | |
stream.once('drain', () => writeToStream(n + 1)) | |
return; | |
} | |
} | |
stream.end(); | |
} | |
writeToStream(0); | |
function timestamp () { | |
const ts = faker.date.recent(7); | |
const str = moment(ts).format('DD/MMM/YYYY:HH:mm:ss ZZ'); | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment