Skip to content
Snippets Groups Projects
Commit d4e42d77 authored by Boris Feld's avatar Boris Feld
Browse files

Add file logging configuration

parent b472b10e
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,9 @@
import time
import shlex
import subprocess
import logging
from os.path import dirname, join, abspath
SCRIPT = abspath(join(dirname(__file__), "main-run.sh"))
......@@ -23,8 +24,11 @@
from os.path import dirname, join, abspath
SCRIPT = abspath(join(dirname(__file__), "main-run.sh"))
LOGGER = logging.getLogger(__name__)
LOG_FORMAT = "[%(asctime)s] %(message)s"
def read_next_scheduling(task_file_path):
with open(task_file_path, "r") as f:
......@@ -41,7 +45,9 @@
print("RUNNING %r" % args)
subprocess.check_call(args)
except subprocess.CalledProcessError as e:
print("\nTask %r failed with error code %r" % (task, e.returncode))
msg = "Task %r failed with error code %r"
LOGGER.error(msg, task, e.returncode)
print("\n" + msg % (task, e.returncode))
# XXX find a way to report an error without removing a task
......@@ -79,4 +85,5 @@
print("=" * 80)
print("Got task %r" % task)
LOGGER.info("Starting %r", task)
run(task)
......@@ -82,4 +89,5 @@
run(task)
LOGGER.info("Ending %r", task)
print("\n" * 2)
remove_task(next_task, task_file_path)
print("=" * 80)
......@@ -87,5 +95,22 @@
time.sleep(1)
def setup_logging(logging_file):
# Reset handlers
LOGGER.handlers = []
LOGGER.setLevel(logging.INFO)
# Add handler
console = logging.FileHandler(logging_file)
console.setLevel(logging.INFO)
formatter = logging.Formatter(LOG_FORMAT)
console.setFormatter(formatter)
LOGGER.addHandler(console)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
......@@ -90,6 +115,7 @@
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--log", help="The logging file to use")
parser.add_argument("TASKS", help="The file path to the task file")
args = parser.parse_args(sys.argv[1:])
......@@ -92,5 +118,9 @@
parser.add_argument("TASKS", help="The file path to the task file")
args = parser.parse_args(sys.argv[1:])
# Configure logging
if args.log:
setup_logging(args.log)
main(args.TASKS)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment