Last active
April 30, 2019 20:12
-
-
Save DFoly/3ff2e2ce1bbbef721efc6d9ce19b62c0 to your computer and use it in GitHub Desktop.
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
from faker import Faker | |
import time | |
import random | |
import os | |
import numpy as np | |
from datetime import datetime, timedelta | |
LINE = """\ | |
{remote_addr} - - [{time_local}] "{request_type} {request_path} HTTP/1.1" [{status}] {body_bytes_sent} "{http_referer}" "{http_user_agent}"\ | |
""" | |
def generate_log_line(): | |
fake = Faker() | |
now = datetime.now() | |
remote_addr = fake.ipv4() | |
time_local = now.strftime('%d/%b/%Y:%H:%M:%S') | |
request_type = random.choice(["GET", "POST", "PUT"]) | |
request_path = "/" + fake.uri_path() | |
status = np.random.choice([200, 401, 404], p = [0.9, 0.05, 0.05]) | |
body_bytes_sent = random.choice(range(5, 1000, 1)) | |
http_referer = fake.uri() | |
http_user_agent = fake.user_agent() | |
log_line = LINE.format( | |
remote_addr=remote_addr, | |
time_local=time_local, | |
request_type=request_type, | |
request_path=request_path, | |
status=status, | |
body_bytes_sent=body_bytes_sent, | |
http_referer=http_referer, | |
http_user_agent=http_user_agent | |
) | |
return log_line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment