Commit a55b18f0 authored by S. Lackner's avatar S. Lackner

[sched] Output a header in the event log (csv)

parent 00a0a8b4
......@@ -49,13 +49,24 @@ class LoggingEvent:
self.type = type
self.data = data
def to_message(self):
"""Returns a human readable message presentation of this event."""
def __str__(self):
return "[{:.6f}] {}/{} <{}> ({})".format(
self.time, self.processed_jobs, self.open_jobs,
self.type, self.msg)
def __str__(self):
@classmethod
def get_csv_header(self):
output = io.StringIO()
csvdata = ["time", "level", "processed_jobs", "open_jobs",
"type", "message", "data"]
writer = csv.writer(
output,
quoting=csv.QUOTE_NONNUMERIC,
delimiter=';')
writer.writerow(csvdata)
return output.getvalue().strip()
def to_csv_line(self):
def conv_obj(o):
try:
return o.__dict__
......@@ -191,6 +202,10 @@ class EventLogger(Logger):
def load_events_from_file(in_file):
events = EventList()
reader = csv.reader(in_file, quoting=csv.QUOTE_NONNUMERIC, delimiter=';')
# Skip header
next(reader)
for row in reader:
if row:
events.add(LoggingEvent.from_entries(row))
......
......@@ -224,6 +224,7 @@ class Scheduler(metaclass=ABCMeta):
self._event_logger = EventLogger(
self, "Events", debug=debug,
to_file="{}_events.csv".format(export_prefix))
self._event_logger.info(LoggingEvent.get_csv_header())
self._events = EventList()
......@@ -370,7 +371,7 @@ class Scheduler(metaclass=ABCMeta):
self._events.add(event)
event_str = event.to_message()
event_str = str(event)
try:
do_publish = True
......@@ -390,7 +391,7 @@ class Scheduler(metaclass=ABCMeta):
self.on_event(event)
return str(event)
return event.to_csv_line()
def debug(self, msg, **kwargs):
"""Writes a debug message to the logging facility."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment