From ae19f1c75ddc4efae4dffe2bc33d614e31f823a2 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 23 Jan 2016 21:43:24 -0500 Subject: [PATCH] master: add filename in worker log entries. Closes #226 --- artiq/master/experiments.py | 4 ++-- artiq/master/log.py | 6 +++--- artiq/master/worker.py | 7 +++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/artiq/master/experiments.py b/artiq/master/experiments.py index 851d5ac66..0edce0976 100644 --- a/artiq/master/experiments.py +++ b/artiq/master/experiments.py @@ -18,7 +18,7 @@ async def _get_repository_entries(entry_dict, root, filename, get_device_db, log): worker = Worker({ "get_device_db": get_device_db, - "log": partial(log, "scan") + "log": partial(log, "scan", os.path.basename(filename)) }) try: description = await worker.examine(os.path.join(root, filename)) @@ -124,7 +124,7 @@ class ExperimentDB: filename = os.path.join(wd, filename) worker = Worker({ "get_device_db": self.get_device_db_fn, - "log": partial(self.log_fn, "examine") + "log": partial(self.log_fn, "examine", os.path.basename(filename)) }) try: description = await worker.examine(filename) diff --git a/artiq/master/log.py b/artiq/master/log.py index ae87e015d..78def9d21 100644 --- a/artiq/master/log.py +++ b/artiq/master/log.py @@ -29,11 +29,11 @@ class LogBufferHandler(logging.Handler): part) -def log_worker(rid, message): +def log_worker(rid, filename, message): level, name, message = parse_log_message(message) log_with_name(name, level, message, - extra={"source": "worker({})".format(rid)}) -log_worker.worker_pass_rid = True + extra={"source": "worker({},{})".format(rid, filename)}) +log_worker.worker_pass_runinfo = True def log_args(parser): diff --git a/artiq/master/worker.py b/artiq/master/worker.py index b5877df0f..16b782a54 100644 --- a/artiq/master/worker.py +++ b/artiq/master/worker.py @@ -1,4 +1,5 @@ import sys +import os import asyncio import logging import subprocess @@ -45,6 +46,7 @@ class Worker: self.send_timeout = send_timeout self.rid = None + self.filename = None self.process = None self.watchdogs = dict() # wid -> expiration (using time.monotonic) @@ -191,8 +193,8 @@ class Worker: func = self.register_experiment else: func = self.handlers[action] - if getattr(func, "worker_pass_rid", False): - func = partial(func, self.rid) + if getattr(func, "worker_pass_runinfo", False): + func = partial(func, self.rid, self.filename) try: data = func(*obj["args"], **obj["kwargs"]) reply = {"status": "ok", "data": data} @@ -227,6 +229,7 @@ class Worker: async def build(self, rid, pipeline_name, wd, expid, priority, timeout=15.0): self.rid = rid + self.filename = os.path.basename(expid["file"]) await self._create_process(expid["log_level"]) await self._worker_action( {"action": "build",