Skip to content

Commit

Permalink
Use the ButlerMDC context manager to ensure MDC is reset
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 26, 2021
1 parent 2de2cf2 commit 69e971a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions python/lsst/ctrl/mpexec/singleQuantumExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,7 @@ def captureLogging(self, taskDef, quantum, butler):
quantum-specific information to log messages. Potentially this can
take into account some info from task configuration as well.
"""
# include quantum dataId and task label into MDC
label = taskDef.label
if quantum.dataId:
label += f":{quantum.dataId}"

ButlerMDC.MDC("LABEL", label)

# Add the handler to the root logger.
# Add a handler to the root logger to capture execution log output.
# How does it get removed reliably?
if taskDef.logOutputDatasetName is not None:
# Either accumulate into ButlerLogRecords or stream
Expand All @@ -221,8 +214,14 @@ def captureLogging(self, taskDef, quantum, butler):

logging.getLogger().addHandler(self.log_handler)

# include quantum dataId and task label into MDC
label = taskDef.label
if quantum.dataId:
label += f":{quantum.dataId}"

try:
yield
with ButlerMDC.set_mdc({"LABEL": label}):
yield
finally:
# Ensure that the logs are stored in butler.
self.writeLogRecords(quantum, taskDef, butler)
Expand Down

0 comments on commit 69e971a

Please sign in to comment.