Skip to content

Instantly share code, notes, and snippets.

@nickpeihl
Last active September 25, 2022 15:58
Show Gist options
  • Save nickpeihl/31ebb3f98728715d199df042c975a018 to your computer and use it in GitHub Desktop.
Save nickpeihl/31ebb3f98728715d199df042c975a018 to your computer and use it in GitHub Desktop.
Fake NGINX access.log
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