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

[sched] event logging to files is now optional

parent 6e489b7a
......@@ -215,14 +215,17 @@ class Scheduler(metaclass=ABCMeta):
self._options = options
debug = self.options.get("debug", False)
export_prefix = self.options.get("export-prefix", "out")
write_events = bool(self.options.get("write-events", False))
# Create the logger
self._logger = Logger(self, debug=debug)
self._event_logger = EventLogger(
self, "Events", debug=debug, to_file="{}_last_events.csv".format(
export_prefix),
append_to_file="{}_events.csv".format(export_prefix))
self._event_logger = None
if write_events:
self._event_logger = EventLogger(
self, "Events", debug=debug,
to_file="{}_last_events.csv".format(export_prefix),
append_to_file="{}_events.csv".format(export_prefix))
self._sched_jobs_logger = EventLogger(
self,
......@@ -449,28 +452,38 @@ class Scheduler(metaclass=ABCMeta):
def debug(self, msg, **kwargs):
"""Writes a debug message to the logging facility."""
self._logger.debug(self._format_log_msg(msg, **kwargs))
self._event_logger.info(self._format_event_msg(1, msg, **kwargs))
event = self._format_event_msg(1, msg, **kwargs)
if self._event_logger:
self._event_logger.info(event)
def info(self, msg, **kwargs):
"""Writes a info message to the logging facility."""
self._logger.info(self._format_log_msg(msg, **kwargs))
self._event_logger.info(self._format_event_msg(2, msg, **kwargs))
event = self._format_event_msg(2, msg, **kwargs)
if self._event_logger:
self._event_logger.info(event)
def warn(self, msg, **kwargs):
"""Writes a warn message to the logging facility."""
self._logger.warn(self._format_log_msg(msg, **kwargs))
self._event_logger.info(self._format_event_msg(3, msg, **kwargs))
event = self._format_event_msg(3, msg, **kwargs)
if self._event_logger:
self._event_logger.info(event)
def error(self, msg, **kwargs):
"""Writes a error message to the logging facility."""
self._logger.error(self._format_log_msg(msg, **kwargs))
self._event_logger.info(self._format_event_msg(4, msg, **kwargs))
event = self._format_event_msg(4, msg, **kwargs)
if self._event_logger:
self._event_logger.info(event)
def fatal(self, msg, **kwargs):
"""Writes a fatal message to the logging facility and terminates the scheduler."""
error_msg = self._format_log_msg(msg, **kwargs)
self._logger.error(error_msg)
self._event_logger.info(self._format_event_msg(5, msg, **kwargs))
event = self._format_event_msg(5, msg, **kwargs)
if self._event_logger:
self._event_logger.info(event)
raise ValueError("Fatal error: {}".format(error_msg))
def _on_pre_init(self):
......
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