-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.py
32 lines (29 loc) · 1.05 KB
/
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
import os as os
class Logger:
"""
A simple CSV Logger which logs on a line-by-line basis.
"""
def __init__(self, headers: list):
data_entries = ", ".join(headers)
data_entries = data_entries + '\n'
if os.path.exists("log.csv"):
os.remove("log.csv")
self.log_file = open("log.csv", 'w')
self.log_file.write(data_entries)
def enter_data(self, data: list):
"""
@brief Enters data into a single line of the output log.
@param data A list of entries to add. Does not have to be the same number of entries as
headers on initial creation.
"""
if len(data) > 1:
for index, entry in enumerate(data):
data[index] = str(entry)
data_entries = ", ".join(data)
else:
data_entries = str(data[0])
data_entries = data_entries + '\n'
self.log_file.write(data_entries)
def terminate(self):
self.enter_data(["------END OF FILE------"])
self.log_file.close()