-
Notifications
You must be signed in to change notification settings - Fork 6
/
logger.py
39 lines (26 loc) · 861 Bytes
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
from Register import Register, Value
class ResultLogger:
def __init__(self):
pass
def log(self, results):
print(results)
class JsonLogger(ResultLogger):
def __init__(self):
ResultLogger.__init__(self)
def log(self, results):
pass
class KeyValueLogger(ResultLogger):
def __init__(self):
ResultLogger.__init__(self)
def log(self, results):
for register, value in results.items():
print(f"{register.name}={value}")
class TableLogger(ResultLogger):
def __init__(self):
ResultLogger.__init__(self)
def log(self, results):
max_len = max([len(key.name) for key in results.keys()])
row_format = f"{{:>{max_len}}} = {{}}"
for register, value in results.items():
print(row_format.format(register.name, value))