Last active
August 17, 2023 06:37
-
-
Save visuve/2bef8c6946d7ffe4d9ec6e9e1b8f6d00 to your computer and use it in GitHub Desktop.
F-Secure Simulator
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
""" | |
2021-09-07 22:06:42.377 [2a88.23e0] D: main: Debug-viesti | |
2021-09-07 22:06:42.377 [2a88.23e0] I: main: Informatiivinen viesti | |
2021-09-07 22:06:42.377 [2a88.23e0] .W: main: Varoitusviesti | |
2021-09-07 22:06:42.377 [2a88.23e0] *E: main: Virheviesti | |
""" | |
from datetime import datetime | |
import os | |
import random | |
import time | |
import sys | |
class LogSimulator: | |
def __init__(self): | |
self.random_thread_ids = [ | |
random.randint(0x0000, 0x5000), | |
random.randint(0x5001, 0xA000), | |
random.randint(0xA001, 0xFFFF) | |
] | |
# Intentionally from frequent to rare | |
self.log_levels = [ | |
" D", " D", " D", " D", | |
" I", " I", " I", | |
".W", ".W", | |
"*E"] | |
self.function_names = [ | |
"main", | |
"foo", | |
"bar", | |
"barbapapa", | |
"godobject", | |
"pulautin", | |
"tunkki", | |
"kopiopasta", | |
"hyrskytin", | |
"silmukka", | |
"olio", | |
"kutkutin", | |
"deleteme"] | |
self.messages = [ | |
"lol apua", | |
"muistia vuotaa", | |
"kaikin puolin harmittaa", | |
"kohta kaatuu?", | |
"kohta kaatuu!", | |
"poikkeus lennahti", | |
"pelottaa", | |
"puskurin ylivuoto", | |
"muisti loppuu", | |
"kekomuisti korruptoitunut", | |
"arvelluttaa", | |
"pinomuistin ylivuoto", | |
"voi hiivatti!", | |
"kaikki on pilalla!", | |
"VIRHE!", | |
"cpu hakkaa satasta", | |
"havaittiin ongelma", | |
"olen saavuttanut tietoisuuden ymparoivasta maailmasta", | |
"aha, no sit se on just niin t. seppo papunen", | |
"liike lahtee lantiosta"] | |
@staticmethod | |
def _timestamp(): | |
now = datetime.now() | |
timestamp = now.strftime("%Y-%m-%d %H:%M:%S.") | |
timestamp += str(now.microsecond)[0:3].rjust(3, '0') | |
return timestamp | |
@staticmethod | |
def _process_id(): | |
return format(os.getpid(), 'x')[0:4].rjust(4, '0') | |
def _random_thread_id(self): | |
random_thread_id = random.choice(self.random_thread_ids) | |
return format(random_thread_id, 'x')[0:4].rjust(4, '0') | |
def _random_log_level(self): | |
return random.choice(self.log_levels) | |
def _random_function_name(self): | |
return random.choice(self.function_names) | |
def _random_message(self): | |
return random.choice(self.messages) | |
def random_logline(self): | |
return "{} [{}.{}] {}: {}: {}".format( | |
self._timestamp(), | |
self._process_id(), | |
self._random_thread_id(), | |
self._random_log_level(), | |
self._random_function_name(), | |
self._random_message()) | |
if __name__ == "__main__": | |
log_file_path = "{}{}f-secure.log".format( | |
os.path.expanduser("~"), | |
os.path.sep) | |
print("Logging into: " + log_file_path) | |
simulator = LogSimulator() | |
with open(log_file_path, 'w') as log_file: | |
while True: | |
log_line = simulator.random_logline() | |
print(log_line, file=log_file) | |
log_file.flush() | |
print('.', end='', file=sys.stdout) | |
sys.stdout.flush() | |
delay = random.uniform(0.1, 5.0) | |
time.sleep(delay) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment